summaryrefslogtreecommitdiff
path: root/core/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-16 19:02:44 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-16 19:02:44 -0400
commitbec416a05058ed821e9c16e3dda477abed41ec0d (patch)
tree72a07a325561e3fc7f12bb261bea16cf369eb7b8 /core/Messenger.c
parent5572396c5330d2464b5ce429eb71d69bde2ea39b (diff)
Fixed some bugs and a regression.
Diffstat (limited to 'core/Messenger.c')
-rw-r--r--core/Messenger.c18
1 files changed, 17 insertions, 1 deletions
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
40uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
41
42
39#define MAX_NUM_FRIENDS 256 43#define MAX_NUM_FRIENDS 256
40 44
41static Friend friendlist[MAX_NUM_FRIENDS]; 45static Friend friendlist[MAX_NUM_FRIENDS];
42 46
43static uint32_t numfriends; 47static 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