]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_key.c
Stop using global variable mesh in net_setup.[ch].
[meshlink] / src / protocol_key.c
index c490a8d215bab845a19a07884e645a9a34aaf7d9..6f4364f2a33189b4a9fc5625495a550932b982ed 100644 (file)
@@ -19,9 +19,7 @@
 
 #include "system.h"
 
-#include "cipher.h"
 #include "connection.h"
-#include "crypto.h"
 #include "logger.h"
 #include "meshlink_internal.h"
 #include "net.h"
@@ -36,7 +34,7 @@
 static bool mykeyused = false;
 
 void send_key_changed(void) {
-       send_request(everyone, "%d %x %s", KEY_CHANGED, rand(), mesh->self->name);
+       send_request(mesh->everyone, "%d %x %s", KEY_CHANGED, rand(), mesh->self->name);
 
        /* Force key exchange for connections using SPTPS */
 
@@ -82,7 +80,7 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const char *data
 }
 
 bool send_req_key(node_t *to) {
-       if(!node_read_ecdsa_public_key(to)) {
+       if(!node_read_ecdsa_public_key(mesh, to)) {
                logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", to->name, to->hostname);
                send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY);
                return true;
@@ -96,7 +94,7 @@ bool send_req_key(node_t *to) {
        sptps_stop(&to->sptps);
        to->status.validkey = false;
        to->status.waitingforkey = true;
-       to->last_req_key = now.tv_sec;
+       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, send_initial_sptps_data, receive_sptps_record);
 }
@@ -113,7 +111,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in
                }
 
                case ANS_PUBKEY: {
-                       if(node_read_ecdsa_public_key(from)) {
+                       if(node_read_ecdsa_public_key(mesh, from)) {
                                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got ANS_PUBKEY from %s (%s) even though we already have his pubkey", from->name, from->hostname);
                                return true;
                        }
@@ -125,12 +123,12 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in
                        }
 
                        logger(DEBUG_PROTOCOL, LOG_INFO, "Learned ECDSA public key from %s (%s)", from->name, from->hostname);
-                       append_config_file(from->name, "ECDSAPublicKey", pubkey);
+                       append_config_file(mesh, from->name, "ECDSAPublicKey", pubkey);
                        return true;
                }
 
                case REQ_KEY: {
-                       if(!node_read_ecdsa_public_key(from)) {
+                       if(!node_read_ecdsa_public_key(mesh, from)) {
                                logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", from->name, from->hostname);
                                send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY);
                                return true;
@@ -152,7 +150,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in
                        sptps_stop(&from->sptps);
                        from->status.validkey = false;
                        from->status.waitingforkey = true;
-                       from->last_req_key = now.tv_sec;
+                       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, send_sptps_data, receive_sptps_record);
                        sptps_receive_data(&from->sptps, buf, len);
                        return true;