]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_key.c
Add meshlink_get_node_tiny().
[meshlink] / src / protocol_key.c
index 693b96db5e11f09d12bc77814dd801a1e07da6c8..25dbc55e5c04b7533e9eb0f6c5eeb62214cc648e 100644 (file)
@@ -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
+                               }
                        }
                }
 
@@ -268,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;
        }