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

Function conn_init

connectd/connectd.c:1032–1073  ·  view source on GitHub ↗

This initializes a fresh io_conn by setting it to io_connect to the * destination */

Source from the content-addressed store, hash-verified

1030/* This initializes a fresh io_conn by setting it to io_connect to the
1031 * destination */
1032static struct io_plan *conn_init(struct io_conn *conn,
1033 struct connecting *connect)
1034{
1035 /*~ I generally dislike the pattern of "set to NULL, assert if NULL at
1036 * bottom". On -O2 and above the compiler will warn you at compile time
1037 * if a there is a path by which the variable is not set, which is always
1038 * preferable to a runtime assertion. In this case, it's the best way
1039 * to use the "enum in a switch" trick to make sure we handle all enum
1040 * cases, so I use it. */
1041 struct addrinfo *ai = NULL;
1042 const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum];
1043
1044 switch (addr->itype) {
1045 case ADDR_INTERNAL_SOCKNAME:
1046 ai = wireaddr_internal_to_addrinfo(tmpctx, addr);
1047 break;
1048 case ADDR_INTERNAL_ALLPROTO:
1049 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1050 "Can't connect to all protocols");
1051 break;
1052 case ADDR_INTERNAL_AUTOTOR:
1053 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1054 "Can't connect to autotor address");
1055 break;
1056 case ADDR_INTERNAL_STATICTOR:
1057 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1058 "Can't connect to statictor address");
1059 break;
1060 case ADDR_INTERNAL_FORPROXY:
1061 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1062 "Can't connect to forproxy address");
1063 break;
1064 case ADDR_INTERNAL_WIREADDR:
1065 /* DNS should have been resolved before, and Tor should not be here! */
1066 ai = wireaddr_to_addrinfo(tmpctx, &addr->u.wireaddr.wireaddr);
1067 break;
1068 }
1069 assert(ai);
1070
1071 io_set_finish(conn, destroy_io_conn, connect);
1072 return io_connect(conn, ai, connection_out, connect);
1073}
1074
1075/* This initializes a fresh io_conn by setting it to io_connect to the
1076 * SOCKS proxy, as handled in tor.c. */

Callers

nothing calls this directly

Calls 3

wireaddr_to_addrinfoFunction · 0.85
status_failedFunction · 0.50

Tested by

no test coverage detected