This initializes a fresh io_conn by setting it to io_connect to the * destination */
| 974 | /* This initializes a fresh io_conn by setting it to io_connect to the |
| 975 | * destination */ |
| 976 | static struct io_plan *conn_init(struct io_conn *conn, |
| 977 | struct connecting *connect) |
| 978 | { |
| 979 | /*~ I generally dislike the pattern of "set to NULL, assert if NULL at |
| 980 | * bottom". On -O2 and above the compiler will warn you at compile time |
| 981 | * if a there is a path by which the variable is not set, which is always |
| 982 | * preferable to a runtime assertion. In this case, it's the best way |
| 983 | * to use the "enum in a switch" trick to make sure we handle all enum |
| 984 | * cases, so I use it. */ |
| 985 | struct addrinfo *ai = NULL; |
| 986 | const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum]; |
| 987 | |
| 988 | switch (addr->itype) { |
| 989 | case ADDR_INTERNAL_SOCKNAME: |
| 990 | ai = wireaddr_internal_to_addrinfo(tmpctx, addr); |
| 991 | break; |
| 992 | case ADDR_INTERNAL_ALLPROTO: |
| 993 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 994 | "Can't connect to all protocols"); |
| 995 | break; |
| 996 | case ADDR_INTERNAL_AUTOTOR: |
| 997 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 998 | "Can't connect to autotor address"); |
| 999 | break; |
| 1000 | case ADDR_INTERNAL_STATICTOR: |
| 1001 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1002 | "Can't connect to statictor address"); |
| 1003 | break; |
| 1004 | case ADDR_INTERNAL_FORPROXY: |
| 1005 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1006 | "Can't connect to forproxy address"); |
| 1007 | break; |
| 1008 | case ADDR_INTERNAL_WIREADDR: |
| 1009 | /* DNS should have been resolved before, and Tor should not be here! */ |
| 1010 | ai = wireaddr_to_addrinfo(tmpctx, &addr->u.wireaddr.wireaddr); |
| 1011 | break; |
| 1012 | } |
| 1013 | assert(ai); |
| 1014 | |
| 1015 | io_set_finish(conn, destroy_io_conn, connect); |
| 1016 | return io_connect(conn, ai, connection_out, connect); |
| 1017 | } |
| 1018 | |
| 1019 | /* This initializes a fresh io_conn by setting it to io_connect to the |
| 1020 | * SOCKS proxy, as handled in tor.c. */ |
nothing calls this directly
no test coverage detected