]> git.meshlink.io Git - meshlink/commitdiff
Move myself to mesh->self.
authorGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 18:55:14 +0000 (20:55 +0200)
committerGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 18:55:14 +0000 (20:55 +0200)
12 files changed:
src/graph.c
src/libmeshlink.c
src/net.c
src/net_packet.c
src/net_setup.c
src/net_socket.c
src/node.c
src/node.h
src/protocol_auth.c
src/protocol_edge.c
src/protocol_key.c
src/route.c

index 233cf5442a4e000e612a8a64f6b384de65ffeaf4..43e526b044ce781976d403f4b50fee581a472d11 100644 (file)
@@ -48,6 +48,7 @@
 #include "graph.h"
 #include "list.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "netutl.h"
 #include "node.h"
 #include "protocol.h"
@@ -125,15 +126,15 @@ static void sssp_bfs(void) {
                n->distance = -1;
        }
 
-       /* Begin with myself */
+       /* Begin with mesh->self */
 
-       myself->status.visited = true;
-       myself->status.indirect = false;
-       myself->nexthop = myself;
-       myself->prevedge = NULL;
-       myself->via = myself;
-       myself->distance = 0;
-       list_insert_head(todo_list, myself);
+       mesh->self->status.visited = true;
+       mesh->self->status.indirect = false;
+       mesh->self->nexthop = mesh->self;
+       mesh->self->prevedge = NULL;
+       mesh->self->via = mesh->self;
+       mesh->self->distance = 0;
+       list_insert_head(todo_list, mesh->self);
 
        /* Loop while todo_list is filled */
 
@@ -173,7 +174,7 @@ static void sssp_bfs(void) {
 
                        e->to->status.visited = true;
                        e->to->status.indirect = indirect;
-                       e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop;
+                       e->to->nexthop = (n->nexthop == mesh->self) ? e->to : n->nexthop;
                        e->to->prevedge = e;
                        e->to->via = indirect ? n->via : e->to;
                        e->to->options = e->options;
index f85f32e8fa7db91762e355dd10e14ccada003769..cd9e8a745f496ecdbe3e38a19aec652e364acfdc 100644 (file)
@@ -421,14 +421,14 @@ bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) {
        packet.probe = false;
        memset(hdr, 0, sizeof *hdr);
        memcpy(hdr->destination,receiver->name,sizeof(hdr->destination));
-       memcpy(hdr->source,myself->name,sizeof(hdr->source));
+       memcpy(hdr->source,mesh->self->name,sizeof(hdr->source));
 
        packet.len = sizeof(tincpackethdr) + len;
        memcpy(packet.data+sizeof(tincpackethdr),buf,len);
 
-        myself->in_packets++;
-        myself->in_bytes += packet.len;
-        route(myself, &packet);
+        mesh->self->in_packets++;
+        mesh->self->in_bytes += packet.len;
+        route(mesh->self, &packet);
 
 return true;
 }
index 87deb97b60d669bf19897a54b6dbd275de644f72..4cae25c1b15206403acf9c5a18d98337dcf5f65c 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -24,6 +24,7 @@
 #include "connection.h"
 #include "graph.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "net.h"
 #include "netutl.h"
@@ -100,7 +101,7 @@ void terminate_connection(connection_t *c, bool report) {
 
                if(report && !c->node->status.reachable) {
                        edge_t *e;
-                       e = lookup_edge(c->node, myself);
+                       e = lookup_edge(c->node, mesh->self);
                        if(e) {
                                send_del_edge(everyone, e);
                                edge_del(e);
@@ -290,7 +291,7 @@ int reload_configuration(void) {
                return EINVAL;
        }
 
-       xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
+       xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, mesh->self->name);
        read_config_file(config_tree, fname);
        free(fname);
 
index 41e2521df386a18c2770e2678d0a715a6067950d..7457b3bd76c1b9caa12d37d2879d34cf17ca9cdb 100644 (file)
@@ -30,6 +30,7 @@
 #include "digest.h"
 #include "graph.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "net.h"
 #include "netutl.h"
 #include "protocol.h"
@@ -462,16 +463,16 @@ bool send_sptps_data(void *handle, uint8_t type, const char *data, size_t len) {
 
        /* Send it via TCP if it is a handshake packet, TCPOnly is in use, or this packet is larger than the MTU. */
 
-       if(type >= SPTPS_HANDSHAKE || ((myself->options | to->options) & OPTION_TCPONLY) || (type != PKT_PROBE && len > to->minmtu)) {
+       if(type >= SPTPS_HANDSHAKE || ((mesh->self->options | to->options) & OPTION_TCPONLY) || (type != PKT_PROBE && len > to->minmtu)) {
                char buf[len * 4 / 3 + 5];
                b64encode(data, buf, len);
                /* If no valid key is known yet, send the packets using ANS_KEY requests,
                   to ensure we get to learn the reflexive UDP address. */
                if(!to->status.validkey) {
-                       to->incompression = myself->incompression;
-                       return send_request(to->nexthop->connection, "%d %s %s %s -1 -1 -1 %d", ANS_KEY, myself->name, to->name, buf, to->incompression);
+                       to->incompression = mesh->self->incompression;
+                       return send_request(to->nexthop->connection, "%d %s %s %s -1 -1 -1 %d", ANS_KEY, mesh->self->name, to->name, buf, to->incompression);
                } else {
-                       return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_SPTPS, buf);
+                       return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_SPTPS, buf);
                }
        }
 
@@ -558,7 +559,7 @@ bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t
 void send_packet(node_t *n, vpn_packet_t *packet) {
        node_t *via;
 
-       if(n == myself) {
+       if(n == mesh->self) {
                n->out_packets++;
                n->out_bytes += packet->len;
                // TODO: send to application
@@ -585,8 +586,8 @@ void send_packet(node_t *n, vpn_packet_t *packet) {
 
 void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
        // Always give ourself a copy of the packet.
-       if(from != myself)
-               send_packet(myself, packet);
+       if(from != mesh->self)
+               send_packet(mesh->self, packet);
 
        logger(DEBUG_TRAFFIC, LOG_INFO, "Broadcasting packet of %d bytes from %s (%s)",
                           packet->len, from->name, from->hostname);
@@ -602,7 +603,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) {
        static time_t last_hard_try = 0;
 
        for splay_each(edge_t, e, edge_weight_tree) {
-               if(!e->to->status.reachable || e->to == myself)
+               if(!e->to->status.reachable || e->to == mesh->self)
                        continue;
 
                if(sockaddrcmp_noport(from, &e->address)) {
index 2cc7ddf55a46c5555cd5a93ba0ecf54e1e214705..63f02753679e4867450e88408a538f0a60ddc510 100644 (file)
@@ -26,6 +26,7 @@
 #include "ecdsa.h"
 #include "graph.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "net.h"
 #include "netutl.h"
 #include "protocol.h"
@@ -102,13 +103,13 @@ static bool read_ecdsa_private_key(void) {
                return false;
        }
 
-       myself->connection->ecdsa = ecdsa_read_pem_private_key(fp);
+       mesh->self->connection->ecdsa = ecdsa_read_pem_private_key(fp);
        fclose(fp);
 
-       if(!myself->connection->ecdsa)
+       if(!mesh->self->connection->ecdsa)
                logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file failed: %s", strerror(errno));
 
-       return myself->connection->ecdsa;
+       return mesh->self->connection->ecdsa;
 }
 
 static bool read_invitation_key(void) {
@@ -186,7 +187,7 @@ char *get_name(void) {
                return NULL;
 
        if(!check_id(name)) {
-               logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for myself!");
+               logger(DEBUG_ALWAYS, LOG_ERR, "Invalid name for mesh->self!");
                free(name);
                return NULL;
        }
@@ -199,7 +200,7 @@ bool setup_myself_reloadable(void) {
        keylifetime = 3600; // TODO: check if this can be removed as well
        maxtimeout = 900;
        autoconnect = 3;
-       myself->options |= OPTION_PMTU_DISCOVERY;
+       mesh->self->options |= OPTION_PMTU_DISCOVERY;
 
        read_invitation_key();
 
@@ -286,7 +287,7 @@ static bool add_listen_address(char *address, bool bindto) {
 }
 
 /*
-  Configure node_t myself and set up the local sockets (listen only)
+  Configure node_t mesh->self and set up the local sockets (listen only)
 */
 bool setup_myself(void) {
        char *name, *hostname, *cipher, *digest, *type;
@@ -298,10 +299,10 @@ bool setup_myself(void) {
                return false;
        }
 
-       myself = new_node();
-       myself->connection = new_connection();
-       myself->name = name;
-       myself->connection->name = xstrdup(name);
+       mesh->self = new_node();
+       mesh->self->connection = new_connection();
+       mesh->self->name = name;
+       mesh->self->connection->name = xstrdup(name);
        read_host_config(config_tree, name);
 
        if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
@@ -309,11 +310,11 @@ bool setup_myself(void) {
        else
                port_specified = true;
 
-       myself->connection->options = 0;
-       myself->connection->protocol_major = PROT_MAJOR;
-       myself->connection->protocol_minor = PROT_MINOR;
+       mesh->self->connection->options = 0;
+       mesh->self->connection->protocol_major = PROT_MAJOR;
+       mesh->self->connection->protocol_minor = PROT_MINOR;
 
-       myself->options |= PROT_MINOR << 24;
+       mesh->self->options |= PROT_MINOR << 24;
 
        if(!read_ecdsa_private_key())
                return false;
@@ -341,16 +342,16 @@ bool setup_myself(void) {
        /* Compression */
 
        // TODO: drop compression in the packet layer?
-       myself->incompression = 0;
-       myself->connection->outcompression = 0;
+       mesh->self->incompression = 0;
+       mesh->self->connection->outcompression = 0;
 
        /* Done */
 
-       myself->nexthop = myself;
-       myself->via = myself;
-       myself->status.reachable = true;
-       myself->last_state_change = now.tv_sec;
-       node_add(myself);
+       mesh->self->nexthop = mesh->self;
+       mesh->self->via = mesh->self;
+       mesh->self->status.reachable = true;
+       mesh->self->last_state_change = now.tv_sec;
+       node_add(mesh->self);
 
        graph();
 
@@ -375,8 +376,8 @@ bool setup_myself(void) {
        if(!myport)
                myport = xstrdup("655");
 
-       xasprintf(&myself->hostname, "MYSELF port %s", myport);
-       myself->connection->hostname = xstrdup(myself->hostname);
+       xasprintf(&mesh->self->hostname, "MYSELF port %s", myport);
+       mesh->self->connection->hostname = xstrdup(mesh->self->hostname);
 
        /* Done. */
 
@@ -418,9 +419,9 @@ void close_network_connections(void) {
        if(outgoing_list)
                list_delete_list(outgoing_list);
 
-       if(myself && myself->connection) {
-               terminate_connection(myself->connection, false);
-               free_connection(myself->connection);
+       if(mesh->self && mesh->self->connection) {
+               terminate_connection(mesh->self->connection, false);
+               free_connection(mesh->self->connection);
        }
 
        for(int i = 0; i < listen_sockets; i++) {
index 0b1e1fb645d428c7291726e4f52eb9b9e086feef..60f4de1d270404e434e58af93ee0bcc8fbfc2f4e 100644 (file)
@@ -23,6 +23,7 @@
 #include "connection.h"
 #include "list.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "net.h"
 #include "netutl.h"
@@ -198,12 +199,12 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
 #endif
 
 #if defined(SOL_IP) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
-       if(myself->options & OPTION_PMTU_DISCOVERY) {
+       if(mesh->self->options & OPTION_PMTU_DISCOVERY) {
                option = IP_PMTUDISC_DO;
                setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, (void *)&option, sizeof(option));
        }
 #elif defined(IPPROTO_IP) && defined(IP_DONTFRAGMENT)
-       if(myself->options & OPTION_PMTU_DISCOVERY) {
+       if(mesh->self->options & OPTION_PMTU_DISCOVERY) {
                option = 1;
                setsockopt(nfd, IPPROTO_IP, IP_DONTFRAGMENT, (void *)&option, sizeof(option));
        }
@@ -212,12 +213,12 @@ int setup_vpn_in_socket(const sockaddr_t *sa) {
 #endif
 
 #if defined(SOL_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
-       if(myself->options & OPTION_PMTU_DISCOVERY) {
+       if(mesh->self->options & OPTION_PMTU_DISCOVERY) {
                option = IPV6_PMTUDISC_DO;
                setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, (void *)&option, sizeof(option));
        }
 #elif defined(IPPROTO_IPV6) && defined(IPV6_DONTFRAG)
-       if(myself->options & OPTION_PMTU_DISCOVERY) {
+       if(mesh->self->options & OPTION_PMTU_DISCOVERY) {
                option = 1;
                setsockopt(nfd, IPPROTO_IPV6, IPV6_DONTFRAG, (void *)&option, sizeof(option));
        }
@@ -292,7 +293,7 @@ static void do_outgoing_pipe(connection_t *c, char *command) {
        setenv("REMOTEADDRESS", host, true);
        setenv("REMOTEPORT", port, true);
        setenv("NODE", c->name, true);
-       setenv("NAME", myself->name, true);
+       setenv("NAME", mesh->self->name, true);
 
        int result = system(command);
        if(result < 0)
@@ -463,7 +464,7 @@ begin:
 
        c->status.connecting = true;
        c->name = xstrdup(outgoing->name);
-       c->outcompression = myself->connection->outcompression;
+       c->outcompression = mesh->self->connection->outcompression;
        c->last_ping_time = now.tv_sec;
 
        connection_add(c);
@@ -607,7 +608,7 @@ void handle_new_meta_connection(void *data, int flags) {
 
        c = new_connection();
        c->name = xstrdup("<unknown>");
-       c->outcompression = myself->connection->outcompression;
+       c->outcompression = mesh->self->connection->outcompression;
 
        c->address = sa;
        c->hostname = sockaddr2hostname(&sa);
index 527970540868007a5296bca04b0d8e2a277b5cf8..83f4a743e92547bd0a582a470647c2995870d1c8 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "hash.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "net.h"
 #include "netutl.h"
 #include "node.h"
@@ -31,8 +32,6 @@
 splay_tree_t *node_tree;
 static hash_t *node_udp_cache;
 
-node_t *myself;
-
 static int node_compare(const node_t *a, const node_t *b) {
        return strcmp(a->name, b->name);
 }
@@ -105,8 +104,8 @@ node_t *lookup_node_udp(const sockaddr_t *sa) {
 }
 
 void update_node_udp(node_t *n, const sockaddr_t *sa) {
-       if(n == myself) {
-               logger(DEBUG_ALWAYS, LOG_WARNING, "Trying to update UDP address of myself!");
+       if(n == mesh->self) {
+               logger(DEBUG_ALWAYS, LOG_WARNING, "Trying to update UDP address of mesh->self!");
                return;
        }
 
index 2ae82e281eb367de10ad08a4a931402419b2b21c..a341f2bb429a2adbec5369b4be44e66507fdbe1c 100644 (file)
@@ -88,7 +88,6 @@ typedef struct node_t {
        uint64_t out_bytes;
 } node_t;
 
-extern struct node_t *myself;
 extern struct splay_tree_t *node_tree;
 
 extern void init_nodes(void);
index 1a79264d133c82c41c7d9d64e37e3066552cf067..14686ac903b1c5d9b1c0e9af186c9f5aa34c1035 100644 (file)
@@ -28,6 +28,7 @@
 #include "edge.h"
 #include "graph.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "net.h"
 #include "netutl.h"
@@ -130,13 +131,13 @@ static bool send_proxyrequest(connection_t *c) {
 bool send_id(connection_t *c) {
        gettimeofday(&c->start, NULL);
 
-       int minor = myself->connection->protocol_minor;
+       int minor = mesh->self->connection->protocol_minor;
 
        if(proxytype && c->outgoing)
                if(!send_proxyrequest(c))
                        return false;
 
-       return send_request(c, "%d %s %d.%d", ID, myself->connection->name, myself->connection->protocol_major, minor);
+       return send_request(c, "%d %s %d.%d", ID, mesh->self->connection->name, mesh->self->connection->protocol_major, minor);
 }
 
 static bool finalize_invitation(connection_t *c, const char *data, uint16_t len) {
@@ -312,7 +313,7 @@ bool id_h(connection_t *c, const char *request) {
 
        /* Check if version matches */
 
-       if(c->protocol_major != myself->connection->protocol_major) {
+       if(c->protocol_major != mesh->self->connection->protocol_major) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Peer %s (%s) uses incompatible version %d.%d",
                        c->name, c->hostname, c->protocol_major, c->protocol_minor);
                return false;
@@ -348,14 +349,14 @@ bool id_h(connection_t *c, const char *request) {
        }
 
        c->allow_request = ACK;
-       char label[25 + strlen(myself->name) + strlen(c->name)];
+       char label[25 + strlen(mesh->self->name) + strlen(c->name)];
 
        if(c->outgoing)
-               snprintf(label, sizeof label, "tinc TCP key expansion %s %s", myself->name, c->name);
+               snprintf(label, sizeof label, "tinc TCP key expansion %s %s", mesh->self->name, c->name);
        else
-               snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, myself->name);
+               snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, mesh->self->name);
 
-       return sptps_start(&c->sptps, c, c->outgoing, false, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
+       return sptps_start(&c->sptps, c, c->outgoing, false, mesh->self->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
 }
 
 bool send_ack(connection_t *c) {
@@ -372,7 +373,7 @@ bool send_ack(connection_t *c) {
 
        /* Check some options */
 
-       if(myself->options & OPTION_PMTU_DISCOVERY)
+       if(mesh->self->options & OPTION_PMTU_DISCOVERY)
                c->options |= OPTION_PMTU_DISCOVERY;
 
        return send_request(c, "%d %s %d %x", ACK, myport, c->estimated_weight, (c->options & 0xffffff) | (PROT_MINOR << 24));
@@ -464,7 +465,7 @@ bool ack_h(connection_t *c, const char *request) {
        /* Create an edge_t for this connection */
 
        c->edge = new_edge();
-       c->edge->from = myself;
+       c->edge->from = mesh->self;
        c->edge->to = n;
        sockaddr2str(&c->address, &hisaddress, NULL);
        c->edge->address = str2sockaddr(hisaddress, hisport);
index 6da3c876afffd870f4b76595eddd76a3aa137bc8..ecad9c6e2c08a562faffff195cea1e559e37b8b6 100644 (file)
@@ -24,6 +24,7 @@
 #include "edge.h"
 #include "graph.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "net.h"
 #include "netutl.h"
@@ -104,7 +105,7 @@ bool add_edge_h(connection_t *c, const char *request) {
 
        if(e) {
                if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
-                       if(from == myself) {
+                       if(from == mesh->self) {
                                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
                                                   "ADD_EDGE", c->name, c->hostname);
                                send_add_edge(c, e);
@@ -117,7 +118,7 @@ bool add_edge_h(connection_t *c, const char *request) {
                        }
                } else
                        return true;
-       } else if(from == myself) {
+       } else if(from == mesh->self) {
                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist",
                                   "ADD_EDGE", c->name, c->hostname);
                contradicting_add_edge++;
@@ -203,7 +204,7 @@ bool del_edge_h(connection_t *c, const char *request) {
                return true;
        }
 
-       if(e->from == myself) {
+       if(e->from == mesh->self) {
                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself",
                                   "DEL_EDGE", c->name, c->hostname);
                contradicting_del_edge++;
@@ -226,7 +227,7 @@ bool del_edge_h(connection_t *c, const char *request) {
        /* If the node is not reachable anymore but we remember it had an edge to us, clean it up */
 
        if(!to->status.reachable) {
-               e = lookup_edge(to, myself);
+               e = lookup_edge(to, mesh->self);
                if(e) {
                        send_del_edge(everyone, e);
                        edge_del(e);
index 5cfa060b2f6a1b37ebcfccbf27f4ebf29e04b6a3..ef182b346ad07d40c297607133ad77245f81f39e 100644 (file)
@@ -23,6 +23,7 @@
 #include "connection.h"
 #include "crypto.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "net.h"
 #include "netutl.h"
 #include "node.h"
@@ -35,7 +36,7 @@
 static bool mykeyused = false;
 
 void send_key_changed(void) {
-       send_request(everyone, "%d %x %s", KEY_CHANGED, rand(), myself->name);
+       send_request(everyone, "%d %x %s", KEY_CHANGED, rand(), mesh->self->name);
 
        /* Force key exchange for connections using SPTPS */
 
@@ -77,27 +78,27 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const char *data
        to->sptps.send_data = send_sptps_data;
        char buf[len * 4 / 3 + 5];
        b64encode(data, buf, len);
-       return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf);
+       return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf);
 }
 
 bool send_req_key(node_t *to) {
        if(!node_read_ecdsa_public_key(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, myself->name, to->name, REQ_PUBKEY);
+               send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY);
                return true;
        }
 
        if(to->sptps.label)
                logger(DEBUG_ALWAYS, LOG_DEBUG, "send_req_key(%s) called while sptps->label != NULL!", to->name);
 
-       char label[25 + strlen(myself->name) + strlen(to->name)];
-       snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name);
+       char label[25 + strlen(mesh->self->name) + strlen(to->name)];
+       snprintf(label, sizeof label, "tinc UDP key expansion %s %s", mesh->self->name, to->name);
        sptps_stop(&to->sptps);
        to->status.validkey = false;
        to->status.waitingforkey = true;
        to->last_req_key = now.tv_sec;
-       to->incompression = myself->incompression;
-       return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record);
+       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);
 }
 
 /* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */
@@ -105,8 +106,8 @@ bool send_req_key(node_t *to) {
 static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, int reqno) {
        switch(reqno) {
                case REQ_PUBKEY: {
-                       char *pubkey = ecdsa_get_base64_public_key(myself->connection->ecdsa);
-                       send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, from->name, ANS_PUBKEY, pubkey);
+                       char *pubkey = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa);
+                       send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey);
                        free(pubkey);
                        return true;
                }
@@ -131,7 +132,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in
                case REQ_KEY: {
                        if(!node_read_ecdsa_public_key(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, myself->name, from->name, REQ_PUBKEY);
+                               send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY);
                                return true;
                        }
 
@@ -146,13 +147,13 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in
                                return true;
                        }
 
-                       char label[25 + strlen(from->name) + strlen(myself->name)];
-                       snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, myself->name);
+                       char label[25 + strlen(from->name) + strlen(mesh->self->name)];
+                       snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, mesh->self->name);
                        sptps_stop(&from->sptps);
                        from->status.validkey = false;
                        from->status.waitingforkey = true;
                        from->last_req_key = now.tv_sec;
-                       sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record);
+                       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;
                }
@@ -214,7 +215,7 @@ bool req_key_h(connection_t *c, const char *request) {
 
        /* Check if this key request is for us */
 
-       if(to == myself) {                      /* Yes */
+       if(to == mesh->self) {                      /* Yes */
                /* Is this an extended REQ_KEY message? */
                if(reqno)
                        return req_key_ext_h(c, request, from, reqno);
@@ -278,7 +279,7 @@ bool ans_key_h(connection_t *c, const char *request) {
 
        /* Forward it if necessary */
 
-       if(to != myself) {
+       if(to != mesh->self) {
                if(!to->status.reachable) {
                        logger(DEBUG_ALWAYS, LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
                                   "ANS_KEY", c->name, c->hostname, to_name);
index 450baf9049159e944174f86b1c0623d6fd0c19ea..d999d11eaf5fa495b03900379a163f62dbfecce8 100644 (file)
@@ -20,6 +20,7 @@
 #include "system.h"
 
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "net.h"
 #include "route.h"
 #include "utils.h"
@@ -71,7 +72,7 @@ void route(node_t *source,vpn_packet_t *packet) {
     return;
     }
 
-    if (owner == myself ) {
+    if (owner == mesh->self ) {
     //TODO: implement sending received data from meshlink library to the application
     logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + sizeof *hdr);
     (recv_callback)(packet->data + sizeof *hdr);
@@ -84,7 +85,7 @@ void route(node_t *source,vpn_packet_t *packet) {
     return;
     }
 
-    via = (owner->via == myself) ? owner->nexthop : owner->via;
+    via = (owner->via == mesh->self) ? owner->nexthop : owner->via;
     if(via == source) {
        logger(DEBUG_TRAFFIC, LOG_ERR, "Routing loop for packet from %s (%s)!", source->name, source->hostname);
        return;