From c1e0a4d57211433dcbc6982da1e947a4887ffbd0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 May 2018 08:48:23 +0930 Subject: [PATCH] gossip/tor: rearrange functions to avoid predeclarations. Signed-off-by: Rusty Russell --- gossipd/tor.c | 123 ++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 75 deletions(-) diff --git a/gossipd/tor.c b/gossipd/tor.c index 4f9595090..be466ca8e 100644 --- a/gossipd/tor.c +++ b/gossipd/tor.c @@ -41,81 +41,6 @@ struct reaching_socks { struct reaching *reach; }; -static struct io_plan *connect_finish(struct io_conn *, - struct reaching_socks *); - -static struct io_plan *connect_finish2(struct io_conn *, - struct reaching_socks *); - -static struct io_plan *connect_out(struct io_conn *, struct reaching_socks *); - -static struct io_plan *io_tor_connect_after_req_to_connect(struct io_conn *, - struct reaching_socks - *); -static struct io_plan *io_tor_connect_after_req_host(struct io_conn *, - struct reaching_socks *); - -static struct io_plan *io_tor_connect_do_req(struct io_conn *, - struct reaching_socks *); - -static struct io_plan *connect_out(struct io_conn *, struct reaching_socks *); - -static struct io_plan *io_tor_connect_do_req(struct io_conn *, - struct reaching_socks *); - -static struct io_plan *io_tor_connect_after_resp_to_connect(struct io_conn - *conn, - struct - reaching_socks *); - -static struct io_plan *io_tor_connect_after_resp_to_connect(struct io_conn - *conn, - struct - reaching_socks - *reach) -{ - if (reach->buffer[1] == SOCKS_ERROR) { - status_trace("Connected out for %s error", reach->host); - return io_close(conn); - } - /* make the V5 request */ - reach->hlen = strlen(reach->host); - reach->buffer[0] = SOCKS_V5; - reach->buffer[1] = SOCKS_CONNECT; - reach->buffer[2] = 0; - reach->buffer[3] = SOCKS_DOMAIN; - reach->buffer[4] = reach->hlen; - - memcpy(reach->buffer + SOCK_REQ_V5_LEN, reach->host, reach->hlen); - memcpy(reach->buffer + SOCK_REQ_V5_LEN + strlen(reach->host), - &(reach->port), sizeof reach->port); - - return io_write(conn, reach->buffer, - SOCK_REQ_V5_HEADER_LEN + reach->hlen, - io_tor_connect_after_req_host, reach); -} - -static struct io_plan *io_tor_connect_after_req_to_connect(struct io_conn *conn, - struct reaching_socks - *reach) -{ - - return io_read(conn, reach->buffer, 2, - &io_tor_connect_after_resp_to_connect, reach); -} - -static struct io_plan *io_tor_connect_do_req(struct io_conn *conn, - struct reaching_socks *reach) -{ - /* make the init request */ - reach->buffer[0] = SOCKS_V5; - reach->buffer[1] = 1; - reach->buffer[2] = SOCKS_NOAUTH; - - return io_write(conn, reach->buffer, SOCK_REQ_METH_LEN, - &io_tor_connect_after_req_to_connect, reach); -} - static struct io_plan *connect_finish2(struct io_conn *conn, struct reaching_socks *reach) { @@ -175,6 +100,54 @@ static struct io_plan *io_tor_connect_after_req_host(struct io_conn *conn, return connect_out(conn, reach); } +static struct io_plan *io_tor_connect_after_resp_to_connect(struct io_conn + *conn, + struct + reaching_socks + *reach) +{ + if (reach->buffer[1] == SOCKS_ERROR) { + status_trace("Connected out for %s error", reach->host); + return io_close(conn); + } + /* make the V5 request */ + reach->hlen = strlen(reach->host); + reach->buffer[0] = SOCKS_V5; + reach->buffer[1] = SOCKS_CONNECT; + reach->buffer[2] = 0; + reach->buffer[3] = SOCKS_DOMAIN; + reach->buffer[4] = reach->hlen; + + memcpy(reach->buffer + SOCK_REQ_V5_LEN, reach->host, reach->hlen); + memcpy(reach->buffer + SOCK_REQ_V5_LEN + strlen(reach->host), + &(reach->port), sizeof reach->port); + + return io_write(conn, reach->buffer, + SOCK_REQ_V5_HEADER_LEN + reach->hlen, + io_tor_connect_after_req_host, reach); +} + +static struct io_plan *io_tor_connect_after_req_to_connect(struct io_conn *conn, + struct reaching_socks + *reach) +{ + + return io_read(conn, reach->buffer, 2, + &io_tor_connect_after_resp_to_connect, reach); +} + +static struct io_plan *io_tor_connect_do_req(struct io_conn *conn, + struct reaching_socks *reach) +{ + /* make the init request */ + reach->buffer[0] = SOCKS_V5; + reach->buffer[1] = 1; + reach->buffer[2] = SOCKS_NOAUTH; + + return io_write(conn, reach->buffer, SOCK_REQ_METH_LEN, + &io_tor_connect_after_req_to_connect, reach); +} + // called when we want to connect to TOR SOCKS5 struct io_plan *io_tor_connect(struct io_conn *conn, const struct wireaddr *tor_proxyaddrs,