diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-22 14:52:42 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-22 14:52:42 -0400 |
commit | 55361eac6f12fb2b2aaec427129aae65f5eb5e6b (patch) | |
tree | 41107d3aaa5edd4bc7e24951390ed676f00e8b2c /core/Messenger.c | |
parent | b368a6b4b898e2d2fa558931f724f2d204de6335 (diff) |
Modified the way friend requests worked.
Added routing of friend requests.
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 25ce067d..3d874837 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -353,15 +353,14 @@ static int set_friend_userstatus(int friendnumber, uint8_t * status, uint16_t le | |||
353 | friendlist[friendnumber].userstatus_length = length; | 353 | friendlist[friendnumber].userstatus_length = length; |
354 | return 0; | 354 | return 0; |
355 | } | 355 | } |
356 | 356 | /* | |
357 | static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); | 357 | static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); |
358 | static uint8_t friend_request_isset = 0; | 358 | static uint8_t friend_request_isset = 0; |
359 | 359 | */ | |
360 | /* set the function that will be executed when a friend request is received. */ | 360 | /* set the function that will be executed when a friend request is received. */ |
361 | void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)) | 361 | void m_callback_friendrequest(void (*function)(uint8_t *, uint8_t *, uint16_t)) |
362 | { | 362 | { |
363 | friend_request = function; | 363 | callback_friendrequest(function); |
364 | friend_request_isset = 1; | ||
365 | } | 364 | } |
366 | 365 | ||
367 | 366 | ||
@@ -413,19 +412,20 @@ static void doFriends() | |||
413 | { | 412 | { |
414 | if(friendlist[i].status == 1) | 413 | if(friendlist[i].status == 1) |
415 | { | 414 | { |
416 | IP_Port friendip = DHT_getfriendip(friendlist[i].client_id); | 415 | int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size); |
417 | int request = check_friendrequest(friendlist[i].friend_request_id); | 416 | if(fr == 0)/*TODO: This needs to be fixed so that it sends the friend requests a couple of times in case |
418 | /* printf("\n%u %u %u\n", friendip.ip.i, request, friendlist[i].friend_request_id); */ | 417 | of packet loss*/ |
419 | if(friendip.ip.i > 1 && request == -1) | 418 | { |
420 | { | 419 | friendlist[i].status = 2; |
421 | friendlist[i].friend_request_id = send_friendrequest(friendlist[i].client_id, | 420 | } |
422 | friendip, friendlist[i].info, friendlist[i].info_size); | 421 | else |
423 | friendlist[i].status = 2; | 422 | if(fr > 0) |
424 | } | 423 | { |
424 | friendlist[i].status = 2; | ||
425 | } | ||
425 | } | 426 | } |
426 | if(friendlist[i].status == 2 || friendlist[i].status == 3) /* friend is not online */ | 427 | if(friendlist[i].status == 2 || friendlist[i].status == 3) /* friend is not online */ |
427 | { | 428 | { |
428 | check_friendrequest(friendlist[i].friend_request_id); /* for now this is used to kill the friend request */ | ||
429 | IP_Port friendip = DHT_getfriendip(friendlist[i].client_id); | 429 | IP_Port friendip = DHT_getfriendip(friendlist[i].client_id); |
430 | switch(is_cryptoconnected(friendlist[i].crypt_connection_id)) | 430 | switch(is_cryptoconnected(friendlist[i].crypt_connection_id)) |
431 | { | 431 | { |
@@ -508,21 +508,6 @@ static void doFriends() | |||
508 | } | 508 | } |
509 | } | 509 | } |
510 | 510 | ||
511 | static void doFriendRequest() | ||
512 | { | ||
513 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | ||
514 | uint8_t temp[MAX_DATA_SIZE]; | ||
515 | |||
516 | int len = handle_friendrequest(public_key, temp); | ||
517 | if(len >= 0) | ||
518 | { | ||
519 | if(friend_request_isset) | ||
520 | { | ||
521 | (*friend_request)(public_key, temp, len); | ||
522 | } | ||
523 | } | ||
524 | } | ||
525 | |||
526 | 511 | ||
527 | 512 | ||
528 | static void doInbound() | 513 | static void doInbound() |
@@ -556,7 +541,7 @@ void doMessenger() | |||
556 | #ifdef DEBUG | 541 | #ifdef DEBUG |
557 | /* if(rand() % 3 != 1) //simulate packet loss */ | 542 | /* if(rand() % 3 != 1) //simulate packet loss */ |
558 | /* { */ | 543 | /* { */ |
559 | if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port)) | 544 | if(DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) |
560 | { | 545 | { |
561 | /* if packet is discarded */ | 546 | /* if packet is discarded */ |
562 | printf("Received unhandled packet with length: %u\n", length); | 547 | printf("Received unhandled packet with length: %u\n", length); |
@@ -570,6 +555,7 @@ void doMessenger() | |||
570 | #else | 555 | #else |
571 | DHT_handlepacket(data, length, ip_port); | 556 | DHT_handlepacket(data, length, ip_port); |
572 | LosslessUDP_handlepacket(data, length, ip_port); | 557 | LosslessUDP_handlepacket(data, length, ip_port); |
558 | friendreq_handlepacket(data, length, ip_port); | ||
573 | #endif | 559 | #endif |
574 | 560 | ||
575 | } | 561 | } |
@@ -577,7 +563,6 @@ void doMessenger() | |||
577 | doLossless_UDP(); | 563 | doLossless_UDP(); |
578 | doNetCrypto(); | 564 | doNetCrypto(); |
579 | doInbound(); | 565 | doInbound(); |
580 | doFriendRequest(); | ||
581 | doFriends(); | 566 | doFriends(); |
582 | } | 567 | } |
583 | 568 | ||