X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_key.c;h=480019e7798c484c8a24288ca3e5ddd7e406050f;hb=HEAD;hp=dbe3d917b779b87126bed3ca23ffcd5324c781a3;hpb=7870cb4a1882fb0e3fd4e90784f81327fc0cab08;p=meshlink diff --git a/src/protocol_key.c b/src/protocol_key.c index dbe3d917..745845a6 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -146,6 +146,13 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "REQ_PUBKEY", from->name, "invalid pubkey"); return true; } + + logger(mesh, MESHLINK_INFO, "Learned ECDSA public key from %s", from->name); + from->status.dirty = true; + + if(!node_write_config(mesh, from, true)) { + // ignore + } } } @@ -170,6 +177,10 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * logger(mesh, MESHLINK_INFO, "Learned ECDSA public key from %s", from->name); from->status.dirty = true; + if(!node_write_config(mesh, from, true)) { + // ignore + } + /* If we are trying to form an outgoing connection to this node, retry immediately */ for list_each(outgoing_t, outgoing, mesh->outgoings) { if(outgoing->node == from && outgoing->ev.cb) { @@ -264,16 +275,15 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * return true; } - strncat(host, " ", MAX_STRING_SIZE - 1); - strncat(host, port, MAX_STRING_SIZE - 1); + char *canonical_address; + xasprintf(&canonical_address, "%s %s", host, port); - if(from->canonical_address && !strcmp(from->canonical_address, host)) { - return true; + if(mesh->log_level <= MESHLINK_DEBUG && (!from->canonical_address || strcmp(from->canonical_address, canonical_address))) { + logger(mesh, MESHLINK_DEBUG, "Updating canonical address of %s to %s", from->name, canonical_address); } - logger(mesh, MESHLINK_DEBUG, "Updating canonical address of %s to %s", from->name, host); free(from->canonical_address); - from->canonical_address = xstrdup(host); + from->canonical_address = canonical_address; return true; } @@ -335,6 +345,10 @@ bool req_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return true; } + size_t len = strlen(request); + from->in_forward += len + SPTPS_OVERHEAD; + to->out_forward += len + SPTPS_OVERHEAD; + send_request(mesh, to->nexthop->connection, NULL, "%s", request); } @@ -401,6 +415,11 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return false; } + /* TODO: find a good way to avoid the use of strlen() */ + size_t len = strlen(request); + from->in_forward += len + SPTPS_OVERHEAD; + to->out_forward += len + SPTPS_OVERHEAD; + /* Append the known UDP address of the from node, if we have a confirmed one */ if(!*address && from->status.udp_confirmed && from->address.sa.sa_family != AF_UNSPEC) { char *reflexive_address, *reflexive_port;