Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Observers/ignored peers can now send and receive custom packets #2728

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -5067,10 +5067,6 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id
return -3;
}

if (gc_get_self_role(chat) >= GR_OBSERVER) {
return -4;
}

bool ret;

if (lossless) {
Expand All @@ -5079,7 +5075,7 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id
ret = send_lossy_group_packet(chat, gconn, message, length, GP_CUSTOM_PRIVATE_PACKET);
}

return ret ? 0 : -5;
return ret ? 0 : -4;
}

/** @brief Handles a custom private packet.
Expand All @@ -5099,10 +5095,6 @@ static int handle_gc_custom_private_packet(const GC_Session *c, const GC_Chat *c
return -1;
}

if (peer->ignore || peer->role >= GR_OBSERVER) {
return 0;
}

if (c->custom_private_packet != nullptr) {
c->custom_private_packet(c->messenger, chat->group_number, peer->peer_id, data, length, userdata);
}
Expand All @@ -5120,10 +5112,6 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat
return -2;
}

if (gc_get_self_role(chat) >= GR_OBSERVER) {
return -3;
}

bool success;

if (lossless) {
Expand All @@ -5132,7 +5120,7 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat
success = send_gc_lossy_packet_all_peers(chat, data, length, GP_CUSTOM_PACKET);
}

return success ? 0 : -4;
return success ? 0 : -3;
}

/** @brief Handles a custom packet.
Expand All @@ -5152,10 +5140,6 @@ static int handle_gc_custom_packet(const GC_Session *c, const GC_Chat *chat, con
return -1;
}

if (peer->ignore || peer->role >= GR_OBSERVER) {
return 0;
}

if (c->custom_packet != nullptr) {
c->custom_packet(c->messenger, chat->group_number, peer->peer_id, data, length, userdata);
}
Expand Down
6 changes: 2 additions & 4 deletions toxcore/group_chats.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t typ
* Returns 0 on success.
* Returns -1 if the message is too long.
* Returns -2 if the message pointer is NULL or length is zero.
* Returns -3 if the sender has the observer role.
* Returns -4 if the packet did not successfully send to any peer.
* Returns -3 if the packet did not successfully send to any peer.
*/
non_null()
int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *data, uint16_t length);
Expand All @@ -206,8 +205,7 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat
* @retval -1 if the message is too long.
* @retval -2 if the message pointer is NULL or length is zero.
* @retval -3 if the supplied peer_id does not designate a valid peer.
* @retval -4 if the sender has the observer role.
* @retval -5 if the packet fails to send.
* @retval -4 if the packet fails to send.
*/
non_null()
int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id peer_id, const uint8_t *message,
Expand Down
10 changes: 0 additions & 10 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -4100,11 +4100,6 @@ bool tox_group_send_custom_packet(const Tox *tox, uint32_t group_number, bool lo
}

case -3: {
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS);
return false;
}

case -4: {
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PACKET_FAIL_SEND);
return false;
}
Expand Down Expand Up @@ -4162,11 +4157,6 @@ bool tox_group_send_custom_private_packet(const Tox *tox, uint32_t group_number,
}

case -4: {
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS);
return false;
}

case -5: {
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND);
return false;
}
Expand Down
10 changes: 0 additions & 10 deletions toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -4604,11 +4604,6 @@ typedef enum Tox_Err_Group_Send_Custom_Packet {
*/
TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY,

/**
* The caller does not have the required permissions to send group messages.
*/
TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS,

/**
* The group is disconnected.
*/
Expand Down Expand Up @@ -4682,11 +4677,6 @@ typedef enum Tox_Err_Group_Send_Custom_Private_Packet {
*/
TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND,

/**
* The caller does not have the required permissions to send group messages.
*/
TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS,

/**
* The packet failed to send.
*/
Expand Down
6 changes: 0 additions & 6 deletions toxcore/tox_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,9 +1370,6 @@ const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom
case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY:
return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY";

case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS:
return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS";

case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED:
return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED";

Expand Down Expand Up @@ -1400,9 +1397,6 @@ const char *tox_err_group_send_custom_private_packet_to_string(Tox_Err_Group_Sen
case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND:
return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND";

case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS:
return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS";

case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND:
return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND";

Expand Down
Loading