summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c3
-rw-r--r--toxcore/group_chats.c8
-rw-r--r--toxcore/network.c24
-rw-r--r--toxcore/network.h12
4 files changed, 33 insertions, 14 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 57cafc3f..c2971a70 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -732,7 +732,8 @@ static int group_num(Messenger *m, uint8_t *group_public_key)
732 uint32_t i; 732 uint32_t i;
733 733
734 for (i = 0; i < m->numchats; ++i) { 734 for (i = 0; i < m->numchats; ++i) {
735 if (id_equal(m->chats[i]->self_public_key, group_public_key)) 735 if (m->chats[i] != NULL)
736 if (id_equal(m->chats[i]->self_public_key, group_public_key))
736 return i; 737 return i;
737 } 738 }
738 739
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index 5376713c..5a68bc1a 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -393,6 +393,7 @@ static int handle_sendnodes(Group_Chat *chat, IP_Port source, int peernum, uint8
393} 393}
394 394
395#define GROUP_DATA_MIN_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + 1) 395#define GROUP_DATA_MIN_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + 1)
396static void send_names_new_peer(Group_Chat *chat);
396 397
397static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len) 398static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
398{ 399{
@@ -445,6 +446,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
445 return 1; 446 return 1;
446 447
447 addpeer(chat, contents); 448 addpeer(chat, contents);
449 send_names_new_peer(chat);
448 break; 450 break;
449 451
450 case GROUP_CHAT_PEER_NICK: 452 case GROUP_CHAT_PEER_NICK:
@@ -638,7 +640,11 @@ static void del_dead_peers(Group_Chat *chat)
638} 640}
639 641
640#define NICK_SEND_INTERVAL 180 642#define NICK_SEND_INTERVAL 180
641 643static void send_names_new_peer(Group_Chat *chat)
644{
645 group_send_nick(chat, chat->nick, chat->nick_len);
646 chat->last_sent_nick = (unix_time() - NICK_SEND_INTERVAL) + 10;
647}
642static void send_names(Group_Chat *chat) 648static void send_names(Group_Chat *chat)
643{ 649{
644 /* send own nick from time to time, to let newly added peers be informed 650 /* send own nick from time to time, to let newly added peers be informed
diff --git a/toxcore/network.c b/toxcore/network.c
index 0f96083c..e5a80254 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -278,7 +278,7 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl
278void networking_poll(Networking_Core *net) 278void networking_poll(Networking_Core *net)
279{ 279{
280 unix_time_update(); 280 unix_time_update();
281 281
282 IP_Port ip_port; 282 IP_Port ip_port;
283 uint8_t data[MAX_UDP_PACKET_SIZE]; 283 uint8_t data[MAX_UDP_PACKET_SIZE];
284 uint32_t length; 284 uint32_t length;
@@ -373,13 +373,15 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds)
373 /* returns -1 on error, 0 on timeout, the socket on activity */ 373 /* returns -1 on error, 0 on timeout, the socket on activity */
374 int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout); 374 int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
375#ifdef LOGGING 375#ifdef LOGGING
376
376 /* only dump if not timeout */ 377 /* only dump if not timeout */
377 if (res) { 378 if (res) {
378 sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno, 379 sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno,
379 strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds), 380 strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
380 FD_ISSET(s->sock, &exceptfds)); 381 FD_ISSET(s->sock, &exceptfds));
381 loglog(logbuffer); 382 loglog(logbuffer);
382 } 383 }
384
383#endif 385#endif
384 386
385 if (FD_ISSET(s->sock, &writefds)) 387 if (FD_ISSET(s->sock, &writefds))
@@ -527,14 +529,14 @@ Networking_Core *new_networking(IP ip, uint16_t port)
527 } else 529 } else
528 return NULL; 530 return NULL;
529 531
530 if (ip.family == AF_INET6) 532 if (ip.family == AF_INET6) {
531 {
532 char ipv6only = 0; 533 char ipv6only = 0;
533 socklen_t optsize = sizeof(ipv6only); 534 socklen_t optsize = sizeof(ipv6only);
534#ifdef LOGGING 535#ifdef LOGGING
535 errno = 0; 536 errno = 0;
536#endif 537#endif
537 int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize); 538 int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize);
539
538 if ((res == 0) && (ipv6only == 0)) { 540 if ((res == 0) && (ipv6only == 0)) {
539#ifdef LOGGING 541#ifdef LOGGING
540 loglog("Dual-stack socket: enabled per default.\n"); 542 loglog("Dual-stack socket: enabled per default.\n");
@@ -542,6 +544,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
542 } else { 544 } else {
543 ipv6only = 0; 545 ipv6only = 0;
544#ifdef LOGGING 546#ifdef LOGGING
547
545 if (res < 0) { 548 if (res < 0) {
546 sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n", 549 sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n",
547 errno, strerror(errno)); 550 errno, strerror(errno));
@@ -551,8 +554,9 @@ Networking_Core *new_networking(IP ip, uint16_t port)
551 errno = 0; 554 errno = 0;
552 res = 555 res =
553#endif 556#endif
554 setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)); 557 setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only));
555#ifdef LOGGING 558#ifdef LOGGING
559
556 if (res < 0) { 560 if (res < 0) {
557 sprintf(logbuffer, 561 sprintf(logbuffer,
558 "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n", 562 "Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n",
@@ -560,6 +564,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
560 loglog(logbuffer); 564 loglog(logbuffer);
561 } else 565 } else
562 loglog("Dual-stack socket: Enabled successfully.\n"); 566 loglog("Dual-stack socket: Enabled successfully.\n");
567
563#endif 568#endif
564 } 569 }
565 570
@@ -607,8 +612,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
607 *portptr = htons(port_to_try); 612 *portptr = htons(port_to_try);
608 int tries, res; 613 int tries, res;
609 614
610 for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) 615 for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) {
611 {
612 res = bind(temp->sock, (struct sockaddr *)&addr, addrsize); 616 res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
613 617
614 if (!res) { 618 if (!res) {
@@ -674,11 +678,7 @@ int ip_equal(IP *a, IP *b)
674 if (a->family == AF_INET) 678 if (a->family == AF_INET)
675 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); 679 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
676 else if (a->family == AF_INET6) 680 else if (a->family == AF_INET6)
677#ifdef WIN32
678 return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
679#else
680 return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr); 681 return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
681#endif
682 else 682 else
683 return 0; 683 return 0;
684 } 684 }
diff --git a/toxcore/network.h b/toxcore/network.h
index 8b9b8b2f..504a12af 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -43,6 +43,18 @@ typedef unsigned int sock_t;
43/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */ 43/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */
44typedef short sa_family_t; 44typedef short sa_family_t;
45 45
46#ifndef IN6_ARE_ADDR_EQUAL
47#ifdef IN6_ADDR_EQUAL
48#define IN6_ARE_ADDR_EQUAL(a,b) IN6_ADDR_EQUAL(a,b)
49#else
50#define IN6_ARE_ADDR_EQUAL(a,b) \
51 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
52 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
53 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
54 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
55#endif
56#endif
57
46#ifndef EWOULDBLOCK 58#ifndef EWOULDBLOCK
47#define EWOULDBLOCK WSAEWOULDBLOCK 59#define EWOULDBLOCK WSAEWOULDBLOCK
48#endif 60#endif