MCPcopy Create free account
hub / github.com/ElementsProject/lightning / connect_finish

Function connect_finish

connectd/tor.c:83–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

status_ioFunction · 0.85
connection_outFunction · 0.85
add_errors_to_error_listFunction · 0.85
io_closeFunction · 0.85
socks5strerrorFunction · 0.85

Tested by

no test coverage detected