From: Guus Sliepen Date: Mon, 21 Apr 2014 21:25:40 +0000 (+0200) Subject: Move node_udp_cache, everyone and invitation_key to mesh. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=eb049936ffce049cf6b53de8ca0f39c98a360363 Move node_udp_cache, everyone and invitation_key to mesh. --- diff --git a/src/connection.c b/src/connection.c index c38bc4a0..1732b150 100644 --- a/src/connection.c +++ b/src/connection.c @@ -29,18 +29,16 @@ #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) { diff --git a/src/connection.h b/src/connection.h index 0cc5ae6f..181de823 100644 --- a/src/connection.h +++ b/src/connection.h @@ -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__)); diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 66b76aec..57c2a8f6 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -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. diff --git a/src/net.c b/src/net.c index c2cbadf0..29401423 100644 --- 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); } } diff --git a/src/net_setup.c b/src/net_setup.c index c5632339..b6d88da3 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -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) { diff --git a/src/protocol.c b/src/protocol.c index 4f762825..aa434ee4 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -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 diff --git a/src/protocol.h b/src/protocol.h index 68b11462..8e2258fc 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -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. diff --git a/src/protocol_auth.c b/src/protocol_auth.c index a990caff..bd1c1c47 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -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 */ diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 641011cf..6eb205fd 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -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); } } diff --git a/src/protocol_key.c b/src/protocol_key.c index c490a8d2..59ca7db4 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -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 */