| 74 | } |
| 75 | |
| 76 | static struct io_plan *connect_finish(struct io_conn *conn, |
| 77 | struct connecting_socks *connect) |
| 78 | { |
| 79 | status_io(LOG_IO_IN, NULL, "proxy", |
| 80 | connect->buffer, SIZE_OF_IPV4_RESPONSE + SIZE_OF_RESPONSE); |
| 81 | |
| 82 | /* buffer[1] contains the reply status code and 0 means "success", |
| 83 | * see https://tools.ietf.org/html/rfc1928#section-6 |
| 84 | */ |
| 85 | if ( connect->buffer[1] == '\0') { |
| 86 | if ( connect->buffer[3] == SOCKS_TYP_IPV6) { |
| 87 | /* Read rest of response */ |
| 88 | return io_read(conn, |
| 89 | connect->buffer + SIZE_OF_RESPONSE + |
| 90 | SIZE_OF_IPV4_RESPONSE, |
| 91 | SIZE_OF_IPV6_RESPONSE - |
| 92 | SIZE_OF_IPV4_RESPONSE, |
| 93 | &connect_finish2, connect); |
| 94 | |
| 95 | } else if ( connect->buffer[3] == SOCKS_TYP_IPV4) { |
| 96 | status_debug("Now try LN connect out for host %s", |
| 97 | connect->host); |
| 98 | return connection_out(conn, connect->connect); |
| 99 | } else { |
| 100 | const char *msg = tal_fmt(tmpctx, |
| 101 | "Tor connect out for host %s error invalid " |
| 102 | "type return: %0x", connect->host, |
| 103 | connect->buffer[3]); |
| 104 | status_debug("%s", msg); |
| 105 | add_errors_to_error_list(connect->connect, msg); |
| 106 | |
| 107 | errno = ECONNREFUSED; |
| 108 | return io_close(conn); |
| 109 | } |
| 110 | } else { |
| 111 | const char *msg = tal_fmt(tmpctx, |
| 112 | "Error connecting to %s: Tor server reply: %s", |
| 113 | connect->host, |
| 114 | socks5strerror(tmpctx, connect->buffer[1])); |
| 115 | status_debug("%s", msg); |
| 116 | add_errors_to_error_list(connect->connect, msg); |
| 117 | |
| 118 | errno = ECONNREFUSED; |
| 119 | return io_close(conn); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /* called when TOR responds */ |
| 124 | static struct io_plan *connect_out(struct io_conn *conn, |
nothing calls this directly
no test coverage detected