X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fnet_setup.c;h=8baff8b87c9f9f9e623470e6f03b72dd6480f37c;hb=be83b0af60449c7b35d17d97f2e6dc12f611e831;hp=e1db743a3c3f3acc484b5c975c0f00599c4dd806;hpb=91501d27480bf37881b6872cf63462c50de197f3;p=meshlink diff --git a/src/net_setup.c b/src/net_setup.c index e1db743a..8baff8b8 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -100,7 +100,7 @@ bool node_read_public_key(meshlink_handle_t *mesh, node_t *n) { // Append any known addresses in the config file to the list we currently have uint32_t known_count = 0; - for(uint32_t i = 0; i < 5; i++) { + for(uint32_t i = 0; i < MAX_RECENT; i++) { if(n->recent[i].sa.sa_family) { known_count++; } @@ -108,14 +108,24 @@ bool node_read_public_key(meshlink_handle_t *mesh, node_t *n) { uint32_t count = packmsg_get_array(&in); - if(count > 5 - known_count) { - count = 5 - known_count; + for(uint32_t i = 0; i < count; i++) { + if(i < MAX_RECENT - known_count) { + n->recent[i + known_count] = packmsg_get_sockaddr(&in); + } else { + packmsg_skip_element(&in); + } } - for(uint32_t i = 0; i < count; i++) { - n->recent[i + known_count] = packmsg_get_sockaddr(&in); + time_t last_reachable = packmsg_get_int64(&in); + time_t last_unreachable = packmsg_get_int64(&in); + + if(!n->last_reachable) { + n->last_reachable = last_reachable; } + if(!n->last_unreachable) { + n->last_unreachable = last_unreachable; + } config_free(&config); return true; @@ -183,14 +193,17 @@ bool node_read_from_config(meshlink_handle_t *mesh, node_t *n, const config_t *c n->canonical_address = packmsg_get_str_dup(&in); uint32_t count = packmsg_get_array(&in); - if(count > 5) { - count = 5; - } - for(uint32_t i = 0; i < count; i++) { - n->recent[i] = packmsg_get_sockaddr(&in); + if(i < MAX_RECENT) { + n->recent[i] = packmsg_get_sockaddr(&in); + } else { + packmsg_skip_element(&in); + } } + n->last_reachable = packmsg_get_int64(&in); + n->last_unreachable = packmsg_get_int64(&in); + return packmsg_done(&in); } @@ -218,7 +231,7 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n) { uint32_t count = 0; - for(uint32_t i = 0; i < 5; i++) { + for(uint32_t i = 0; i < MAX_RECENT; i++) { if(n->recent[i].sa.sa_family) { count++; } else { @@ -232,7 +245,11 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n) { packmsg_add_sockaddr(&out, &n->recent[i]); } + packmsg_add_int64(&out, n->last_reachable); + packmsg_add_int64(&out, n->last_unreachable); + if(!packmsg_output_ok(&out)) { + meshlink_errno = MESHLINK_EINTERNAL; return false; } @@ -396,15 +413,13 @@ bool setup_myself(meshlink_handle_t *mesh) { mesh->self->nexthop = mesh->self; mesh->self->status.reachable = true; - mesh->self->last_state_change = mesh->loop.now.tv_sec; node_add(mesh, mesh->self); graph(mesh); if(!config_scan_all(mesh, "current", "hosts", load_node, NULL)) { - meshlink_errno = MESHLINK_ESTORAGE; - return false; + logger(mesh, MESHLINK_WARNING, "Could not scan all host config files"); } /* Open sockets */ @@ -437,6 +452,7 @@ bool setup_myself(meshlink_handle_t *mesh) { /* Done. */ mesh->last_config_check = mesh->loop.now.tv_sec; + mesh->last_unreachable = mesh->loop.now.tv_sec; return true; }