From 99e0bcc27dbe2869e300a50056dd33436f73e364 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Thu, 7 Mar 2024 08:22:28 -0500 Subject: [PATCH] refactor: Observers/ignored peers can now send and receive custom packets The Observer role was intended to prevent peers from being disruptive and/or interacting with other peers in the group. It wasn't intended to cripple custom protocols running on-top of the groups such as file sharing and message syncing. In cases where it might be undesirable for observers to use custom packets (e.g. starting a file transfer) the client will have the ability to decide whether or not to allow it. --- toxcore/group_chats.c | 20 ++------------------ toxcore/group_chats.h | 6 ++---- toxcore/tox.c | 10 ---------- toxcore/tox.h | 10 ---------- toxcore/tox_api.c | 6 ------ 5 files changed, 4 insertions(+), 48 deletions(-) diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 4197191c3b..6bee144836 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -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) { @@ -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. @@ -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); } @@ -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) { @@ -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. @@ -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); } diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h index 32a7323dc4..6c85e99822 100644 --- a/toxcore/group_chats.h +++ b/toxcore/group_chats.h @@ -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); @@ -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, diff --git a/toxcore/tox.c b/toxcore/tox.c index 8411762678..706ccb8985 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -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; } @@ -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; } diff --git a/toxcore/tox.h b/toxcore/tox.h index 8d1f208ff7..9ba9ab366a 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -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. */ @@ -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. */ diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index bd8b531d06..5904c803af 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -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"; @@ -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";