diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-10 14:21:06 -0700 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-10 14:21:06 -0700 |
commit | 6c2b2806d10881a4c44a47e877898e9de1cc63c9 (patch) | |
tree | 2879741f06260a5390ae619954f53f141ba4ce54 /core/Messenger.c | |
parent | 341de59bb627600c27ef29b113fa71bac120350f (diff) | |
parent | 5b6465528f88c4ed45fe57d5c2c21270f9109bb9 (diff) |
Merge pull request #415 from slvr/pr
Beginning to centralise packet handling
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index dd651107..37ab5e2d 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -518,6 +518,11 @@ int initMessenger(void) | |||
518 | if(init_networking(ip,PORT) == -1) | 518 | if(init_networking(ip,PORT) == -1) |
519 | return -1; | 519 | return -1; |
520 | 520 | ||
521 | DHT_init(); | ||
522 | LosslessUDP_init(); | ||
523 | friendreq_init(); | ||
524 | LANdiscovery_init(); | ||
525 | |||
521 | return 0; | 526 | return 0; |
522 | } | 527 | } |
523 | 528 | ||
@@ -684,29 +689,8 @@ static void LANdiscovery(void) | |||
684 | /* the main loop that needs to be run at least 200 times per second. */ | 689 | /* the main loop that needs to be run at least 200 times per second. */ |
685 | void doMessenger(void) | 690 | void doMessenger(void) |
686 | { | 691 | { |
687 | IP_Port ip_port; | 692 | networking_poll(); |
688 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 693 | |
689 | uint32_t length; | ||
690 | while (receivepacket(&ip_port, data, &length) != -1) { | ||
691 | #ifdef DEBUG | ||
692 | /* if(rand() % 3 != 1) //simulate packet loss */ | ||
693 | /* { */ | ||
694 | if (DHT_handlepacket(data, length, ip_port) && LosslessUDP_handlepacket(data, length, ip_port) && | ||
695 | friendreq_handlepacket(data, length, ip_port) && LANdiscovery_handlepacket(data, length, ip_port)) | ||
696 | /* if packet is discarded */ | ||
697 | printf("Received unhandled packet with length: %u\n", length); | ||
698 | else | ||
699 | printf("Received handled packet with length: %u\n", length); | ||
700 | /* } */ | ||
701 | printf("Status: %u %u %u\n",friendlist[0].status ,is_cryptoconnected(friendlist[0].crypt_connection_id), friendlist[0].crypt_connection_id); | ||
702 | #else | ||
703 | DHT_handlepacket(data, length, ip_port); | ||
704 | LosslessUDP_handlepacket(data, length, ip_port); | ||
705 | friendreq_handlepacket(data, length, ip_port); | ||
706 | LANdiscovery_handlepacket(data, length, ip_port); | ||
707 | #endif | ||
708 | |||
709 | } | ||
710 | doDHT(); | 694 | doDHT(); |
711 | doLossless_UDP(); | 695 | doLossless_UDP(); |
712 | doNetCrypto(); | 696 | doNetCrypto(); |