X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_key.c;h=179252984e1c3856947ba2569a86ba6e6d2b324c;hb=282b99f3c71705bd6e34d4e4f9e8369ea63c87ed;hp=43a227bbd65b459aaf7254a5069609ff2a1ea6f7;hpb=0d133a5ff230ad78da3208d32521d7549836187e;p=meshlink diff --git a/src/protocol_key.c b/src/protocol_key.c index 43a227bb..17925298 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -80,7 +80,7 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data } bool send_req_key(meshlink_handle_t *mesh, node_t *to) { - if(!node_read_ecdsa_public_key(mesh, to)) { + if(!node_read_public_key(mesh, to)) { logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s", to->name); send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY); return true; @@ -96,8 +96,7 @@ bool send_req_key(meshlink_handle_t *mesh, node_t *to) { to->status.validkey = false; to->status.waitingforkey = true; to->last_req_key = mesh->loop.now.tv_sec; - to->incompression = mesh->self->incompression; - return sptps_start(&to->sptps, to, true, true, mesh->self->connection->ecdsa, to->ecdsa, label, sizeof(label) - 1, send_initial_sptps_data, receive_sptps_record); + return sptps_start(&to->sptps, to, true, true, mesh->private_key, to->ecdsa, label, sizeof(label) - 1, send_initial_sptps_data, receive_sptps_record); } /* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */ @@ -107,7 +106,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * switch(reqno) { case REQ_PUBKEY: { - char *pubkey = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa); + char *pubkey = ecdsa_get_base64_public_key(mesh->private_key); if(!from->nexthop || !from->nexthop->connection) { return false; @@ -119,7 +118,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * } case ANS_PUBKEY: { - if(node_read_ecdsa_public_key(mesh, from)) { + if(node_read_public_key(mesh, from)) { logger(mesh, MESHLINK_WARNING, "Got ANS_PUBKEY from %s even though we already have his pubkey", from->name); return true; } @@ -132,12 +131,23 @@ 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); - append_config_file(mesh, from->name, "ECDSAPublicKey", pubkey); + from->status.dirty = true; + + /* 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) { + outgoing->timeout = 0; + timeout_set(&mesh->loop, &outgoing->ev, &(struct timeval) { + 0, 0 + }); + } + } + return true; } case REQ_KEY: { - if(!node_read_ecdsa_public_key(mesh, from)) { + if(!node_read_public_key(mesh, from)) { logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s", from->name); send_request(mesh, from->nexthop->connection, NULL, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY); return true; @@ -166,7 +176,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * from->status.validkey = false; from->status.waitingforkey = true; from->last_req_key = mesh->loop.now.tv_sec; - sptps_start(&from->sptps, from, false, true, mesh->self->connection->ecdsa, from->ecdsa, label, sizeof(label) - 1, send_sptps_data, receive_sptps_record); + sptps_start(&from->sptps, from, false, true, mesh->private_key, from->ecdsa, label, sizeof(label) - 1, send_sptps_data, receive_sptps_record); sptps_receive_data(&from->sptps, buf, len); return true; } @@ -324,8 +334,6 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return true; } - from->outcompression = compression; - /* SPTPS or old-style key exchange? */ char buf[strlen(key)]; @@ -342,9 +350,7 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { update_node_udp(mesh, from, &sa); } - if(from->options & OPTION_PMTU_DISCOVERY && !(from->options & OPTION_TCPONLY)) { - send_mtu_probe(mesh, from); - } + send_mtu_probe(mesh, from); } return true;