summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-15 08:16:38 -0700
committerirungentoo <irungentoo@gmail.com>2013-07-15 08:16:38 -0700
commit619ecb0bb35f62d39afdc91b87f5c267f905ec0c (patch)
tree4f197a641a4fcb8b60519c44368265454fc7f48a
parent7674e6572647a6c44daf2f064ef3c489c9878722 (diff)
parent859f31c160634547ecea8a0c857d55a1e68d1cc9 (diff)
Merge pull request #43 from Jeffail/master
Mostly superficial changes
-rw-r--r--.gitignore1
-rw-r--r--core/DHT.c5
-rw-r--r--core/Messenger.c43
3 files changed, 21 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 4c5c6d3f..263cdb90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
2 2
3//nacl build 3//nacl build
4nacl/build/ 4nacl/build/
5build
diff --git a/core/DHT.c b/core/DHT.c
index 42869c49..ce2ce6f8 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -126,6 +126,7 @@ int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_
126 { 126 {
127 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); 127 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
128 } 128 }
129
129 for(j = 0; j < CLIENT_ID_SIZE; j++) 130 for(j = 0; j < CLIENT_ID_SIZE; j++)
130 { 131 {
131 132
@@ -768,7 +769,7 @@ int DHT_addfriend(uint8_t * client_id)
768 { 769 {
769 temp = malloc(sizeof(Friend)); 770 temp = malloc(sizeof(Friend));
770 } 771 }
771 if(num_friends > 0) 772 else
772 { 773 {
773 temp = realloc(friends_list, sizeof(Friend) * (num_friends + 1)); 774 temp = realloc(friends_list, sizeof(Friend) * (num_friends + 1));
774 } 775 }
@@ -782,8 +783,6 @@ int DHT_addfriend(uint8_t * client_id)
782 memcpy(friends_list[num_friends].client_id, client_id, CLIENT_ID_SIZE); 783 memcpy(friends_list[num_friends].client_id, client_id, CLIENT_ID_SIZE);
783 num_friends++; 784 num_friends++;
784 return 0; 785 return 0;
785
786
787} 786}
788 787
789 788
diff --git a/core/Messenger.c b/core/Messenger.c
index 94b4c740..85c5df95 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -33,20 +33,14 @@ typedef struct
33 uint8_t status;//0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online. 33 uint8_t status;//0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online.
34 uint8_t info[MAX_DATA_SIZE]; //the data that is sent during the friend requests we do 34 uint8_t info[MAX_DATA_SIZE]; //the data that is sent during the friend requests we do
35 uint16_t info_size; //length of the info 35 uint16_t info_size; //length of the info
36
37}Friend; 36}Friend;
38 37
39 38
40
41
42
43#define MAX_NUM_FRIENDS 256 39#define MAX_NUM_FRIENDS 256
44 40
45static Friend friendlist[MAX_NUM_FRIENDS]; 41static Friend friendlist[MAX_NUM_FRIENDS];
46 42
47
48static uint32_t numfriends; 43static uint32_t numfriends;
49
50 44
51//return the friend id associated to that public key. 45//return the friend id associated to that public key.
52//return -1 if no such friend 46//return -1 if no such friend
@@ -66,6 +60,7 @@ int getfriend_id(uint8_t * client_id)
66 return -1; 60 return -1;
67} 61}
68 62
63
69//copies the public key associated to that friend id into client_id buffer. 64//copies the public key associated to that friend id into client_id buffer.
70//make sure that client_id is of size CLIENT_ID_SIZE. 65//make sure that client_id is of size CLIENT_ID_SIZE.
71//returns 0 if success 66//returns 0 if success
@@ -94,8 +89,8 @@ int getclient_id(int friend_id, uint8_t * client_id)
94//return -1 if failure. 89//return -1 if failure.
95int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length) 90int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length)
96{ 91{
97 if(length == 0 || length > MAX_DATA_SIZE - 1 - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES 92 if(length == 0 || length >=
98 - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES) 93 (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES))
99 { 94 {
100 return -1; 95 return -1;
101 } 96 }
@@ -105,7 +100,7 @@ int m_addfriend(uint8_t * client_id, uint8_t * data, uint16_t length)
105 return -1; 100 return -1;
106 } 101 }
107 uint32_t i; 102 uint32_t i;
108 for(i = 0; i < (numfriends + 1); i++) 103 for(i = 0; i <= numfriends; i++)
109 { 104 {
110 if(friendlist[i].status == 0) 105 if(friendlist[i].status == 0)
111 { 106 {
@@ -131,7 +126,7 @@ int m_addfriend_norequest(uint8_t * client_id)
131 return -1; 126 return -1;
132 } 127 }
133 uint32_t i; 128 uint32_t i;
134 for(i = 0; i < (numfriends + 1); i++) 129 for(i = 0; i <= numfriends; i++)
135 { 130 {
136 if(friendlist[i].status == 0) 131 if(friendlist[i].status == 0)
137 { 132 {
@@ -205,7 +200,6 @@ int m_sendmessage(int friendnumber, uint8_t * message, uint32_t length)
205 temp[0] = 64; 200 temp[0] = 64;
206 memcpy(temp + 1, message, length); 201 memcpy(temp + 1, message, length);
207 return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1); 202 return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, temp, length + 1);
208
209} 203}
210 204
211 205
@@ -236,7 +230,6 @@ void initMessenger()
236 IP ip; 230 IP ip;
237 ip.i = 0; 231 ip.i = 0;
238 init_networking(ip, PORT); 232 init_networking(ip, PORT);
239
240} 233}
241 234
242static void doFriends() 235static void doFriends()
@@ -261,19 +254,21 @@ static void doFriends()
261 if(friendlist[i].status == 2 || friendlist[i].status == 3) 254 if(friendlist[i].status == 2 || friendlist[i].status == 3)
262 { 255 {
263 check_friendrequest(friendlist[i].friend_request_id);//for now this is used to kill the friend request 256 check_friendrequest(friendlist[i].friend_request_id);//for now this is used to kill the friend request
264
265 IP_Port friendip = DHT_getfriendip(friendlist[i].client_id); 257 IP_Port friendip = DHT_getfriendip(friendlist[i].client_id);
266 if(is_cryptoconnected(friendlist[i].crypt_connection_id) == 0 && friendip.ip.i > 1) 258 switch(is_cryptoconnected(friendlist[i].crypt_connection_id))
267 {
268 friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip);
269 }
270 if(is_cryptoconnected(friendlist[i].crypt_connection_id) == 3)//if connection is established.
271 { 259 {
272 friendlist[i].status = 4; 260 case 0:
273 } 261 if (friendip.ip.i > 1)
274 if(is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) 262 friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip);
275 { 263 break;
276 crypto_kill(friendlist[i].crypt_connection_id); 264 case 3: // Connection is established
265 friendlist[i].status = 4;
266 break;
267 case 4:
268 crypto_kill(friendlist[i].crypt_connection_id);
269 break;
270 default:
271 break;
277 } 272 }
278 } 273 }
279 while(friendlist[i].status == 4) 274 while(friendlist[i].status == 4)
@@ -308,9 +303,7 @@ static void doFriendRequest()
308 if(len >= 0) 303 if(len >= 0)
309 { 304 {
310 (*friend_request)(public_key, temp, len); 305 (*friend_request)(public_key, temp, len);
311
312 } 306 }
313
314} 307}
315 308
316 309