]> git.meshlink.io Git - meshlink/commitdiff
Move node_udp_cache, everyone and invitation_key to mesh.
authorGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 21:25:40 +0000 (23:25 +0200)
committerGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 21:25:40 +0000 (23:25 +0200)
src/connection.c
src/connection.h
src/meshlink_internal.h
src/net.c
src/net_setup.c
src/protocol.c
src/protocol.h
src/protocol_auth.c
src/protocol_edge.c
src/protocol_key.c

index c38bc4a071ca7cb205a5d85a5e7a9b91a4957191..1732b150fcfd499e57f810502266be83f5f10b90 100644 (file)
 #include "utils.h"
 #include "xalloc.h"
 
-connection_t *everyone;
-
 void init_connections(void) {
        mesh->connections = list_alloc((list_action_t) free_connection);
-       everyone = new_connection();
-       everyone->name = xstrdup("everyone");
-       everyone->hostname = xstrdup("BROADCAST");
+       mesh->everyone = new_connection();
+       mesh->everyone->name = xstrdup("mesh->everyone");
+       mesh->everyone->hostname = xstrdup("BROADCAST");
 }
 
 void exit_connections(void) {
        list_delete_list(mesh->connections);
-       free_connection(everyone);
+       free_connection(mesh->everyone);
 }
 
 connection_t *new_connection(void) {
index 0cc5ae6fa5d59d526c90bcf2c70d8590c123ff77..181de823a6a81a2fafd033c9c8a37f59d916b2be 100644 (file)
@@ -90,8 +90,6 @@ typedef struct connection_t {
        splay_tree_t *config_tree;      /* Pointer to configuration tree belonging to him */
 } connection_t;
 
-extern connection_t *everyone;
-
 extern void init_connections(void);
 extern void exit_connections(void);
 extern connection_t *new_connection(void) __attribute__ ((__malloc__));
index 66b76aec8192ad549357117b47e29032afbc9c89..57c2a8f6fb6a45800b9ed3ccea23b84fbd881a84 100644 (file)
@@ -23,6 +23,7 @@
 #include "system.h"
 
 #include "event.h"
+#include "hash.h"
 #include "meshlink.h"
 #include "sockaddr.h"
 
@@ -84,6 +85,10 @@ struct meshlink_handle {
 
        bool localdiscovery;
        sockaddr_t localdiscovery_address;
+
+       hash_t *node_udp_cache;
+       struct connection_t *everyone;
+       struct ecdsa *invitation_key;
 };
 
 /// A handle for a MeshLink node.
index c2cbadf005e29cf39423e7d84b46cce85f8dca07..294014231b1b04f0f556c11d826b57f45596414f 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -44,7 +44,7 @@ void purge(void) {
                        logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Purging node %s (%s)", n->name, n->hostname);
 
                        for splay_each(edge_t, e, n->edge_tree) {
-                               send_del_edge(everyone, e);
+                               send_del_edge(mesh->everyone, e);
                                edge_del(e);
                        }
                }
@@ -78,7 +78,7 @@ void terminate_connection(connection_t *c, bool report) {
 
        if(c->edge) {
                if(report)
-                       send_del_edge(everyone, c->edge);
+                       send_del_edge(mesh->everyone, c->edge);
 
                edge_del(c->edge);
                c->edge = NULL;
@@ -93,7 +93,7 @@ void terminate_connection(connection_t *c, bool report) {
                        edge_t *e;
                        e = lookup_edge(c->node, mesh->self);
                        if(e) {
-                               send_del_edge(everyone, e);
+                               send_del_edge(mesh->everyone, e);
                                edge_del(e);
                        }
                }
index c5632339889edc6bfb185bfce650d2be125e9816..b6d88da3c3c42f9629959cf5cbcd77bede667b3f 100644 (file)
@@ -108,9 +108,9 @@ static bool read_invitation_key(void) {
        FILE *fp;
        char *fname;
 
-       if(invitation_key) {
-               ecdsa_free(invitation_key);
-               invitation_key = NULL;
+       if(mesh->invitation_key) {
+               ecdsa_free(mesh->invitation_key);
+               mesh->invitation_key = NULL;
        }
 
        xasprintf(&fname, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", mesh->confbase);
@@ -118,14 +118,14 @@ static bool read_invitation_key(void) {
        fp = fopen(fname, "r");
 
        if(fp) {
-               invitation_key = ecdsa_read_pem_private_key(fp);
+               mesh->invitation_key = ecdsa_read_pem_private_key(fp);
                fclose(fp);
-               if(!invitation_key)
+               if(!mesh->invitation_key)
                        logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
        }
 
        free(fname);
-       return invitation_key;
+       return mesh->invitation_key;
 }
 
 void load_all_nodes(void) {
index 4f762825cd926d746d0bc2cf181e5f32939a32ca..aa434ee46b23cf3aac870ba0778c2e8770a1d386 100644 (file)
@@ -88,7 +88,7 @@ bool send_request(connection_t *c, const char *format, ...) {
 
        request[len++] = '\n';
 
-       if(c == everyone) {
+       if(c == mesh->everyone) {
                broadcast_meta(NULL, request, len);
                return true;
        } else
index 68b11462143c33a9fdd8adc99c0932439752cc73..8e2258fc3401d1a218e7ef4794b70b2e6473638f 100644 (file)
@@ -56,8 +56,6 @@ typedef struct past_request_t {
        time_t firstseen;
 } past_request_t;
 
-extern ecdsa_t *invitation_key;
-
 /* Maximum size of strings in a request.
  * scanf terminates %2048s with a NUL character,
  * but the NUL character can be written after the 2048th non-NUL character.
index a990caffdc3548fd82628a4851db6327d19bc4aa..bd1c1c47fe18691d6eb4c46e53975f01c5986035 100644 (file)
@@ -40,8 +40,6 @@
 #include "xalloc.h"
 #include "ed25519/sha512.h"
 
-ecdsa_t *invitation_key = NULL;
-
 static bool send_proxyrequest(connection_t *c) {
        switch(mesh->proxytype) {
                case PROXY_HTTP: {
@@ -184,7 +182,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const char *dat
                return false;
 
        // Recover the filename from the cookie and the key
-       char *fingerprint = ecdsa_get_base64_public_key(invitation_key);
+       char *fingerprint = ecdsa_get_base64_public_key(mesh->invitation_key);
        char hash[64];
        char hashbuf[18 + strlen(fingerprint)];
        char cookie[25];
@@ -265,7 +263,7 @@ bool id_h(connection_t *c, const char *request) {
        /* Check if this is an invitation  */
 
        if(name[0] == '?') {
-               if(!invitation_key) {
+               if(!mesh->invitation_key) {
                        logger(DEBUG_ALWAYS, LOG_ERR, "Got invitation from %s but we don't have an invitation key", c->hostname);
                        return false;
                }
@@ -277,7 +275,7 @@ bool id_h(connection_t *c, const char *request) {
                }
 
                c->status.invitation = true;
-               char *mykey = ecdsa_get_base64_public_key(invitation_key);
+               char *mykey = ecdsa_get_base64_public_key(mesh->invitation_key);
                if(!mykey)
                        return false;
                if(!send_request(c, "%d %s", ACK, mykey))
@@ -286,7 +284,7 @@ bool id_h(connection_t *c, const char *request) {
 
                c->protocol_minor = 2;
 
-               return sptps_start(&c->sptps, c, false, false, invitation_key, c->ecdsa, "tinc invitation", 15, send_meta_sptps, receive_invitation_sptps);
+               return sptps_start(&c->sptps, c, false, false, mesh->invitation_key, c->ecdsa, "tinc invitation", 15, send_meta_sptps, receive_invitation_sptps);
        }
 
        /* Check if identity is a valid name */
@@ -466,7 +464,7 @@ bool ack_h(connection_t *c, const char *request) {
 
        /* Notify everyone of the new edge */
 
-       send_add_edge(everyone, c->edge);
+       send_add_edge(mesh->everyone, c->edge);
 
        /* Run MST and SSSP algorithms */
 
index 641011cffd859f1391f57a1cf64456012542af66..6eb205fdddb3e138f2123ab720910b3263235785 100644 (file)
@@ -229,7 +229,7 @@ bool del_edge_h(connection_t *c, const char *request) {
        if(!to->status.reachable) {
                e = lookup_edge(to, mesh->self);
                if(e) {
-                       send_del_edge(everyone, e);
+                       send_del_edge(mesh->everyone, e);
                        edge_del(e);
                }
        }
index c490a8d215bab845a19a07884e645a9a34aaf7d9..59ca7db499e540bc331dcd34e7848f078597567f 100644 (file)
@@ -36,7 +36,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 */