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 #define MAX_CONNECTIONS 256 -Connection connections[MAX_CONNECTIONS]; +static Connection connections[MAX_CONNECTIONS]; + +//static uint32_t numconnections; //Functions @@ -170,6 +172,7 @@ int new_connection(IP_Port ip_port) connections[i].SYNC_rate = SYNC_RATE; connections[i].data_rate = DATA_SYNC_RATE; connections[i].last_recvSYNC = current_time(); + connections[i].last_sent = current_time(); connections[i].killat = ~0; connections[i].send_counter = 0; return i; @@ -199,6 +202,7 @@ int new_inconnection(IP_Port ip_port) connections[i].SYNC_rate = SYNC_RATE; connections[i].data_rate = DATA_SYNC_RATE; connections[i].last_recvSYNC = current_time(); + connections[i].last_sent = current_time(); //if this connection isn't handled within 5 seconds, kill it connections[i].killat = current_time() + 1000000UL*CONNEXION_TIMEOUT; 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 }Friend; + +uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; + + #define MAX_NUM_FRIENDS 256 static Friend friendlist[MAX_NUM_FRIENDS]; static uint32_t numfriends; + +//1 if we are online +//0 if we are offline +//static uint8_t online; + //return the friend id associated to that public key. //return -1 if no such friend @@ -94,7 +103,10 @@ int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length) { return -1; } - + if(memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) + { + return -1; + } if(getfriend_id(client_id) != -1) { return -1; @@ -106,6 +118,7 @@ int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length) { DHT_addfriend(client_id); friendlist[i].status = 1; + friendlist[i].crypt_connection_id = -1; friendlist[i].friend_request_id = -1; memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); @@ -132,6 +145,7 @@ int m_addfriend_norequest(uint8_t * client_id) { DHT_addfriend(client_id); friendlist[i].status = 2; + friendlist[i].crypt_connection_id = -1; friendlist[i].friend_request_id = -1; memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); numfriends++; @@ -348,6 +362,7 @@ void doMessenger() printf("Received handled packet with length: %u\n", length); } //} + printf("Status: %u %u\n",friendlist[0].status ,is_cryptoconnected(friendlist[0].crypt_connection_id) ); #else DHT_handlepacket(data, length, ip_port); LosslessUDP_handlepacket(data, length, ip_port); @@ -361,3 +376,4 @@ void doMessenger() doFriendRequest(); doFriends(); } + 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 @@ #include "nTox.h" + +#ifdef WIN32 +#define c_sleep(x) Sleep(1*x) +#else +#include +#define c_sleep(x) usleep(1000*x) +#endif + char lines[HISTORY][STRING_LENGTH]; char line[STRING_LENGTH]; int x,y; @@ -212,6 +220,7 @@ int main(int argc, char *argv[]) } } doMessenger(); + c_sleep(1); do_refresh(); } endwin();