mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Possibly fixed the issue that group chats would sometimes DOS themselves.
This commit is contained in:
parent
9b61edbb07
commit
1ef5d40935
|
@ -250,6 +250,22 @@ static int addpeer(Group_Chat *chat, uint8_t *client_id)
|
||||||
return (chat->numpeers - 1);
|
return (chat->numpeers - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set a peer from the group chat to deleted.
|
||||||
|
*
|
||||||
|
* return 0 if success
|
||||||
|
* return -1 if error.
|
||||||
|
*/
|
||||||
|
static int del_peer_set(Group_Chat *chat, int peernum)
|
||||||
|
{
|
||||||
|
if ((uint32_t)peernum >= chat->numpeers)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
chat->group[peernum].deleted = 1;
|
||||||
|
chat->group[peernum].deleted_time = unix_time();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete a peer from the group chat.
|
* Delete a peer from the group chat.
|
||||||
*
|
*
|
||||||
|
@ -488,6 +504,9 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
|
||||||
if (peernum == -1)
|
if (peernum == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if (chat->group[peernum].deleted)
|
||||||
|
return 1;
|
||||||
|
|
||||||
/* Spam prevention (1 message per peer per second limit.)
|
/* Spam prevention (1 message per peer per second limit.)
|
||||||
|
|
||||||
if (chat->group[peernum].last_recv == temp_time)
|
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)
|
||||||
if (contents_len != 0)
|
if (contents_len != 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
delpeer(chat, peernum);
|
del_peer_set(chat, peernum);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GROUP_CHAT_PEER_NICK:
|
case GROUP_CHAT_PEER_NICK:
|
||||||
|
@ -758,6 +777,7 @@ static void ping_group(Group_Chat *chat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DEL_PEER_DELAY 3
|
||||||
static void del_dead_peers(Group_Chat *chat)
|
static void del_dead_peers(Group_Chat *chat)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -766,6 +786,11 @@ static void del_dead_peers(Group_Chat *chat)
|
||||||
if (is_timeout(chat->group[i].last_recv_msgping, GROUP_PING_INTERVAL * 4)) {
|
if (is_timeout(chat->group[i].last_recv_msgping, GROUP_PING_INTERVAL * 4)) {
|
||||||
delpeer(chat, i);
|
delpeer(chat, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chat->group[i].deleted) {
|
||||||
|
if (is_timeout(chat->group[i].deleted_time, DEL_PEER_DELAY))
|
||||||
|
delpeer(chat, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ typedef struct {
|
||||||
|
|
||||||
uint8_t nick[MAX_NICK_BYTES];
|
uint8_t nick[MAX_NICK_BYTES];
|
||||||
uint16_t nick_len;
|
uint16_t nick_len;
|
||||||
|
|
||||||
|
uint8_t deleted;
|
||||||
|
uint64_t deleted_time;
|
||||||
} Group_Peer;
|
} Group_Peer;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user