diff options
-rw-r--r-- | core/Lossless_UDP.c | 6 | ||||
-rw-r--r-- | core/Messenger.c | 18 | ||||
-rw-r--r-- | testing/nTox.c | 9 |
3 files changed, 31 insertions, 2 deletions
diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index 06e05fdb..e61c04bc 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c | |||
@@ -89,7 +89,9 @@ typedef struct | |||
89 | 89 | ||
90 | #define MAX_CONNECTIONS 256 | 90 | #define MAX_CONNECTIONS 256 |
91 | 91 | ||
92 | Connection connections[MAX_CONNECTIONS]; | 92 | static Connection connections[MAX_CONNECTIONS]; |
93 | |||
94 | //static uint32_t numconnections; | ||
93 | 95 | ||
94 | //Functions | 96 | //Functions |
95 | 97 | ||
@@ -170,6 +172,7 @@ int new_connection(IP_Port ip_port) | |||
170 | connections[i].SYNC_rate = SYNC_RATE; | 172 | connections[i].SYNC_rate = SYNC_RATE; |
171 | connections[i].data_rate = DATA_SYNC_RATE; | 173 | connections[i].data_rate = DATA_SYNC_RATE; |
172 | connections[i].last_recvSYNC = current_time(); | 174 | connections[i].last_recvSYNC = current_time(); |
175 | connections[i].last_sent = current_time(); | ||
173 | connections[i].killat = ~0; | 176 | connections[i].killat = ~0; |
174 | connections[i].send_counter = 0; | 177 | connections[i].send_counter = 0; |
175 | return i; | 178 | return i; |
@@ -199,6 +202,7 @@ int new_inconnection(IP_Port ip_port) | |||
199 | connections[i].SYNC_rate = SYNC_RATE; | 202 | connections[i].SYNC_rate = SYNC_RATE; |
200 | connections[i].data_rate = DATA_SYNC_RATE; | 203 | connections[i].data_rate = DATA_SYNC_RATE; |
201 | connections[i].last_recvSYNC = current_time(); | 204 | connections[i].last_recvSYNC = current_time(); |
205 | connections[i].last_sent = current_time(); | ||
202 | //if this connection isn't handled within 5 seconds, kill it | 206 | //if this connection isn't handled within 5 seconds, kill it |
203 | connections[i].killat = current_time() + 1000000UL*CONNEXION_TIMEOUT; | 207 | connections[i].killat = current_time() + 1000000UL*CONNEXION_TIMEOUT; |
204 | connections[i].send_counter = 127; | 208 | connections[i].send_counter = 127; |
diff --git a/core/Messenger.c b/core/Messenger.c index 85c5df95..25313db0 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -36,11 +36,20 @@ typedef struct | |||
36 | }Friend; | 36 | }Friend; |
37 | 37 | ||
38 | 38 | ||
39 | |||
40 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | ||
41 | |||
42 | |||
39 | #define MAX_NUM_FRIENDS 256 | 43 | #define MAX_NUM_FRIENDS 256 |
40 | 44 | ||
41 | static Friend friendlist[MAX_NUM_FRIENDS]; | 45 | static Friend friendlist[MAX_NUM_FRIENDS]; |
42 | 46 | ||
43 | static uint32_t numfriends; | 47 | static uint32_t numfriends; |
48 | |||
49 | //1 if we are online | ||
50 | //0 if we are offline | ||
51 | //static uint8_t online; | ||
52 | |||
44 | 53 | ||
45 | //return the friend id associated to that public key. | 54 | //return the friend id associated to that public key. |
46 | //return -1 if no such friend | 55 | //return -1 if no such friend |
@@ -94,7 +103,10 @@ int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length) | |||
94 | { | 103 | { |
95 | return -1; | 104 | return -1; |
96 | } | 105 | } |
97 | 106 | if(memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) | |
107 | { | ||
108 | return -1; | ||
109 | } | ||
98 | if(getfriend_id(client_id) != -1) | 110 | if(getfriend_id(client_id) != -1) |
99 | { | 111 | { |
100 | return -1; | 112 | return -1; |
@@ -106,6 +118,7 @@ int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length) | |||
106 | { | 118 | { |
107 | DHT_addfriend(client_id); | 119 | DHT_addfriend(client_id); |
108 | friendlist[i].status = 1; | 120 | friendlist[i].status = 1; |
121 | friendlist[i].crypt_connection_id = -1; | ||
109 | friendlist[i].friend_request_id = -1; | 122 | friendlist[i].friend_request_id = -1; |
110 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); | 123 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); |
111 | 124 | ||
@@ -132,6 +145,7 @@ int m_addfriend_norequest(uint8_t * client_id) | |||
132 | { | 145 | { |
133 | DHT_addfriend(client_id); | 146 | DHT_addfriend(client_id); |
134 | friendlist[i].status = 2; | 147 | friendlist[i].status = 2; |
148 | friendlist[i].crypt_connection_id = -1; | ||
135 | friendlist[i].friend_request_id = -1; | 149 | friendlist[i].friend_request_id = -1; |
136 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); | 150 | memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); |
137 | numfriends++; | 151 | numfriends++; |
@@ -348,6 +362,7 @@ void doMessenger() | |||
348 | printf("Received handled packet with length: %u\n", length); | 362 | printf("Received handled packet with length: %u\n", length); |
349 | } | 363 | } |
350 | //} | 364 | //} |
365 | printf("Status: %u %u\n",friendlist[0].status ,is_cryptoconnected(friendlist[0].crypt_connection_id) ); | ||
351 | #else | 366 | #else |
352 | DHT_handlepacket(data, length, ip_port); | 367 | DHT_handlepacket(data, length, ip_port); |
353 | LosslessUDP_handlepacket(data, length, ip_port); | 368 | LosslessUDP_handlepacket(data, length, ip_port); |
@@ -361,3 +376,4 @@ void doMessenger() | |||
361 | doFriendRequest(); | 376 | doFriendRequest(); |
362 | doFriends(); | 377 | doFriends(); |
363 | } | 378 | } |
379 | |||
diff --git a/testing/nTox.c b/testing/nTox.c index 937d9d54..acc0be89 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -1,4 +1,12 @@ | |||
1 | #include "nTox.h" | 1 | #include "nTox.h" |
2 | |||
3 | #ifdef WIN32 | ||
4 | #define c_sleep(x) Sleep(1*x) | ||
5 | #else | ||
6 | #include <unistd.h> | ||
7 | #define c_sleep(x) usleep(1000*x) | ||
8 | #endif | ||
9 | |||
2 | char lines[HISTORY][STRING_LENGTH]; | 10 | char lines[HISTORY][STRING_LENGTH]; |
3 | char line[STRING_LENGTH]; | 11 | char line[STRING_LENGTH]; |
4 | int x,y; | 12 | int x,y; |
@@ -212,6 +220,7 @@ int main(int argc, char *argv[]) | |||
212 | } | 220 | } |
213 | } | 221 | } |
214 | doMessenger(); | 222 | doMessenger(); |
223 | c_sleep(1); | ||
215 | do_refresh(); | 224 | do_refresh(); |
216 | } | 225 | } |
217 | endwin(); | 226 | endwin(); |