diff options
author | Jfreegman <Jfreegman@gmail.com> | 2013-08-05 13:42:15 -0400 |
---|---|---|
committer | Jfreegman <Jfreegman@gmail.com> | 2013-08-05 13:42:15 -0400 |
commit | a91aee0a9f4945ee3124e9e03f535e8ab4a40ce3 (patch) | |
tree | 1187850a0ac0c429bd610c638cc60c49cab9daaf | |
parent | 29880b4299a1eedcf1b8c732925a088b54be1358 (diff) | |
parent | dc3fe775fca468ace65165fa1178b8d35397e20a (diff) |
Merge remote-tracking branch 'upstream/master' into testing
-rw-r--r-- | core/DHT.c | 12 | ||||
-rw-r--r-- | core/DHT.h | 4 | ||||
-rw-r--r-- | core/LAN_discovery.c | 2 | ||||
-rw-r--r-- | core/Lossless_UDP.c | 14 | ||||
-rw-r--r-- | core/Lossless_UDP.h | 4 | ||||
-rw-r--r-- | core/Messenger.c | 16 | ||||
-rw-r--r-- | core/Messenger.h | 6 | ||||
-rw-r--r-- | core/net_crypto.c | 12 | ||||
-rw-r--r-- | core/net_crypto.h | 6 | ||||
-rw-r--r-- | core/network.c | 6 | ||||
-rw-r--r-- | core/network.h | 6 | ||||
-rw-r--r-- | testing/nTox.c | 30 | ||||
-rw-r--r-- | testing/nTox_win32.c | 29 |
13 files changed, 88 insertions, 59 deletions
@@ -873,7 +873,7 @@ IP_Port DHT_getfriendip(uint8_t * client_id) | |||
873 | /* Ping each client in the "friends" list every 60 seconds. Send a get nodes request | 873 | /* Ping each client in the "friends" list every 60 seconds. Send a get nodes request |
874 | * every 20 seconds to a random good node for each "friend" in our "friends" list. | 874 | * every 20 seconds to a random good node for each "friend" in our "friends" list. |
875 | */ | 875 | */ |
876 | void doDHTFriends() | 876 | static void doDHTFriends(void) |
877 | { | 877 | { |
878 | uint32_t i, j; | 878 | uint32_t i, j; |
879 | uint64_t temp_time = unix_time(); | 879 | uint64_t temp_time = unix_time(); |
@@ -912,7 +912,7 @@ static uint64_t close_lastgetnodes; | |||
912 | /* Ping each client in the close nodes list every 60 seconds. | 912 | /* Ping each client in the close nodes list every 60 seconds. |
913 | * Send a get nodes request every 20 seconds to a random good node in the list. | 913 | * Send a get nodes request every 20 seconds to a random good node in the list. |
914 | */ | 914 | */ |
915 | void doClose() | 915 | static void doClose(void) |
916 | { | 916 | { |
917 | uint32_t i; | 917 | uint32_t i; |
918 | uint64_t temp_time = unix_time(); | 918 | uint64_t temp_time = unix_time(); |
@@ -1211,7 +1211,7 @@ static void punch_holes(IP ip, uint16_t * port_list, uint16_t numports, uint16_t | |||
1211 | friends_list[friend_num].punching_index = i; | 1211 | friends_list[friend_num].punching_index = i; |
1212 | } | 1212 | } |
1213 | 1213 | ||
1214 | static void doNAT() | 1214 | static void doNAT(void) |
1215 | { | 1215 | { |
1216 | uint32_t i; | 1216 | uint32_t i; |
1217 | uint64_t temp_time = unix_time(); | 1217 | uint64_t temp_time = unix_time(); |
@@ -1275,7 +1275,7 @@ int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) | |||
1275 | return 0; | 1275 | return 0; |
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | void doDHT() | 1278 | void doDHT(void) |
1279 | { | 1279 | { |
1280 | doClose(); | 1280 | doClose(); |
1281 | doDHTFriends(); | 1281 | doDHTFriends(); |
@@ -1283,7 +1283,7 @@ void doDHT() | |||
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | /* get the size of the DHT (for saving) */ | 1285 | /* get the size of the DHT (for saving) */ |
1286 | uint32_t DHT_size() | 1286 | uint32_t DHT_size(void) |
1287 | { | 1287 | { |
1288 | return sizeof(close_clientlist) + sizeof(Friend) * num_friends; | 1288 | return sizeof(close_clientlist) + sizeof(Friend) * num_friends; |
1289 | } | 1289 | } |
@@ -1341,7 +1341,7 @@ int DHT_load(uint8_t * data, uint32_t size) | |||
1341 | /* returns 0 if we are not connected to the DHT | 1341 | /* returns 0 if we are not connected to the DHT |
1342 | * returns 1 if we are | 1342 | * returns 1 if we are |
1343 | */ | 1343 | */ |
1344 | int DHT_isconnected() | 1344 | int DHT_isconnected(void) |
1345 | { | 1345 | { |
1346 | uint32_t i; | 1346 | uint32_t i; |
1347 | uint64_t temp_time = unix_time(); | 1347 | uint64_t temp_time = unix_time(); |
@@ -58,7 +58,7 @@ int DHT_delfriend(uint8_t *client_id); | |||
58 | IP_Port DHT_getfriendip(uint8_t *client_id); | 58 | IP_Port DHT_getfriendip(uint8_t *client_id); |
59 | 59 | ||
60 | /* Run this function at least a couple times per second (It's the main loop) */ | 60 | /* Run this function at least a couple times per second (It's the main loop) */ |
61 | void doDHT(); | 61 | void doDHT(void); |
62 | 62 | ||
63 | /* if we receive a DHT packet we call this function so it can be handled. | 63 | /* if we receive a DHT packet we call this function so it can be handled. |
64 | return 0 if packet is handled correctly. | 64 | return 0 if packet is handled correctly. |
@@ -90,7 +90,7 @@ int friend_ips(IP_Port *ip_portlist, uint8_t *friend_id); | |||
90 | /* SAVE/LOAD functions */ | 90 | /* SAVE/LOAD functions */ |
91 | 91 | ||
92 | /* get the size of the DHT (for saving) */ | 92 | /* get the size of the DHT (for saving) */ |
93 | uint32_t DHT_size(); | 93 | uint32_t DHT_size(void); |
94 | 94 | ||
95 | /* save the DHT in data where data is an array of size DHT_size() */ | 95 | /* save the DHT in data where data is an array of size DHT_size() */ |
96 | void DHT_save(uint8_t *data); | 96 | void DHT_save(uint8_t *data); |
diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c index 67cbfe9a..55953685 100644 --- a/core/LAN_discovery.c +++ b/core/LAN_discovery.c | |||
@@ -76,7 +76,7 @@ static uint32_t get_broadcast(void) | |||
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | /* Return the broadcast ip */ | 78 | /* Return the broadcast ip */ |
79 | static IP broadcast_ip() | 79 | static IP broadcast_ip(void) |
80 | { | 80 | { |
81 | IP ip; | 81 | IP ip; |
82 | #ifdef __linux | 82 | #ifdef __linux |
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index 8538f76c..3a289735 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c | |||
@@ -284,7 +284,7 @@ static int new_inconnection(IP_Port ip_port) | |||
284 | * Returns an integer corresponding to the next connection in our incoming connection list. | 284 | * Returns an integer corresponding to the next connection in our incoming connection list. |
285 | * Return -1 if there are no new incoming connections in the list. | 285 | * Return -1 if there are no new incoming connections in the list. |
286 | */ | 286 | */ |
287 | int incoming_connection() | 287 | int incoming_connection(void) |
288 | { | 288 | { |
289 | uint32_t i; | 289 | uint32_t i; |
290 | for (i = 0; i < MAX_CONNECTIONS; ++i) { | 290 | for (i = 0; i < MAX_CONNECTIONS; ++i) { |
@@ -298,7 +298,7 @@ int incoming_connection() | |||
298 | } | 298 | } |
299 | 299 | ||
300 | /* Try to free some memory from the connections array. */ | 300 | /* Try to free some memory from the connections array. */ |
301 | static void free_connections() | 301 | static void free_connections(void) |
302 | { | 302 | { |
303 | uint32_t i; | 303 | uint32_t i; |
304 | for(i = connections_length; i != 0; --i) | 304 | for(i = connections_length; i != 0; --i) |
@@ -793,7 +793,7 @@ int LosslessUDP_handlepacket(uint8_t *packet, uint32_t length, IP_Port source) | |||
793 | * Send handshake requests | 793 | * Send handshake requests |
794 | * handshake packets are sent at the same rate as SYNC packets | 794 | * handshake packets are sent at the same rate as SYNC packets |
795 | */ | 795 | */ |
796 | static void doNew() | 796 | static void doNew(void) |
797 | { | 797 | { |
798 | uint32_t i; | 798 | uint32_t i; |
799 | uint64_t temp_time = current_time(); | 799 | uint64_t temp_time = current_time(); |
@@ -817,7 +817,7 @@ static void doNew() | |||
817 | } | 817 | } |
818 | } | 818 | } |
819 | 819 | ||
820 | static void doSYNC() | 820 | static void doSYNC(void) |
821 | { | 821 | { |
822 | uint32_t i; | 822 | uint32_t i; |
823 | uint64_t temp_time = current_time(); | 823 | uint64_t temp_time = current_time(); |
@@ -830,7 +830,7 @@ static void doSYNC() | |||
830 | } | 830 | } |
831 | } | 831 | } |
832 | 832 | ||
833 | static void doData() | 833 | static void doData(void) |
834 | { | 834 | { |
835 | uint32_t i; | 835 | uint32_t i; |
836 | uint64_t j; | 836 | uint64_t j; |
@@ -851,7 +851,7 @@ static void doData() | |||
851 | * | 851 | * |
852 | * TODO: flow control. | 852 | * TODO: flow control. |
853 | */ | 853 | */ |
854 | static void adjustRates() | 854 | static void adjustRates(void) |
855 | { | 855 | { |
856 | uint32_t i; | 856 | uint32_t i; |
857 | uint64_t temp_time = current_time(); | 857 | uint64_t temp_time = current_time(); |
@@ -871,7 +871,7 @@ static void adjustRates() | |||
871 | } | 871 | } |
872 | 872 | ||
873 | /* Call this function a couple times per second It's the main loop. */ | 873 | /* Call this function a couple times per second It's the main loop. */ |
874 | void doLossless_UDP() | 874 | void doLossless_UDP(void) |
875 | { | 875 | { |
876 | doNew(); | 876 | doNew(); |
877 | doSYNC(); | 877 | doSYNC(); |
diff --git a/core/Lossless_UDP.h b/core/Lossless_UDP.h index 75ef273e..b4cb186a 100644 --- a/core/Lossless_UDP.h +++ b/core/Lossless_UDP.h | |||
@@ -52,7 +52,7 @@ int getconnection_id(IP_Port ip_port); | |||
52 | * Returns an int corresponding to the next connection in our imcoming connection list | 52 | * Returns an int corresponding to the next connection in our imcoming connection list |
53 | * Return -1 if there are no new incoming connections in the list. | 53 | * Return -1 if there are no new incoming connections in the list. |
54 | */ | 54 | */ |
55 | int incoming_connection(); | 55 | int incoming_connection(void); |
56 | 56 | ||
57 | /* | 57 | /* |
58 | * Return -1 if it could not kill the connection. | 58 | * Return -1 if it could not kill the connection. |
@@ -110,7 +110,7 @@ uint32_t recvqueue(int connection_id); | |||
110 | int is_connected(int connection_id); | 110 | int is_connected(int connection_id); |
111 | 111 | ||
112 | /* Call this function a couple times per second It's the main loop. */ | 112 | /* Call this function a couple times per second It's the main loop. */ |
113 | void doLossless_UDP(); | 113 | void doLossless_UDP(void); |
114 | 114 | ||
115 | /* | 115 | /* |
116 | * If we receive a Lossless_UDP packet, call this function so it can be handled. | 116 | * If we receive a Lossless_UDP packet, call this function so it can be handled. |
diff --git a/core/Messenger.c b/core/Messenger.c index c768633e..57d485bb 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -114,7 +114,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) | |||
114 | return FAERR_ALREADYSENT; | 114 | return FAERR_ALREADYSENT; |
115 | 115 | ||
116 | uint32_t i; | 116 | uint32_t i; |
117 | for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ | 117 | for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ |
118 | if(friendlist[i].status == NOFRIEND) { | 118 | if(friendlist[i].status == NOFRIEND) { |
119 | DHT_addfriend(client_id); | 119 | DHT_addfriend(client_id); |
120 | friendlist[i].status = FRIEND_ADDED; | 120 | friendlist[i].status = FRIEND_ADDED; |
@@ -138,7 +138,7 @@ int m_addfriend_norequest(uint8_t * client_id) | |||
138 | if (getfriend_id(client_id) != -1) | 138 | if (getfriend_id(client_id) != -1) |
139 | return -1; | 139 | return -1; |
140 | uint32_t i; | 140 | uint32_t i; |
141 | for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ | 141 | for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */ |
142 | if(friendlist[i].status == NOFRIEND) { | 142 | if(friendlist[i].status == NOFRIEND) { |
143 | DHT_addfriend(client_id); | 143 | DHT_addfriend(client_id); |
144 | friendlist[i].status = FRIEND_REQUESTED; | 144 | friendlist[i].status = FRIEND_REQUESTED; |
@@ -363,7 +363,7 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t)) | |||
363 | 363 | ||
364 | #define PORT 33445 | 364 | #define PORT 33445 |
365 | /* run this at startup */ | 365 | /* run this at startup */ |
366 | int initMessenger() | 366 | int initMessenger(void) |
367 | { | 367 | { |
368 | new_keys(); | 368 | new_keys(); |
369 | m_set_userstatus((uint8_t*)"Online", sizeof("Online")); | 369 | m_set_userstatus((uint8_t*)"Online", sizeof("Online")); |
@@ -378,7 +378,7 @@ int initMessenger() | |||
378 | } | 378 | } |
379 | 379 | ||
380 | //TODO: make this function not suck. | 380 | //TODO: make this function not suck. |
381 | static void doFriends() | 381 | static void doFriends(void) |
382 | { | 382 | { |
383 | /* TODO: add incoming connections and some other stuff. */ | 383 | /* TODO: add incoming connections and some other stuff. */ |
384 | uint32_t i; | 384 | uint32_t i; |
@@ -464,7 +464,7 @@ static void doFriends() | |||
464 | } | 464 | } |
465 | } | 465 | } |
466 | 466 | ||
467 | static void doInbound() | 467 | static void doInbound(void) |
468 | { | 468 | { |
469 | uint8_t secret_nonce[crypto_box_NONCEBYTES]; | 469 | uint8_t secret_nonce[crypto_box_NONCEBYTES]; |
470 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 470 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
@@ -488,7 +488,7 @@ static void doInbound() | |||
488 | static uint64_t last_LANdiscovery; | 488 | static uint64_t last_LANdiscovery; |
489 | 489 | ||
490 | /*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ | 490 | /*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ |
491 | static void LANdiscovery() | 491 | static void LANdiscovery(void) |
492 | { | 492 | { |
493 | if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { | 493 | if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { |
494 | send_LANdiscovery(htons(PORT)); | 494 | send_LANdiscovery(htons(PORT)); |
@@ -498,7 +498,7 @@ static void LANdiscovery() | |||
498 | 498 | ||
499 | 499 | ||
500 | /* the main loop that needs to be run at least 200 times per second. */ | 500 | /* the main loop that needs to be run at least 200 times per second. */ |
501 | void doMessenger() | 501 | void doMessenger(void) |
502 | { | 502 | { |
503 | IP_Port ip_port; | 503 | IP_Port ip_port; |
504 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 504 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
@@ -532,7 +532,7 @@ void doMessenger() | |||
532 | } | 532 | } |
533 | 533 | ||
534 | /* returns the size of the messenger data (for saving) */ | 534 | /* returns the size of the messenger data (for saving) */ |
535 | uint32_t Messenger_size() | 535 | uint32_t Messenger_size(void) |
536 | { | 536 | { |
537 | return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES | 537 | return crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES |
538 | + sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * numfriends; | 538 | + sizeof(uint32_t) + DHT_size() + sizeof(uint32_t) + sizeof(Friend) * numfriends; |
diff --git a/core/Messenger.h b/core/Messenger.h index acf62a32..20b38caa 100644 --- a/core/Messenger.h +++ b/core/Messenger.h | |||
@@ -160,15 +160,15 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t)); | |||
160 | /* run this at startup | 160 | /* run this at startup |
161 | returns 0 if no connection problems | 161 | returns 0 if no connection problems |
162 | returns -1 if there are problems */ | 162 | returns -1 if there are problems */ |
163 | int initMessenger(); | 163 | int initMessenger(void); |
164 | 164 | ||
165 | /* the main loop that needs to be run at least 200 times per second */ | 165 | /* the main loop that needs to be run at least 200 times per second */ |
166 | void doMessenger(); | 166 | void doMessenger(void); |
167 | 167 | ||
168 | /* SAVING AND LOADING FUNCTIONS: */ | 168 | /* SAVING AND LOADING FUNCTIONS: */ |
169 | 169 | ||
170 | /* returns the size of the messenger data (for saving) */ | 170 | /* returns the size of the messenger data (for saving) */ |
171 | uint32_t Messenger_size(); | 171 | uint32_t Messenger_size(void); |
172 | 172 | ||
173 | /* save the messenger in data (must be allocated memory of size Messenger_size()) */ | 173 | /* save the messenger in data (must be allocated memory of size Messenger_size()) */ |
174 | void Messenger_save(uint8_t *data); | 174 | void Messenger_save(uint8_t *data); |
diff --git a/core/net_crypto.c b/core/net_crypto.c index 4ce173c5..1c56b95a 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c | |||
@@ -440,7 +440,7 @@ int is_cryptoconnected(int crypt_connection_id) | |||
440 | 440 | ||
441 | /* Generate our public and private keys | 441 | /* Generate our public and private keys |
442 | Only call this function the first time the program starts. */ | 442 | Only call this function the first time the program starts. */ |
443 | void new_keys() | 443 | void new_keys(void) |
444 | { | 444 | { |
445 | crypto_box_keypair(self_public_key,self_secret_key); | 445 | crypto_box_keypair(self_public_key,self_secret_key); |
446 | } | 446 | } |
@@ -479,7 +479,7 @@ static int new_incoming(int id) | |||
479 | 479 | ||
480 | /* TODO: optimize this | 480 | /* TODO: optimize this |
481 | handle all new incoming connections. */ | 481 | handle all new incoming connections. */ |
482 | static void handle_incomings() | 482 | static void handle_incomings(void) |
483 | { | 483 | { |
484 | int income; | 484 | int income; |
485 | while (1) { | 485 | while (1) { |
@@ -490,7 +490,7 @@ static void handle_incomings() | |||
490 | } | 490 | } |
491 | 491 | ||
492 | /* handle received packets for not yet established crypto connections. */ | 492 | /* handle received packets for not yet established crypto connections. */ |
493 | static void receive_crypto() | 493 | static void receive_crypto(void) |
494 | { | 494 | { |
495 | uint32_t i; | 495 | uint32_t i; |
496 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { | 496 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { |
@@ -547,7 +547,7 @@ static void receive_crypto() | |||
547 | 547 | ||
548 | /* run this to (re)initialize net_crypto | 548 | /* run this to (re)initialize net_crypto |
549 | sets all the global connection variables to their default values. */ | 549 | sets all the global connection variables to their default values. */ |
550 | void initNetCrypto() | 550 | void initNetCrypto(void) |
551 | { | 551 | { |
552 | memset(crypto_connections, 0 ,sizeof(crypto_connections)); | 552 | memset(crypto_connections, 0 ,sizeof(crypto_connections)); |
553 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); | 553 | memset(incoming_connections, -1 ,sizeof(incoming_connections)); |
@@ -556,7 +556,7 @@ void initNetCrypto() | |||
556 | crypto_connections[i].number = ~0; | 556 | crypto_connections[i].number = ~0; |
557 | } | 557 | } |
558 | 558 | ||
559 | static void killTimedout() | 559 | static void killTimedout(void) |
560 | { | 560 | { |
561 | uint32_t i; | 561 | uint32_t i; |
562 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { | 562 | for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { |
@@ -570,7 +570,7 @@ static void killTimedout() | |||
570 | } | 570 | } |
571 | 571 | ||
572 | /* main loop */ | 572 | /* main loop */ |
573 | void doNetCrypto() | 573 | void doNetCrypto(void) |
574 | { | 574 | { |
575 | /* TODO:check if friend requests were sent correctly | 575 | /* TODO:check if friend requests were sent correctly |
576 | handle new incoming connections | 576 | handle new incoming connections |
diff --git a/core/net_crypto.h b/core/net_crypto.h index 0e7284c9..66634d45 100644 --- a/core/net_crypto.h +++ b/core/net_crypto.h | |||
@@ -110,7 +110,7 @@ int is_cryptoconnected(int crypt_connection_id); | |||
110 | 110 | ||
111 | /* Generate our public and private keys | 111 | /* Generate our public and private keys |
112 | Only call this function the first time the program starts. */ | 112 | Only call this function the first time the program starts. */ |
113 | void new_keys(); | 113 | void new_keys(void); |
114 | 114 | ||
115 | /* save the public and private keys to the keys array | 115 | /* save the public and private keys to the keys array |
116 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ | 116 | Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES */ |
@@ -122,10 +122,10 @@ void load_keys(uint8_t * keys); | |||
122 | 122 | ||
123 | /* run this to (re)initialize net_crypto | 123 | /* run this to (re)initialize net_crypto |
124 | sets all the global connection variables to their default values. */ | 124 | sets all the global connection variables to their default values. */ |
125 | void initNetCrypto(); | 125 | void initNetCrypto(void); |
126 | 126 | ||
127 | /* main loop */ | 127 | /* main loop */ |
128 | void doNetCrypto(); | 128 | void doNetCrypto(void); |
129 | 129 | ||
130 | #ifdef __cplusplus | 130 | #ifdef __cplusplus |
131 | } | 131 | } |
diff --git a/core/network.c b/core/network.c index c58549bf..8c6fa7b6 100644 --- a/core/network.c +++ b/core/network.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "network.h" | 24 | #include "network.h" |
25 | 25 | ||
26 | /* returns current UNIX time in microseconds (us). */ | 26 | /* returns current UNIX time in microseconds (us). */ |
27 | uint64_t current_time() | 27 | uint64_t current_time(void) |
28 | { | 28 | { |
29 | uint64_t time; | 29 | uint64_t time; |
30 | #ifdef WIN32 | 30 | #ifdef WIN32 |
@@ -46,7 +46,7 @@ uint64_t current_time() | |||
46 | 46 | ||
47 | /* return a random number | 47 | /* return a random number |
48 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ | 48 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ |
49 | uint32_t random_int() | 49 | uint32_t random_int(void) |
50 | { | 50 | { |
51 | #ifndef VANILLA_NACL | 51 | #ifndef VANILLA_NACL |
52 | //NOTE: this function comes from libsodium | 52 | //NOTE: this function comes from libsodium |
@@ -153,7 +153,7 @@ int init_networking(IP ip, uint16_t port) | |||
153 | } | 153 | } |
154 | 154 | ||
155 | /* function to cleanup networking stuff */ | 155 | /* function to cleanup networking stuff */ |
156 | void shutdown_networking() | 156 | void shutdown_networking(void) |
157 | { | 157 | { |
158 | #ifdef WIN32 | 158 | #ifdef WIN32 |
159 | closesocket(sock); | 159 | closesocket(sock); |
diff --git a/core/network.h b/core/network.h index a7559ebe..d246a9d1 100644 --- a/core/network.h +++ b/core/network.h | |||
@@ -90,11 +90,11 @@ typedef struct { | |||
90 | } ADDR; | 90 | } ADDR; |
91 | 91 | ||
92 | /* returns current time in milleseconds since the epoch. */ | 92 | /* returns current time in milleseconds since the epoch. */ |
93 | uint64_t current_time(); | 93 | uint64_t current_time(void); |
94 | 94 | ||
95 | /* return a random number | 95 | /* return a random number |
96 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ | 96 | NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ |
97 | uint32_t random_int(); | 97 | uint32_t random_int(void); |
98 | 98 | ||
99 | /* Basic network functions: */ | 99 | /* Basic network functions: */ |
100 | 100 | ||
@@ -115,7 +115,7 @@ int receivepacket(IP_Port *ip_port, uint8_t *data, uint32_t *length); | |||
115 | int init_networking(IP ip, uint16_t port); | 115 | int init_networking(IP ip, uint16_t port); |
116 | 116 | ||
117 | /* function to cleanup networking stuff(doesn't do much right now) */ | 117 | /* function to cleanup networking stuff(doesn't do much right now) */ |
118 | void shutdown_networking(); | 118 | void shutdown_networking(void); |
119 | 119 | ||
120 | /* | 120 | /* |
121 | resolve_addr(): | 121 | resolve_addr(): |
diff --git a/testing/nTox.c b/testing/nTox.c index ec597bc3..fe91b1fa 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -42,7 +42,12 @@ char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message " | |||
42 | "name)\n/q (to quit)"; | 42 | "name)\n/q (to quit)"; |
43 | int x, y; | 43 | int x, y; |
44 | 44 | ||
45 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 45 | typedef struct { |
46 | uint8_t id[CLIENT_ID_SIZE]; | ||
47 | uint8_t accepted; | ||
48 | } Friend_request; | ||
49 | |||
50 | Friend_request pending_requests[256]; | ||
46 | uint8_t num_requests = 0; | 51 | uint8_t num_requests = 0; |
47 | 52 | ||
48 | void get_id(char *data) | 53 | void get_id(char *data) |
@@ -231,15 +236,21 @@ void line_eval(char *line) | |||
231 | else if (inpt_command == 'a') { | 236 | else if (inpt_command == 'a') { |
232 | uint8_t numf = atoi(line + 3); | 237 | uint8_t numf = atoi(line + 3); |
233 | char numchar[100]; | 238 | char numchar[100]; |
234 | int num = m_addfriend_norequest(pending_requests[numf]); | 239 | if (numf >= num_requests || pending_requests[numf].accepted) { |
235 | if (num != -1) { | 240 | sprintf(numchar,"[i] you either didn't receive that request or you already accepted it"); |
236 | sprintf(numchar, "[i] friend request %u accepted", numf); | ||
237 | new_lines(numchar); | ||
238 | sprintf(numchar, "[i] added friendnumber %d", num); | ||
239 | new_lines(numchar); | 241 | new_lines(numchar); |
240 | } else { | 242 | } else { |
241 | sprintf(numchar, "[i] failed to add friend"); | 243 | int num = m_addfriend_norequest(pending_requests[numf].id); |
242 | new_lines(numchar); | 244 | if (num != -1) { |
245 | pending_requests[numf].accepted = 1; | ||
246 | sprintf(numchar, "[i] friend request %u accepted", numf); | ||
247 | new_lines(numchar); | ||
248 | sprintf(numchar, "[i] added friendnumber %d", num); | ||
249 | new_lines(numchar); | ||
250 | } else { | ||
251 | sprintf(numchar, "[i] failed to add friend"); | ||
252 | new_lines(numchar); | ||
253 | } | ||
243 | } | 254 | } |
244 | do_refresh(); | 255 | do_refresh(); |
245 | } | 256 | } |
@@ -332,7 +343,8 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
332 | char numchar[100]; | 343 | char numchar[100]; |
333 | sprintf(numchar, "[i] accept request with /a %u", num_requests); | 344 | sprintf(numchar, "[i] accept request with /a %u", num_requests); |
334 | new_lines(numchar); | 345 | new_lines(numchar); |
335 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 346 | memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE); |
347 | pending_requests[num_requests].accepted = 0; | ||
336 | ++num_requests; | 348 | ++num_requests; |
337 | do_refresh(); | 349 | do_refresh(); |
338 | } | 350 | } |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 5501ecf5..f3c7a188 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -26,7 +26,12 @@ | |||
26 | 26 | ||
27 | #include <process.h> | 27 | #include <process.h> |
28 | 28 | ||
29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 29 | typedef struct { |
30 | uint8_t id[CLIENT_ID_SIZE]; | ||
31 | uint8_t accepted; | ||
32 | } Friend_request; | ||
33 | |||
34 | Friend_request pending_requests[256]; | ||
30 | uint8_t num_requests = 0; | 35 | uint8_t num_requests = 0; |
31 | uint32_t maxnumfriends; | 36 | uint32_t maxnumfriends; |
32 | 37 | ||
@@ -51,7 +56,8 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
51 | char numchar[100]; | 56 | char numchar[100]; |
52 | sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests); | 57 | sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests); |
53 | printf(numchar); | 58 | printf(numchar); |
54 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 59 | memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE); |
60 | pending_requests[num_requests].accepted = 0; | ||
55 | ++num_requests; | 61 | ++num_requests; |
56 | } | 62 | } |
57 | 63 | ||
@@ -287,10 +293,21 @@ void accept_friend_request() | |||
287 | friend_request_received = 0; | 293 | friend_request_received = 0; |
288 | uint8_t numf = atoi(line + 3); | 294 | uint8_t numf = atoi(line + 3); |
289 | char numchar[100]; | 295 | char numchar[100]; |
290 | int num = m_addfriend_norequest(pending_requests[numf]); | 296 | if (numf >= num_requests || pending_requests[numf].accepted) { |
291 | sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); | 297 | sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it"); |
292 | printf(numchar); | 298 | printf(numchar); |
293 | ++maxnumfriends; | 299 | } else { |
300 | int num = m_addfriend_norequest(pending_requests[numf].id); | ||
301 | if (num != -1) { | ||
302 | pending_requests[numf].accepted = 1; | ||
303 | sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); | ||
304 | printf(numchar); | ||
305 | ++maxnumfriends; | ||
306 | } else { | ||
307 | sprintf(numchar, "[i] failed to add friend"); | ||
308 | printf(numchar); | ||
309 | } | ||
310 | } | ||
294 | } | 311 | } |
295 | 312 | ||
296 | void line_eval(char* line) | 313 | void line_eval(char* line) |