summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/Lossless_UDP.c4
-rw-r--r--toxcore/group_chats.c26
-rw-r--r--toxcore/group_chats.h4
-rw-r--r--toxcore/net_crypto.h3
4 files changed, 22 insertions, 15 deletions
diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c
index ce1779ec..8b9beb63 100644
--- a/toxcore/Lossless_UDP.c
+++ b/toxcore/Lossless_UDP.c
@@ -860,8 +860,8 @@ static void adjust_datasendspeed(Connection *connection, uint32_t req_packets)
860 return; 860 return;
861 } 861 }
862 862
863 if (req_packets <= (connection->data_rate / connection->SYNC_rate) / 5 || req_packets <= 10) { 863 if (req_packets <= (connection->data_rate / connection->SYNC_rate) / 4 || req_packets <= 10) {
864 connection->data_rate += (connection->data_rate / 8) + 1; 864 connection->data_rate += (connection->data_rate / 4) + 1;
865 865
866 if (connection->data_rate > connection->sendbuffer_length * connection->SYNC_rate) 866 if (connection->data_rate > connection->sendbuffer_length * connection->SYNC_rate)
867 connection->data_rate = connection->sendbuffer_length * connection->SYNC_rate; 867 connection->data_rate = connection->sendbuffer_length * connection->SYNC_rate;
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index ba7e0750..9275d63e 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -289,7 +289,7 @@ static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum)
289 chat->group[peernum].last_pinged = unix_time(); 289 chat->group[peernum].last_pinged = unix_time();
290 chat->group[peernum].pingid = contents.pingid; 290 chat->group[peernum].pingid = contents.pingid;
291 291
292 return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, sizeof(contents), 48); 292 return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, sizeof(contents), CRYPTO_PACKET_GROUP_CHAT_GET_NODES);
293} 293}
294 294
295static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64_t pingid) 295static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64_t pingid)
@@ -310,7 +310,7 @@ static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64
310 } 310 }
311 311
312 return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents, 312 return send_groupchatpacket(chat, ip_port, chat->group[peernum].client_id, (uint8_t *)&contents,
313 sizeof(contents.pingid) + sizeof(groupchat_nodes) * j, 49); 313 sizeof(contents.pingid) + sizeof(groupchat_nodes) * j, CRYPTO_PACKET_GROUP_CHAT_SEND_NODES);
314} 314}
315 315
316static int handle_getnodes(Group_Chat *chat, IP_Port source, int peernum, uint8_t *data, uint32_t len) 316static int handle_getnodes(Group_Chat *chat, IP_Port source, int peernum, uint8_t *data, uint32_t len)
@@ -414,21 +414,21 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
414 uint16_t contents_len = len - GROUP_DATA_MIN_SIZE; 414 uint16_t contents_len = len - GROUP_DATA_MIN_SIZE;
415 415
416 switch (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)]) { 416 switch (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)]) {
417 case 0: /* If message is ping */ 417 case GROUP_CHAT_PING: /* If message is ping */
418 if (contents_len != 0) 418 if (contents_len != 0)
419 return 1; 419 return 1;
420 420
421 chat->group[peernum].last_recv_msgping = unix_time(); 421 chat->group[peernum].last_recv_msgping = unix_time();
422 break; 422 break;
423 423
424 case 16: /* If message is new peer */ 424 case GROUP_CHAT_NEW_PEER: /* If message is new peer */
425 if (contents_len != crypto_box_PUBLICKEYBYTES) 425 if (contents_len != crypto_box_PUBLICKEYBYTES)
426 return 1; 426 return 1;
427 427
428 addpeer(chat, contents); 428 addpeer(chat, contents);
429 break; 429 break;
430 430
431 case 64: /* If message is chat message */ 431 case GROUP_CHAT_CHAT_MESSAGE: /* If message is chat message */
432 if (chat->group_message != NULL) 432 if (chat->group_message != NULL)
433 (*chat->group_message)(chat, peernum, contents, contents_len, chat->group_message_userdata); 433 (*chat->group_message)(chat, peernum, contents, contents_len, chat->group_message_userdata);
434 434
@@ -441,7 +441,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
441 } 441 }
442 442
443 if (handled == 1) { 443 if (handled == 1) {
444 sendto_allpeers(chat, data, len, 50); 444 sendto_allpeers(chat, data, len, CRYPTO_PACKET_GROUP_CHAT_BROADCAST);
445 return 0; 445 return 0;
446 } 446 }
447 447
@@ -468,7 +468,7 @@ static uint8_t send_data(Group_Chat *chat, uint8_t *data, uint32_t len, uint8_t
468 memcpy(packet + GROUP_DATA_MIN_SIZE, data, len); 468 memcpy(packet + GROUP_DATA_MIN_SIZE, data, len);
469 469
470 packet[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] = message_id; 470 packet[crypto_box_PUBLICKEYBYTES + sizeof(message_num)] = message_id;
471 return sendto_allpeers(chat, packet, len + GROUP_DATA_MIN_SIZE, 50); 471 return sendto_allpeers(chat, packet, len + GROUP_DATA_MIN_SIZE, CRYPTO_PACKET_GROUP_CHAT_BROADCAST);
472} 472}
473/* 473/*
474 * Handle get nodes group packet. 474 * Handle get nodes group packet.
@@ -499,13 +499,13 @@ int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, ui
499 return 1; 499 return 1;
500 500
501 switch (number) { 501 switch (number) {
502 case 48: 502 case CRYPTO_PACKET_GROUP_CHAT_GET_NODES:
503 return handle_getnodes(chat, source, peernum, data, len); 503 return handle_getnodes(chat, source, peernum, data, len);
504 504
505 case 49: 505 case CRYPTO_PACKET_GROUP_CHAT_SEND_NODES:
506 return handle_sendnodes(chat, source, peernum, data, len); 506 return handle_sendnodes(chat, source, peernum, data, len);
507 507
508 case 50: 508 case CRYPTO_PACKET_GROUP_CHAT_BROADCAST:
509 return handle_data(chat, data, len); 509 return handle_data(chat, data, len);
510 510
511 default: 511 default:
@@ -517,13 +517,13 @@ int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, ui
517 517
518uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length) 518uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length)
519{ 519{
520 return send_data(chat, message, length, 64); //TODO: better return values? 520 return send_data(chat, message, length, GROUP_CHAT_CHAT_MESSAGE); //TODO: better return values?
521} 521}
522 522
523uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id) 523uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id)
524{ 524{
525 addpeer(chat, client_id); 525 addpeer(chat, client_id);
526 return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, 16); //TODO: better return values? 526 return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, GROUP_CHAT_NEW_PEER); //TODO: better return values?
527} 527}
528 528
529void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *), 529void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *),
@@ -572,7 +572,7 @@ static void ping_close(Group_Chat *chat)
572static void ping_group(Group_Chat *chat) 572static void ping_group(Group_Chat *chat)
573{ 573{
574 if (is_timeout(chat->last_sent_ping, GROUP_PING_INTERVAL)) { 574 if (is_timeout(chat->last_sent_ping, GROUP_PING_INTERVAL)) {
575 if (send_data(chat, 0, 0, 0) != 0) /* Ping */ 575 if (send_data(chat, 0, 0, GROUP_CHAT_PING) != 0) /* Ping */
576 chat->last_sent_ping = unix_time(); 576 chat->last_sent_ping = unix_time();
577 } 577 }
578} 578}
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h
index 8afe95e2..b3f2e5a8 100644
--- a/toxcore/group_chats.h
+++ b/toxcore/group_chats.h
@@ -67,6 +67,10 @@ typedef struct Group_Chat {
67 67
68} Group_Chat; 68} Group_Chat;
69 69
70#define GROUP_CHAT_PING 0
71#define GROUP_CHAT_NEW_PEER 16
72#define GROUP_CHAT_CHAT_MESSAGE 64
73
70/* Copy the name of peernum to name. 74/* Copy the name of peernum to name.
71 * name must be at least MAX_NICK_BYTES long. 75 * name must be at least MAX_NICK_BYTES long.
72 * 76 *
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 0de66e98..34683148 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -28,6 +28,9 @@
28 28
29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */ 29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */
30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */ 30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */
31#define CRYPTO_PACKET_GROUP_CHAT_GET_NODES 48 /* Group chat get Nodes packet */
32#define CRYPTO_PACKET_GROUP_CHAT_SEND_NODES 49 /* Group chat send Nodes packet */
33#define CRYPTO_PACKET_GROUP_CHAT_BROADCAST 50 /* Group chat broadcast packet */
31#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2) 34#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)
32 35
33#define CRYPTO_CONN_NO_CONNECTION 0 36#define CRYPTO_CONN_NO_CONNECTION 0