summaryrefslogtreecommitdiff
path: root/toxcore/group_chats.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/group_chats.c')
-rw-r--r--toxcore/group_chats.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index 5376713c..ed867365 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -27,6 +27,8 @@
27#endif 27#endif
28 28
29#include "group_chats.h" 29#include "group_chats.h"
30#include "assoc.h"
31#include "LAN_discovery.h"
30#include "util.h" 32#include "util.h"
31 33
32#define GROUPCHAT_MAXDATA_LENGTH (MAX_DATA_SIZE - (1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES)) 34#define GROUPCHAT_MAXDATA_LENGTH (MAX_DATA_SIZE - (1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES))
@@ -306,6 +308,16 @@ static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum)
306 308
307 chat->group[peernum].last_pinged = unix_time(); 309 chat->group[peernum].last_pinged = unix_time();
308 chat->group[peernum].pingid = contents.pingid; 310 chat->group[peernum].pingid = contents.pingid;
311 chat->group[peernum].ping_via = ip_port;
312
313
314 if (chat->assoc) {
315 IPPTs ippts;
316 ippts.timestamp = unix_time();
317 ippts.ip_port = ip_port;
318
319 Assoc_add_entry(chat->assoc, chat->group[peernum].client_id, &ippts, NULL);
320 }
309 321
310 return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, sizeof(contents), 322 return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, sizeof(contents),
311 CRYPTO_PACKET_GROUP_CHAT_GET_NODES); 323 CRYPTO_PACKET_GROUP_CHAT_GET_NODES);
@@ -373,6 +385,9 @@ static int handle_sendnodes(Group_Chat *chat, IP_Port source, int peernum, uint8
373 uint16_t numnodes = (len - sizeof(contents.pingid)) / sizeof(groupchat_nodes); 385 uint16_t numnodes = (len - sizeof(contents.pingid)) / sizeof(groupchat_nodes);
374 uint32_t i; 386 uint32_t i;
375 387
388 IPPTs ippts_send;
389 ippts_send.timestamp = unix_time();
390
376 for (i = 0; i < numnodes; ++i) { 391 for (i = 0; i < numnodes; ++i) {
377 if (peer_okping(chat, contents.nodes[i].client_id) > 0) { 392 if (peer_okping(chat, contents.nodes[i].client_id) > 0) {
378 int peern = peer_in_chat(chat, contents.nodes[i].client_id); 393 int peern = peer_in_chat(chat, contents.nodes[i].client_id);
@@ -385,10 +400,26 @@ static int handle_sendnodes(Group_Chat *chat, IP_Port source, int peernum, uint8
385 continue; 400 continue;
386 401
387 send_getnodes(chat, contents.nodes[i].ip_port, peern); 402 send_getnodes(chat, contents.nodes[i].ip_port, peern);
403
404 if (chat->assoc) {
405 ippts_send.ip_port = contents.nodes[i].ip_port;
406 Assoc_add_entry(chat->assoc, contents.nodes[i].client_id, &ippts_send, NULL);
407 }
388 } 408 }
389 } 409 }
390 410
391 add_closepeer(chat, chat->group[peernum].client_id, source); 411 add_closepeer(chat, chat->group[peernum].client_id, source);
412
413 if (chat->assoc) {
414 ippts_send.ip_port = chat->group[peernum].ping_via;
415 ippts_send.timestamp = chat->group[peernum].last_pinged;
416
417 IP_Port ipp_recv;
418 ipp_recv = source;
419
420 Assoc_add_entry(chat->assoc, contents.nodes[i].client_id, &ippts_send, &ipp_recv);
421 }
422
392 return 0; 423 return 0;
393} 424}
394 425
@@ -583,7 +614,8 @@ void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat,
583 chat->group_message_userdata = userdata; 614 chat->group_message_userdata = userdata;
584} 615}
585 616
586Group_Chat *new_groupchat(Networking_Core *net) 617
618Group_Chat *new_groupchat(Networking_Core *net, Assoc *assoc)
587{ 619{
588 unix_time_update(); 620 unix_time_update();
589 621
@@ -593,6 +625,9 @@ Group_Chat *new_groupchat(Networking_Core *net)
593 Group_Chat *chat = calloc(1, sizeof(Group_Chat)); 625 Group_Chat *chat = calloc(1, sizeof(Group_Chat));
594 chat->net = net; 626 chat->net = net;
595 crypto_box_keypair(chat->self_public_key, chat->self_secret_key); 627 crypto_box_keypair(chat->self_public_key, chat->self_secret_key);
628
629 chat->assoc = assoc;
630
596 return chat; 631 return chat;
597} 632}
598 633