mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Move LAN discovery from Messenger to friend_connection.
This commit is contained in:
parent
6a1efc32e6
commit
69e3e5f3a4
|
@ -336,3 +336,8 @@ void LANdiscovery_init(DHT *dht)
|
|||
{
|
||||
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht);
|
||||
}
|
||||
|
||||
void LANdiscovery_kill(DHT *dht)
|
||||
{
|
||||
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, NULL, NULL);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@ int send_LANdiscovery(uint16_t port, DHT *dht);
|
|||
/* Sets up packet handlers. */
|
||||
void LANdiscovery_init(DHT *dht);
|
||||
|
||||
/* Clear packet handlers. */
|
||||
void LANdiscovery_kill(DHT *dht);
|
||||
|
||||
/* checks if a given IP isn't routable
|
||||
*
|
||||
* return 0 if ip is a LAN ip.
|
||||
|
|
|
@ -1765,15 +1765,6 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */
|
||||
static void LANdiscovery(Messenger *m)
|
||||
{
|
||||
if (m->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) {
|
||||
send_LANdiscovery(htons(TOX_PORT_DEFAULT), m->dht);
|
||||
m->last_LANdiscovery = unix_time();
|
||||
}
|
||||
}
|
||||
|
||||
/* Run this at startup. */
|
||||
Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
|
||||
{
|
||||
|
@ -1842,7 +1833,6 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
|
|||
|
||||
m->options = *options;
|
||||
friendreq_init(&(m->fr), m->fr_c);
|
||||
LANdiscovery_init(m->dht);
|
||||
set_nospam(&(m->fr), random_int());
|
||||
set_filter_function(&(m->fr), &friend_already_added, m);
|
||||
|
||||
|
@ -2308,7 +2298,6 @@ void do_messenger(Messenger *m)
|
|||
do_onion_client(m->onion_c);
|
||||
do_friend_connections(m->fr_c);
|
||||
do_friends(m);
|
||||
LANdiscovery(m);
|
||||
connection_status_cb(m);
|
||||
|
||||
#ifdef LOGGING
|
||||
|
|
|
@ -234,8 +234,6 @@ struct Messenger {
|
|||
|
||||
uint32_t numonline_friends;
|
||||
|
||||
uint64_t last_LANdiscovery;
|
||||
|
||||
#define NUM_SAVED_TCP_RELAYS 8
|
||||
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
|
||||
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
|
||||
|
|
|
@ -758,10 +758,20 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c)
|
|||
temp->onion_c = onion_c;
|
||||
|
||||
new_connection_handler(temp->net_crypto, &handle_new_connections, temp);
|
||||
LANdiscovery_init(temp->dht);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */
|
||||
static void LANdiscovery(Friend_Connections *fr_c)
|
||||
{
|
||||
if (fr_c->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) {
|
||||
send_LANdiscovery(htons(TOX_PORT_DEFAULT), fr_c->dht);
|
||||
fr_c->last_LANdiscovery = unix_time();
|
||||
}
|
||||
}
|
||||
|
||||
/* main friend_connections loop. */
|
||||
void do_friend_connections(Friend_Connections *fr_c)
|
||||
{
|
||||
|
@ -809,6 +819,8 @@ void do_friend_connections(Friend_Connections *fr_c)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
LANdiscovery(fr_c);
|
||||
}
|
||||
|
||||
/* Free everything related with friend_connections. */
|
||||
|
@ -823,5 +835,6 @@ void kill_friend_connections(Friend_Connections *fr_c)
|
|||
kill_friend_connection(fr_c, i);
|
||||
}
|
||||
|
||||
LANdiscovery_kill(fr_c->dht);
|
||||
free(fr_c);
|
||||
}
|
||||
|
|
|
@ -109,6 +109,8 @@ typedef struct {
|
|||
|
||||
int (*fr_request_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t len);
|
||||
void *fr_request_object;
|
||||
|
||||
uint64_t last_LANdiscovery;
|
||||
} Friend_Connections;
|
||||
|
||||
/* return friendcon_id corresponding to the real public key on success.
|
||||
|
|
Loading…
Reference in New Issue
Block a user