diff options
author | slvr <slvr@unsafeio.com> | 2013-08-12 14:19:25 +0100 |
---|---|---|
committer | slvr <slvr@unsafeio.com> | 2013-08-12 14:19:25 +0100 |
commit | f3511db29bb3f4a931c6efe66415981d73483262 (patch) | |
tree | 986f803109932ce13e0f3842ae5eedec77ae5880 /core | |
parent | 1a39c397c57cfc2008d432cc38458a45b961aff0 (diff) |
Added LAN discovery timer
Diffstat (limited to 'core')
-rw-r--r-- | core/Messenger.c | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 92c83b9b..e70b0378 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -22,6 +22,8 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "Messenger.h" | 24 | #include "Messenger.h" |
25 | #include "timer.h" | ||
26 | |||
25 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 27 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
26 | 28 | ||
27 | typedef struct { | 29 | typedef struct { |
@@ -520,27 +522,6 @@ static int write_cryptpacket_id(int friendnumber, uint8_t packet_id, uint8_t *da | |||
520 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, packet, length + 1); | 522 | return write_cryptpacket(friendlist[friendnumber].crypt_connection_id, packet, length + 1); |
521 | } | 523 | } |
522 | 524 | ||
523 | #define PORT 33445 | ||
524 | /* run this at startup */ | ||
525 | int initMessenger(void) | ||
526 | { | ||
527 | new_keys(); | ||
528 | m_set_statusmessage((uint8_t*)"Online", sizeof("Online")); | ||
529 | initNetCrypto(); | ||
530 | IP ip; | ||
531 | ip.i = 0; | ||
532 | |||
533 | if(init_networking(ip,PORT) == -1) | ||
534 | return -1; | ||
535 | |||
536 | DHT_init(); | ||
537 | LosslessUDP_init(); | ||
538 | friendreq_init(); | ||
539 | LANdiscovery_init(); | ||
540 | |||
541 | return 0; | ||
542 | } | ||
543 | |||
544 | //TODO: make this function not suck. | 525 | //TODO: make this function not suck. |
545 | static void doFriends(void) | 526 | static void doFriends(void) |
546 | { | 527 | { |
@@ -692,17 +673,37 @@ static void doInbound(void) | |||
692 | /*Interval in seconds between LAN discovery packet sending*/ | 673 | /*Interval in seconds between LAN discovery packet sending*/ |
693 | #define LAN_DISCOVERY_INTERVAL 60 | 674 | #define LAN_DISCOVERY_INTERVAL 60 |
694 | 675 | ||
695 | static uint64_t last_LANdiscovery; | ||
696 | |||
697 | /*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ | 676 | /*Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds*/ |
698 | static void LANdiscovery(void) | 677 | static int LANdiscovery_timercallback(timer* t, void*) |
699 | { | 678 | { |
700 | if (last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { | 679 | send_LANdiscovery(htons(PORT)); |
701 | send_LANdiscovery(htons(PORT)); | 680 | timer_start(t, LAN_DISCOVERY_INTERVAL); |
702 | last_LANdiscovery = unix_time(); | 681 | return 0; |
703 | } | ||
704 | } | 682 | } |
705 | 683 | ||
684 | #define PORT 33445 | ||
685 | /* run this at startup */ | ||
686 | int initMessenger(void) | ||
687 | { | ||
688 | timer_init(); | ||
689 | new_keys(); | ||
690 | m_set_statusmessage((uint8_t*)"Online", sizeof("Online")); | ||
691 | initNetCrypto(); | ||
692 | IP ip; | ||
693 | ip.i = 0; | ||
694 | |||
695 | if(init_networking(ip,PORT) == -1) | ||
696 | return -1; | ||
697 | |||
698 | DHT_init(); | ||
699 | LosslessUDP_init(); | ||
700 | friendreq_init(); | ||
701 | LANdiscovery_init(); | ||
702 | |||
703 | timer_single(&LANdiscovery_timercallback, 0, LAN_DISCOVERY_INTERVAL); | ||
704 | |||
705 | return 0; | ||
706 | } | ||
706 | 707 | ||
707 | /* the main loop that needs to be run at least 200 times per second. */ | 708 | /* the main loop that needs to be run at least 200 times per second. */ |
708 | void doMessenger(void) | 709 | void doMessenger(void) |