]> git.meshlink.io Git - meshlink/commitdiff
Remove unused support for proxies.
authorGuus Sliepen <guus@meshlink.io>
Tue, 7 Apr 2020 21:17:38 +0000 (23:17 +0200)
committerGuus Sliepen <guus@meshlink.io>
Tue, 7 Apr 2020 22:51:51 +0000 (00:51 +0200)
src/meshlink_internal.h
src/net.c
src/net_socket.c
src/protocol.c
src/protocol_auth.c

index 8a632e26f0527e676c6cdbf662a05df70fd73ce8..8ba4e9801a6a743e47122fe6332e69baca3f691f 100644 (file)
@@ -57,14 +57,6 @@ typedef struct listen_socket_t {
        sockaddr_t broadcast_sa;
 } listen_socket_t;
 
-typedef enum proxytype_t {
-       PROXY_NONE = 0,
-       PROXY_SOCKS4,
-       PROXY_SOCKS4A,
-       PROXY_SOCKS5,
-       PROXY_HTTP,
-} proxytype_t;
-
 struct meshlink_open_params {
        char *confbase;
        char *appname;
@@ -199,13 +191,6 @@ struct meshlink_handle {
        meshlink_queue_t adns_queue;
        meshlink_queue_t adns_done_queue;
        signal_t adns_signal;
-
-       // Proxy configuration, currently not exposed.
-       char *proxyhost;
-       char *proxyport;
-       char *proxyuser;
-       char *proxypass;
-       proxytype_t proxytype;
 };
 
 /// A handle for a MeshLink node.
index 05049cffca96c87039f94b6b5b11e5d4c2b224d8..d80df2fd84c3d6d728a79bac55301e60a43e6d1d 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -92,13 +92,6 @@ void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report)
        if(outgoing) {
                do_outgoing_connection(mesh, outgoing);
        }
-
-#ifndef HAVE_MINGW
-       /* Clean up dead proxy processes */
-
-       while(waitpid(-1, NULL, WNOHANG) > 0);
-
-#endif
 }
 
 /*
index 63bf49ea3c6f0511de3322e9d84e21d8ddcc5092..30ff016917bee18e4383fbe5b420fdaa01b66f6f 100644 (file)
@@ -333,9 +333,6 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo
 }
 
 void do_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
-       struct addrinfo *proxyai = NULL;
-       int result;
-
 begin:
 
        if(!get_next_outgoing_address(mesh, outgoing)) {
@@ -354,35 +351,26 @@ begin:
 
        memcpy(&c->address, outgoing->aip->ai_addr, outgoing->aip->ai_addrlen);
 
-       char *hostname = sockaddr2hostname(&c->address);
-
-       logger(mesh, MESHLINK_INFO, "Trying to connect to %s at %s", outgoing->node->name, hostname);
+       if(mesh->log_level <= MESHLINK_INFO) {
+               char *hostname = sockaddr2hostname(&c->address);
+               logger(mesh, MESHLINK_INFO, "Trying to connect to %s at %s", outgoing->node->name, hostname);
+               free(hostname);
+       }
 
-       if(!mesh->proxytype) {
-               c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
-               configure_tcp(c);
-       } else {
-               proxyai = str2addrinfo(mesh->proxyhost, mesh->proxyport, SOCK_STREAM);
+       c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
 
-               if(!proxyai) {
-                       free_connection(c);
+       if(c->socket == -1) {
+               if(mesh->log_level <= MESHLINK_ERROR) {
+                       char *hostname = sockaddr2hostname(&c->address);
+                       logger(mesh, MESHLINK_ERROR, "Creating socket for %s at %s failed: %s", c->name, hostname, sockstrerror(sockerrno));
                        free(hostname);
-                       goto begin;
                }
 
-               logger(mesh, MESHLINK_INFO, "Using proxy at %s port %s", mesh->proxyhost, mesh->proxyport);
-               c->socket = socket(proxyai->ai_family, SOCK_STREAM, IPPROTO_TCP);
-               configure_tcp(c);
-       }
-
-       if(c->socket == -1) {
-               logger(mesh, MESHLINK_ERROR, "Creating socket for %s at %s failed: %s", c->name, hostname, sockstrerror(sockerrno));
                free_connection(c);
-               free(hostname);
                goto begin;
        }
 
-       free(hostname);
+       configure_tcp(c);
 
 #ifdef FD_CLOEXEC
        fcntl(c->socket, F_SETFD, FD_CLOEXEC);
@@ -399,17 +387,16 @@ begin:
 
        /* Connect */
 
-       if(!mesh->proxytype) {
-               result = connect(c->socket, &c->address.sa, SALEN(c->address.sa));
-       } else {
-               result = connect(c->socket, proxyai->ai_addr, proxyai->ai_addrlen);
-               freeaddrinfo(proxyai);
-       }
+       int result = connect(c->socket, &c->address.sa, SALEN(c->address.sa));
 
        if(result == -1 && !sockinprogress(sockerrno)) {
-               logger(mesh, MESHLINK_ERROR, "Could not connect to %s: %s", outgoing->node->name, sockstrerror(sockerrno));
-               free_connection(c);
+               if(mesh->log_level <= MESHLINK_ERROR) {
+                       char *hostname = sockaddr2hostname(&c->address);
+                       logger(mesh, MESHLINK_ERROR, "Could not connect to %s: %s", outgoing->node->name, sockstrerror(sockerrno));
+                       free(hostname);
+               }
 
+               free_connection(c);
                goto begin;
        }
 
index 482808a7e71885c6cf37d24ce42444f9d18c8aac..c8c75cfc4714b0a7c15f62c4491ebfbd0054edc1 100644 (file)
@@ -130,22 +130,6 @@ void forward_request(meshlink_handle_t *mesh, connection_t *from, submesh_t *s,
 bool receive_request(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        assert(request);
 
-       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)) {
-                       if(!strncmp(request + 9, "200", 3)) {
-                               logger(mesh, MESHLINK_DEBUG, "Proxy request granted");
-                               return true;
-                       } else {
-                               logger(mesh, MESHLINK_DEBUG, "Proxy request rejected: %s", request + 9);
-                               return false;
-                       }
-               }
-       }
-
        int reqno = atoi(request);
 
        if(reqno || *request == '0') {
index 416066ff0ed0a6eb6654bab6a0e70bc2b709e8e6..5632c5a216d23c044e07d820da8661fc4b501f8e 100644 (file)
 
 extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n);
 
-static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) {
-       switch(mesh->proxytype) {
-       case PROXY_HTTP: {
-               char *host;
-               char *port;
-
-               sockaddr2str(&c->address, &host, &port);
-               send_request(mesh, c, NULL, "CONNECT %s:%s HTTP/1.1\r\n\r", host, port);
-               free(host);
-               free(port);
-               return true;
-       }
-
-       case PROXY_SOCKS4: {
-               if(c->address.sa.sa_family != AF_INET) {
-                       logger(mesh, MESHLINK_ERROR, "Cannot connect to an IPv6 host through a SOCKS 4 proxy!");
-                       return false;
-               }
-
-               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(mesh->proxyuser) {
-                       memcpy(s4req + 8, mesh->proxyuser, strlen(mesh->proxyuser));
-               }
-
-               s4req[sizeof(s4req) - 1] = 0;
-               c->tcplen = 8;
-               return send_meta(mesh, c, s4req, sizeof(s4req));
-       }
-
-       case PROXY_SOCKS5: {
-               int len = 3 + 6 + (c->address.sa.sa_family == AF_INET ? 4 : 16);
-               c->tcplen = 2;
-
-               if(mesh->proxypass) {
-                       len += 3 + strlen(mesh->proxyuser) + strlen(mesh->proxypass);
-               }
-
-               char s5req[len];
-               int i = 0;
-               s5req[i++] = 5;
-               s5req[i++] = 1;
-
-               if(mesh->proxypass) {
-                       s5req[i++] = 2;
-                       s5req[i++] = 1;
-                       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;
-               }
-
-               s5req[i++] = 5;
-               s5req[i++] = 1;
-               s5req[i++] = 0;
-
-               if(c->address.sa.sa_family == AF_INET) {
-                       s5req[i++] = 1;
-                       memcpy(s5req + i, &c->address.in.sin_addr, 4);
-                       i += 4;
-                       memcpy(s5req + i, &c->address.in.sin_port, 2);
-                       i += 2;
-                       c->tcplen += 10;
-               } else if(c->address.sa.sa_family == AF_INET6) {
-                       s5req[i++] = 3;
-                       memcpy(s5req + i, &c->address.in6.sin6_addr, 16);
-                       i += 16;
-                       memcpy(s5req + i, &c->address.in6.sin6_port, 2);
-                       i += 2;
-                       c->tcplen += 22;
-               } else {
-                       logger(mesh, MESHLINK_ERROR, "Address family %hx not supported for SOCKS 5 proxies!", c->address.sa.sa_family);
-                       return false;
-               }
-
-               if(i > len) {
-                       abort();
-               }
-
-               return send_meta(mesh, c, s5req, sizeof(s5req));
-       }
-
-       case PROXY_SOCKS4A:
-               logger(mesh, MESHLINK_ERROR, "Proxy type not implemented yet");
-               return false;
-
-       default:
-               logger(mesh, MESHLINK_ERROR, "Unknown proxy type");
-               return false;
-       }
-}
-
 bool send_id(meshlink_handle_t *mesh, connection_t *c) {
-       if(mesh->proxytype && c->outgoing)
-               if(!send_proxyrequest(mesh, c)) {
-                       return false;
-               }
-
        return send_request(mesh, c, NULL, "%d %s %d.%d %s", ID, mesh->self->name, PROT_MAJOR, PROT_MINOR, mesh->appname);
 }