summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-02-16 07:25:10 -0500
committerirungentoo <irungentoo@gmail.com>2014-02-16 07:25:10 -0500
commit1ef5d409355f433e2b067f0f7dd57ec9382e701a (patch)
treef299c0672c1c7c9199eb4a176f56b574c89cf715
parent9b61edbb075feed80b19cc82a8d481dd5fa45aee (diff)
Possibly fixed the issue that group chats would sometimes DOS themselves.
-rw-r--r--toxcore/group_chats.c27
-rw-r--r--toxcore/group_chats.h3
2 files changed, 29 insertions, 1 deletions
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index 6dff52ef..e686ee5d 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -251,6 +251,22 @@ static int addpeer(Group_Chat *chat, uint8_t *client_id)
251} 251}
252 252
253/* 253/*
254 * Set a peer from the group chat to deleted.
255 *
256 * return 0 if success
257 * return -1 if error.
258 */
259static int del_peer_set(Group_Chat *chat, int peernum)
260{
261 if ((uint32_t)peernum >= chat->numpeers)
262 return -1;
263
264 chat->group[peernum].deleted = 1;
265 chat->group[peernum].deleted_time = unix_time();
266 return 0;
267}
268
269/*
254 * Delete a peer from the group chat. 270 * Delete a peer from the group chat.
255 * 271 *
256 * return 0 if success 272 * return 0 if success
@@ -488,6 +504,9 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
488 if (peernum == -1) 504 if (peernum == -1)
489 return 1; 505 return 1;
490 506
507 if (chat->group[peernum].deleted)
508 return 1;
509
491 /* Spam prevention (1 message per peer per second limit.) 510 /* Spam prevention (1 message per peer per second limit.)
492 511
493 if (chat->group[peernum].last_recv == temp_time) 512 if (chat->group[peernum].last_recv == temp_time)
@@ -531,7 +550,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
531 if (contents_len != 0) 550 if (contents_len != 0)
532 return 1; 551 return 1;
533 552
534 delpeer(chat, peernum); 553 del_peer_set(chat, peernum);
535 break; 554 break;
536 555
537 case GROUP_CHAT_PEER_NICK: 556 case GROUP_CHAT_PEER_NICK:
@@ -758,6 +777,7 @@ static void ping_group(Group_Chat *chat)
758 } 777 }
759} 778}
760 779
780#define DEL_PEER_DELAY 3
761static void del_dead_peers(Group_Chat *chat) 781static void del_dead_peers(Group_Chat *chat)
762{ 782{
763 uint32_t i; 783 uint32_t i;
@@ -766,6 +786,11 @@ static void del_dead_peers(Group_Chat *chat)
766 if (is_timeout(chat->group[i].last_recv_msgping, GROUP_PING_INTERVAL * 4)) { 786 if (is_timeout(chat->group[i].last_recv_msgping, GROUP_PING_INTERVAL * 4)) {
767 delpeer(chat, i); 787 delpeer(chat, i);
768 } 788 }
789
790 if (chat->group[i].deleted) {
791 if (is_timeout(chat->group[i].deleted_time, DEL_PEER_DELAY))
792 delpeer(chat, i);
793 }
769 } 794 }
770} 795}
771 796
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h
index 8d5f5e50..e31aa229 100644
--- a/toxcore/group_chats.h
+++ b/toxcore/group_chats.h
@@ -41,6 +41,9 @@ typedef struct {
41 41
42 uint8_t nick[MAX_NICK_BYTES]; 42 uint8_t nick[MAX_NICK_BYTES];
43 uint16_t nick_len; 43 uint16_t nick_len;
44
45 uint8_t deleted;
46 uint64_t deleted_time;
44} Group_Peer; 47} Group_Peer;
45 48
46typedef struct { 49typedef struct {