Skip to content

Commit 99e0bcc

Browse files
committed
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.
1 parent b3c3c49 commit 99e0bcc

File tree

5 files changed

+4
-48
lines changed

5 files changed

+4
-48
lines changed

toxcore/group_chats.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,10 +5067,6 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id
50675067
return -3;
50685068
}
50695069

5070-
if (gc_get_self_role(chat) >= GR_OBSERVER) {
5071-
return -4;
5072-
}
5073-
50745070
bool ret;
50755071

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

5082-
return ret ? 0 : -5;
5078+
return ret ? 0 : -4;
50835079
}
50845080

50855081
/** @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
50995095
return -1;
51005096
}
51015097

5102-
if (peer->ignore || peer->role >= GR_OBSERVER) {
5103-
return 0;
5104-
}
5105-
51065098
if (c->custom_private_packet != nullptr) {
51075099
c->custom_private_packet(c->messenger, chat->group_number, peer->peer_id, data, length, userdata);
51085100
}
@@ -5120,10 +5112,6 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat
51205112
return -2;
51215113
}
51225114

5123-
if (gc_get_self_role(chat) >= GR_OBSERVER) {
5124-
return -3;
5125-
}
5126-
51275115
bool success;
51285116

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

5135-
return success ? 0 : -4;
5123+
return success ? 0 : -3;
51365124
}
51375125

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

5155-
if (peer->ignore || peer->role >= GR_OBSERVER) {
5156-
return 0;
5157-
}
5158-
51595143
if (c->custom_packet != nullptr) {
51605144
c->custom_packet(c->messenger, chat->group_number, peer->peer_id, data, length, userdata);
51615145
}

toxcore/group_chats.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t typ
192192
* Returns 0 on success.
193193
* Returns -1 if the message is too long.
194194
* Returns -2 if the message pointer is NULL or length is zero.
195-
* Returns -3 if the sender has the observer role.
196-
* Returns -4 if the packet did not successfully send to any peer.
195+
* Returns -3 if the packet did not successfully send to any peer.
197196
*/
198197
non_null()
199198
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
206205
* @retval -1 if the message is too long.
207206
* @retval -2 if the message pointer is NULL or length is zero.
208207
* @retval -3 if the supplied peer_id does not designate a valid peer.
209-
* @retval -4 if the sender has the observer role.
210-
* @retval -5 if the packet fails to send.
208+
* @retval -4 if the packet fails to send.
211209
*/
212210
non_null()
213211
int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id peer_id, const uint8_t *message,

toxcore/tox.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,11 +4100,6 @@ bool tox_group_send_custom_packet(const Tox *tox, uint32_t group_number, bool lo
41004100
}
41014101

41024102
case -3: {
4103-
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS);
4104-
return false;
4105-
}
4106-
4107-
case -4: {
41084103
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PACKET_FAIL_SEND);
41094104
return false;
41104105
}
@@ -4162,11 +4157,6 @@ bool tox_group_send_custom_private_packet(const Tox *tox, uint32_t group_number,
41624157
}
41634158

41644159
case -4: {
4165-
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS);
4166-
return false;
4167-
}
4168-
4169-
case -5: {
41704160
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND);
41714161
return false;
41724162
}

toxcore/tox.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,11 +4604,6 @@ typedef enum Tox_Err_Group_Send_Custom_Packet {
46044604
*/
46054605
TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY,
46064606

4607-
/**
4608-
* The caller does not have the required permissions to send group messages.
4609-
*/
4610-
TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS,
4611-
46124607
/**
46134608
* The group is disconnected.
46144609
*/
@@ -4682,11 +4677,6 @@ typedef enum Tox_Err_Group_Send_Custom_Private_Packet {
46824677
*/
46834678
TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND,
46844679

4685-
/**
4686-
* The caller does not have the required permissions to send group messages.
4687-
*/
4688-
TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS,
4689-
46904680
/**
46914681
* The packet failed to send.
46924682
*/

toxcore/tox_api.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,6 @@ const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom
13701370
case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY:
13711371
return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY";
13721372

1373-
case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS:
1374-
return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS";
1375-
13761373
case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED:
13771374
return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED";
13781375

@@ -1400,9 +1397,6 @@ const char *tox_err_group_send_custom_private_packet_to_string(Tox_Err_Group_Sen
14001397
case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND:
14011398
return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND";
14021399

1403-
case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS:
1404-
return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS";
1405-
14061400
case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND:
14071401
return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND";
14081402

0 commit comments

Comments
 (0)