diff options
Diffstat (limited to 'testing/experiment/group_chats.c')
-rw-r--r-- | testing/experiment/group_chats.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/testing/experiment/group_chats.c b/testing/experiment/group_chats.c index faf274d5..635bba72 100644 --- a/testing/experiment/group_chats.c +++ b/testing/experiment/group_chats.c | |||
@@ -110,6 +110,9 @@ static int peer_okping(Group_Chat *chat, uint8_t *client_id) | |||
110 | uint32_t i, j = 0; | 110 | uint32_t i, j = 0; |
111 | uint64_t temp_time = unix_time(); | 111 | uint64_t temp_time = unix_time(); |
112 | 112 | ||
113 | if (memcmp(chat->self_public_key, client_id, crypto_box_PUBLICKEYBYTES) == 0) | ||
114 | return -1; | ||
115 | |||
113 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; ++i) { | 116 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; ++i) { |
114 | if (chat->close[i].last_recv + BAD_NODE_TIMEOUT < temp_time) { | 117 | if (chat->close[i].last_recv + BAD_NODE_TIMEOUT < temp_time) { |
115 | ++j; | 118 | ++j; |
@@ -201,7 +204,7 @@ static uint8_t sendto_allpeers(Group_Chat *chat, uint8_t *data, uint16_t length, | |||
201 | uint64_t temp_time = unix_time(); | 204 | uint64_t temp_time = unix_time(); |
202 | 205 | ||
203 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; ++i) { | 206 | for (i = 0; i < GROUP_CLOSE_CONNECTIONS; ++i) { |
204 | if (chat->close[i].ip_port.ip.uint32 != 0 && chat->close[i].last_recv > temp_time + BAD_NODE_TIMEOUT) { | 207 | if (chat->close[i].ip_port.ip.uint32 != 0 && chat->close[i].last_recv + BAD_NODE_TIMEOUT > temp_time) { |
205 | if (send_groupchatpacket(chat, chat->close[i].ip_port, chat->close[i].client_id, data, length, request_id) == 0) | 208 | if (send_groupchatpacket(chat, chat->close[i].ip_port, chat->close[i].client_id, data, length, request_id) == 0) |
206 | ++sent; | 209 | ++sent; |
207 | } | 210 | } |
@@ -392,17 +395,21 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len) | |||
392 | memcpy(&message_num, data + crypto_box_PUBLICKEYBYTES, sizeof(uint32_t)); | 395 | memcpy(&message_num, data + crypto_box_PUBLICKEYBYTES, sizeof(uint32_t)); |
393 | message_num = ntohl(message_num); | 396 | message_num = ntohl(message_num); |
394 | 397 | ||
395 | if (message_num - chat->group[peernum].last_message_number > 64 || | 398 | if (chat->group[peernum].last_message_number == 0) { |
396 | message_num == chat->group[peernum].last_message_number) | 399 | chat->group[peernum].last_message_number = message_num; |
400 | } else if (message_num - chat->group[peernum].last_message_number > 64 || | ||
401 | message_num == chat->group[peernum].last_message_number) | ||
397 | return 1; | 402 | return 1; |
398 | 403 | ||
399 | chat->group[peernum].last_message_number = message_num; | 404 | chat->group[peernum].last_message_number = message_num; |
400 | 405 | ||
401 | int handled = 0; | 406 | int handled = 0; |
402 | 407 | ||
403 | if (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] == 64 | 408 | if (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] == 64) { |
404 | && chat->group_message != NULL) { /* If message is chat message */ | 409 | if (chat->group_message != NULL) /* If message is chat message */ |
405 | (*chat->group_message)(chat, peernum, data + GROUP_DATA_MIN_SIZE, len - 1, chat->group_message_userdata); | 410 | (*chat->group_message)(chat, peernum, data + GROUP_DATA_MIN_SIZE, len - GROUP_DATA_MIN_SIZE, |
411 | chat->group_message_userdata); | ||
412 | |||
406 | handled = 1; | 413 | handled = 1; |
407 | } | 414 | } |
408 | 415 | ||
@@ -420,10 +427,16 @@ static uint8_t send_data(Group_Chat *chat, uint8_t *data, uint32_t len, uint8_t | |||
420 | return 1; | 427 | return 1; |
421 | 428 | ||
422 | uint8_t packet[MAX_DATA_SIZE]; | 429 | uint8_t packet[MAX_DATA_SIZE]; |
430 | ++chat->message_number; | ||
431 | |||
432 | if (chat->message_number == 0) | ||
433 | chat->message_number = 1; | ||
434 | |||
423 | uint32_t message_num = htonl(chat->message_number); | 435 | uint32_t message_num = htonl(chat->message_number); |
424 | //TODO | 436 | //TODO |
425 | memcpy(packet, chat->self_public_key, crypto_box_PUBLICKEYBYTES); | 437 | memcpy(packet, chat->self_public_key, crypto_box_PUBLICKEYBYTES); |
426 | memcpy(packet + crypto_box_PUBLICKEYBYTES, &message_num, sizeof(message_num)); | 438 | memcpy(packet + crypto_box_PUBLICKEYBYTES, &message_num, sizeof(message_num)); |
439 | memcpy(packet + GROUP_DATA_MIN_SIZE, data, len); | ||
427 | packet[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] = message_id; | 440 | packet[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] = message_id; |
428 | return sendto_allpeers(chat, packet, len + GROUP_DATA_MIN_SIZE, 50); | 441 | return sendto_allpeers(chat, packet, len + GROUP_DATA_MIN_SIZE, 50); |
429 | } | 442 | } |