diff options
author | Denys Smirnov <denis.smirnov.91@gmail.com> | 2019-04-14 21:51:23 +0300 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-04-15 12:38:42 +0200 |
commit | 91ec0074a3c44641c07c3299f95a54161ef0b9df (patch) | |
tree | cdd0f9588cdda15dbe5f4fca1178bcc70a6ac44a /src | |
parent | 089574cbfd85530ea9ebe7d11bc293598142e41c (diff) |
Delay sending messages and setting handlers until the protocol is known.
Diffstat (limited to 'src')
-rw-r--r-- | src/hub.c | 42 |
1 files changed, 27 insertions, 15 deletions
@@ -1853,6 +1853,24 @@ hub_t *hub_create(ui_tab_t *tab) { return hub; } +static void handle_fully_connected(hub_t *hub) { + net_set_keepalive(hub->net, hub->adc ? "\n" : "|"); + + /* If we have a pre-configured active IP, make sure to enable active mode + * immediately. */ + if(hub_ip(hub)) + listen_refresh(); + + if(hub->adc) + net_writef(hub->net, "HSUP ADBASE ADTIGR%s\n", var_get_bool(hub->id, VAR_adc_blom) ? " ADBLO0 ADBLOM" : ""); + + // In the case that the joincomplete detection fails, consider the join to be + // complete anyway after a 2-minute timeout. + hub->joincomplete_timer = g_timeout_add_seconds(120, joincomplete_timer, hub); + + // Start handling incoming messages + net_readmsg(hub->net, hub->adc ? '\n' : '|', hub->adc ? adc_handle : nmdc_handle); +} static void handle_handshake(net_t *n, const char *kpr, int proto) { g_return_if_fail(kpr != NULL); @@ -1877,12 +1895,15 @@ static void handle_handshake(net_t *n, const char *kpr, int proto) { if(!old) { ui_mf(hub->tab, 0, "No previous TLS keyprint known. Storing `%s' for future validation.", kpf); var_set(hub->id, VAR_hubkp, kpf, NULL); + handle_fully_connected(hub); return; } // Keyprint matches? no problems! - if(strcmp(old, kpf) == 0) + if(strcmp(old, kpf) == 0) { + handle_fully_connected(hub); return; + } // Keyprint doesn't match... now we have a problem! ui_mf(hub->tab, UIP_HIGH, @@ -1907,7 +1928,6 @@ static void handle_connect(net_t *n, const char *addr) { return; } - net_set_keepalive(n, hub->adc ? "\n" : "|"); ui_mf(hub->tab, 0, "Connected to %s.", net_remoteaddr(n)); if(hub->tls) @@ -1915,20 +1935,12 @@ static void handle_connect(net_t *n, const char *addr) { if(!net_is_connected(hub->net)) return; - /* If we have a pre-configured active IP, make sure to enable active mode - * immediately. */ - if(hub_ip(hub)) - listen_refresh(); - - if(hub->adc) - net_writef(hub->net, "HSUP ADBASE ADTIGR%s\n", var_get_bool(hub->id, VAR_adc_blom) ? " ADBLO0 ADBLOM" : ""); - - // In the case that the joincomplete detection fails, consider the join to be - // complete anyway after a 2-minute timeout. - hub->joincomplete_timer = g_timeout_add_seconds(120, joincomplete_timer, hub); + // TLS may negotiate a different protocol, and handle_handshake + // will eventually call handle_fully_connected as well. + if(hub->tls) + return; - // Start handling incoming messages - net_readmsg(hub->net, hub->adc ? '\n' : '|', hub->adc ? adc_handle : nmdc_handle); + handle_fully_connected(hub); } |