]> git.meshlink.io Git - meshlink/commitdiff
Move proxy variables to mesh.
authorGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 20:50:03 +0000 (22:50 +0200)
committerGuus Sliepen <guus@sliepen.org>
Mon, 21 Apr 2014 20:50:03 +0000 (22:50 +0200)
src/meshlink_internal.h
src/net.h
src/net_setup.c
src/net_socket.c
src/protocol.c
src/protocol_auth.c

index c21608fe344f562dcb02e07153acded3eb805d25..3c2b0423f7df7ec3952b6f571cdb92ba0cefe274 100644 (file)
 #include "event.h"
 #include "meshlink.h"
 
+typedef enum proxytype_t {
+       PROXY_NONE = 0,
+       PROXY_SOCKS4,
+       PROXY_SOCKS4A,
+       PROXY_SOCKS5,
+       PROXY_HTTP,
+       PROXY_EXEC,
+} proxytype_t;
+
 /// A handle for an instance of MeshLink.
 struct meshlink_handle {
        char *confbase;
@@ -53,6 +62,14 @@ struct meshlink_handle {
        time_t last_config_check;
        timeout_t pingtimer;
        timeout_t periodictimer;
+
+       char *myport;
+
+       char *proxyhost;
+       char *proxyport;
+       char *proxyuser;
+       char *proxypass;
+       proxytype_t proxytype;
 };
 
 /// A handle for a MeshLink node.
index c87bbf3684bfd0ede2bff6fe36133e1deb2b8f4e..184dd934d050624491c2c972889ae1ac3976240e 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -91,23 +91,7 @@ extern int listen_sockets;
 extern int keylifetime;
 extern int max_connection_burst;
 extern bool do_prune;
-extern char *myport;
 extern int autoconnect;
-extern bool disablebuggypeers;
-
-extern char *proxyhost;
-extern char *proxyport;
-extern char *proxyuser;
-extern char *proxypass;
-typedef enum proxytype_t {
-       PROXY_NONE = 0,
-       PROXY_SOCKS4,
-       PROXY_SOCKS4A,
-       PROXY_SOCKS5,
-       PROXY_HTTP,
-       PROXY_EXEC,
-} proxytype_t;
-extern proxytype_t proxytype;
 
 /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
 #include "connection.h"
index d966f1632b9a406fca8149ac7f48c06ae88cb414..c48c0d5b66f458ec9e764a6ce917f28cadd359b1 100644 (file)
 #include "utils.h"
 #include "xalloc.h"
 
-char *myport;
-
-char *proxyhost;
-char *proxyport;
-char *proxyuser;
-char *proxypass;
-proxytype_t proxytype;
-int autoconnect;
-bool disablebuggypeers;
+int autoconnect = 3;
 
 bool node_read_ecdsa_public_key(node_t *n) {
        if(ecdsa_active(n->ecdsa))
@@ -211,7 +203,7 @@ bool setup_myself_reloadable(void) {
   Add listening sockets.
 */
 static bool add_listen_address(char *address, bool bindto) {
-       char *port = myport;
+       char *port = mesh->myport;
 
        if(address) {
                char *space = strchr(address, ' ');
@@ -305,8 +297,8 @@ bool setup_myself(void) {
        mesh->self->connection->name = xstrdup(name);
        read_host_config(mesh->config, name);
 
-       if(!get_config_string(lookup_config(mesh->config, "Port"), &myport))
-               myport = xstrdup("655");
+       if(!get_config_string(lookup_config(mesh->config, "Port"), &mesh->myport))
+               mesh->myport = xstrdup("655");
        else
                port_specified = true;
 
@@ -319,16 +311,16 @@ bool setup_myself(void) {
        if(!read_ecdsa_private_key())
                return false;
 
-       /* Ensure myport is numeric */
+       /* Ensure mesh->myport is numeric */
 
-       if(!atoi(myport)) {
-               struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
+       if(!atoi(mesh->myport)) {
+               struct addrinfo *ai = str2addrinfo("localhost", mesh->myport, SOCK_DGRAM);
                sockaddr_t sa;
                if(!ai || !ai->ai_addr)
                        return false;
-               free(myport);
+               free(mesh->myport);
                memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
-               sockaddr2str(&sa, NULL, &myport);
+               sockaddr2str(&sa, NULL, &mesh->myport);
        }
 
        /* Check some options */
@@ -373,10 +365,10 @@ bool setup_myself(void) {
 
        // TODO: require Port to be set? Or use "0" and use getsockname()?
 
-       if(!myport)
-               myport = xstrdup("655");
+       if(!mesh->myport)
+               mesh->myport = xstrdup("655");
 
-       xasprintf(&mesh->self->hostname, "MYSELF port %s", myport);
+       xasprintf(&mesh->self->hostname, "MYSELF port %s", mesh->myport);
        mesh->self->connection->hostname = xstrdup(mesh->self->hostname);
 
        /* Done. */
@@ -436,7 +428,7 @@ void close_network_connections(void) {
        exit_nodes();
        exit_connections();
 
-       if(myport) free(myport);
+       if(mesh->myport) free(mesh->myport);
 
        return;
 }
index 80fe84cac2876aff23b5e7826a5df7fdae3bb84a..bc599e8ad927239c316b712efe64096b9a8edc72 100644 (file)
@@ -405,18 +405,18 @@ begin:
 
        logger(DEBUG_CONNECTIONS, LOG_INFO, "Trying to connect to %s (%s)", outgoing->name, c->hostname);
 
-       if(!proxytype) {
+       if(!mesh->proxytype) {
                c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
                configure_tcp(c);
-       } else if(proxytype == PROXY_EXEC) {
-               do_outgoing_pipe(c, proxyhost);
+       } else if(mesh->proxytype == PROXY_EXEC) {
+               do_outgoing_pipe(c, mesh->proxyhost);
        } else {
-               proxyai = str2addrinfo(proxyhost, proxyport, SOCK_STREAM);
+               proxyai = str2addrinfo(mesh->proxyhost, mesh->proxyport, SOCK_STREAM);
                if(!proxyai) {
                        free_connection(c);
                        goto begin;
                }
-               logger(DEBUG_CONNECTIONS, LOG_INFO, "Using proxy at %s port %s", proxyhost, proxyport);
+               logger(DEBUG_CONNECTIONS, LOG_INFO, "Using proxy at %s port %s", mesh->proxyhost, mesh->proxyport);
                c->socket = socket(proxyai->ai_family, SOCK_STREAM, IPPROTO_TCP);
                configure_tcp(c);
        }
@@ -431,7 +431,7 @@ begin:
        fcntl(c->socket, F_SETFD, FD_CLOEXEC);
 #endif
 
-       if(proxytype != PROXY_EXEC) {
+       if(mesh->proxytype != PROXY_EXEC) {
 #if defined(SOL_IPV6) && defined(IPV6_V6ONLY)
                int option = 1;
                if(c->address.sa.sa_family == AF_INET6)
@@ -443,9 +443,9 @@ begin:
 
        /* Connect */
 
-       if(!proxytype) {
+       if(!mesh->proxytype) {
                result = connect(c->socket, &c->address.sa, SALEN(c->address.sa));
-       } else if(proxytype == PROXY_EXEC) {
+       } else if(mesh->proxytype == PROXY_EXEC) {
                result = 0;
        } else {
                result = connect(c->socket, proxyai->ai_addr, proxyai->ai_addrlen);
index eb406544b68177cd2274c78b487c55896e5b9ffb..4f762825cd926d746d0bc2cf181e5f32939a32ca 100644 (file)
@@ -22,6 +22,7 @@
 #include "conf.h"
 #include "connection.h"
 #include "logger.h"
+#include "meshlink_internal.h"
 #include "meta.h"
 #include "protocol.h"
 #include "utils.h"
@@ -106,7 +107,7 @@ void forward_request(connection_t *from, const char *request) {
 }
 
 bool receive_request(connection_t *c, const char *request) {
-       if(c->outgoing && proxytype == PROXY_HTTP && c->allow_request == ID) {
+       if(c->outgoing && mesh->proxytype == PROXY_HTTP && c->allow_request == ID) {
                if(!request[0] || request[0] == '\r')
                        return true;
                if(!strncasecmp(request, "HTTP/1.1 ", 9)) {
index 8b419bad8863c3e18bcf5a56afc2acb05a2a4f17..a990caffdc3548fd82628a4851db6327d19bc4aa 100644 (file)
@@ -43,7 +43,7 @@
 ecdsa_t *invitation_key = NULL;
 
 static bool send_proxyrequest(connection_t *c) {
-       switch(proxytype) {
+       switch(mesh->proxytype) {
                case PROXY_HTTP: {
                        char *host;
                        char *port;
@@ -59,13 +59,13 @@ static bool send_proxyrequest(connection_t *c) {
                                logger(DEBUG_ALWAYS, LOG_ERR, "Cannot connect to an IPv6 host through a SOCKS 4 proxy!");
                                return false;
                        }
-                       char s4req[9 + (proxyuser ? strlen(proxyuser) : 0)];
+                       char s4req[9 + (mesh->proxyuser ? strlen(mesh->proxyuser) : 0)];
                        s4req[0] = 4;
                        s4req[1] = 1;
                        memcpy(s4req + 2, &c->address.in.sin_port, 2);
                        memcpy(s4req + 4, &c->address.in.sin_addr, 4);
-                       if(proxyuser)
-                               memcpy(s4req + 8, proxyuser, strlen(proxyuser));
+                       if(mesh->proxyuser)
+                               memcpy(s4req + 8, mesh->proxyuser, strlen(mesh->proxyuser));
                        s4req[sizeof s4req - 1] = 0;
                        c->tcplen = 8;
                        return send_meta(c, s4req, sizeof s4req);
@@ -73,21 +73,21 @@ static bool send_proxyrequest(connection_t *c) {
                case PROXY_SOCKS5: {
                        int len = 3 + 6 + (c->address.sa.sa_family == AF_INET ? 4 : 16);
                        c->tcplen = 2;
-                       if(proxypass)
-                               len += 3 + strlen(proxyuser) + strlen(proxypass);
+                       if(mesh->proxypass)
+                               len += 3 + strlen(mesh->proxyuser) + strlen(mesh->proxypass);
                        char s5req[len];
                        int i = 0;
                        s5req[i++] = 5;
                        s5req[i++] = 1;
-                       if(proxypass) {
+                       if(mesh->proxypass) {
                                s5req[i++] = 2;
                                s5req[i++] = 1;
-                               s5req[i++] = strlen(proxyuser);
-                               memcpy(s5req + i, proxyuser, strlen(proxyuser));
-                               i += strlen(proxyuser);
-                               s5req[i++] = strlen(proxypass);
-                               memcpy(s5req + i, proxypass, strlen(proxypass));
-                               i += strlen(proxypass);
+                               s5req[i++] = strlen(mesh->proxyuser);
+                               memcpy(s5req + i, mesh->proxyuser, strlen(mesh->proxyuser));
+                               i += strlen(mesh->proxyuser);
+                               s5req[i++] = strlen(mesh->proxypass);
+                               memcpy(s5req + i, mesh->proxypass, strlen(mesh->proxypass));
+                               i += strlen(mesh->proxypass);
                                c->tcplen += 2;
                        } else {
                                s5req[i++] = 0;
@@ -133,7 +133,7 @@ bool send_id(connection_t *c) {
 
        int minor = mesh->self->connection->protocol_minor;
 
-       if(proxytype && c->outgoing)
+       if(mesh->proxytype && c->outgoing)
                if(!send_proxyrequest(c))
                        return false;
 
@@ -376,24 +376,12 @@ bool send_ack(connection_t *c) {
        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));
+       return send_request(c, "%d %s %d %x", ACK, mesh->myport, c->estimated_weight, (c->options & 0xffffff) | (PROT_MINOR << 24));
 }
 
 static void send_everything(connection_t *c) {
        /* Send all known subnets and edges */
 
-       // TODO: remove this
-       if(disablebuggypeers) {
-               static struct {
-                       vpn_packet_t pkt;
-                       char pad[MAXBUFSIZE - MAXSIZE];
-               } zeropkt;
-
-               memset(&zeropkt, 0, sizeof zeropkt);
-               zeropkt.pkt.len = MAXBUFSIZE;
-               send_tcppacket(c, &zeropkt.pkt);
-       }
-
        for splay_each(node_t, n, mesh->nodes) {
                for splay_each(edge_t, e, n->edge_tree)
                        send_add_edge(c, e);