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

Function peer_exchange_initmsg

connectd/peer_exchange_initmsg.c:205–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
206 struct daemon *daemon,
207 const struct feature_set *our_features,
208 const struct crypto_state *cs,
209 const struct node_id *id,
210 const struct wireaddr_internal *addr,
211 struct oneshot *timeout,
212 enum is_websocket is_websocket,
213 struct timemono starttime,
214 bool incoming)
215{
216 /* If conn is closed, forget peer */
217 struct early_peer *peer = tal(conn, struct early_peer);
218 struct io_plan *(*next)(struct io_conn *, struct early_peer *);
219 struct tlv_init_tlvs *tlvs;
220
221 peer->daemon = daemon;
222 peer->id = *id;
223 peer->addr = *addr;
224 peer->cs = *cs;
225 peer->incoming = incoming;
226 peer->is_websocket = is_websocket;
227 peer->timeout = timeout;
228 peer->starttime = starttime;
229
230 /* BOLT #1:
231 *
232 * The sending node:
233 * - MUST send `init` as the first Lightning message for any
234 * connection.
235 * ...
236 * - SHOULD set `networks` to all chains it will gossip or open
237 * channels for.
238 */
239 tlvs = tlv_init_tlvs_new(tmpctx);
240 tlvs->networks = tal_dup_arr(tlvs, struct bitcoin_blkid,
241 &chainparams->genesis_blockhash, 1, 0);
242
243 /* set optional tlv `remote_addr` on incoming IP connections */
244 tlvs->remote_addr = NULL;
245
246 /* BOLT #1:
247 * The sending node:
248 * ...
249 * - SHOULD set `remote_addr` to reflect the remote IP address (and port) of an
250 * incoming connection, if the node is the receiver and the connection was done
251 * via IP.
252 */
253 if (incoming
254 && addr->itype == ADDR_INTERNAL_WIREADDR
255 && !addr->u.wireaddr.is_websocket
256 && address_routable(&addr->u.wireaddr.wireaddr, true)) {
257 switch (addr->u.wireaddr.wireaddr.type) {
258 case ADDR_TYPE_IPV4:
259 case ADDR_TYPE_IPV6:
260 tlvs->remote_addr = tal_arr(tlvs, u8, 0);
261 towire_wireaddr(&tlvs->remote_addr, &addr->u.wireaddr.wireaddr);
262 break;

Callers 2

handshake_in_successFunction · 0.85
handshake_out_successFunction · 0.85

Calls 9

towire_wireaddrFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
dev_sabotage_fdFunction · 0.85
io_conn_fdFunction · 0.85
tal_bytelenFunction · 0.85
address_routableFunction · 0.70
status_peer_ioFunction · 0.50
dev_disconnect_outFunction · 0.50
status_failedFunction · 0.50

Tested by

no test coverage detected