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

Function peer_exchange_initmsg

connectd/peer_exchange_initmsg.c:188–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186#endif
187
188struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
189 struct daemon *daemon,
190 const struct feature_set *our_features,
191 const struct crypto_state *cs,
192 const struct node_id *id,
193 const struct wireaddr_internal *addr,
194 struct oneshot *timeout,
195 bool incoming)
196{
197 /* If conn is closed, forget peer */
198 struct early_peer *peer = tal(conn, struct early_peer);
199 struct io_plan *(*next)(struct io_conn *, struct early_peer *);
200 struct tlv_init_tlvs *tlvs;
201
202 peer->daemon = daemon;
203 peer->id = *id;
204 peer->addr = *addr;
205 peer->cs = *cs;
206 peer->incoming = incoming;
207
208 /* Attach timer to early peer, so it gets freed with it. */
209 notleak(tal_steal(peer, timeout));
210
211 /* BOLT #1:
212 *
213 * The sending node:
214 * - MUST send `init` as the first Lightning message for any
215 * connection.
216 * ...
217 * - SHOULD set `networks` to all chains it will gossip or open
218 * channels for.
219 */
220 tlvs = tlv_init_tlvs_new(tmpctx);
221 tlvs->networks = tal_dup_arr(tlvs, struct bitcoin_blkid,
222 &chainparams->genesis_blockhash, 1, 0);
223
224 /* set optional tlv `remote_addr` on incoming IP connections */
225 tlvs->remote_addr = NULL;
226
227 /* BOLT #1:
228 * The sending node:
229 * ...
230 * - SHOULD set `remote_addr` to reflect the remote IP address (and port) of an
231 * incoming connection, if the node is the receiver and the connection was done
232 * via IP.
233 */
234 if (incoming && addr->itype == ADDR_INTERNAL_WIREADDR &&
235 address_routable(&addr->u.wireaddr, true)) {
236 switch (addr->u.wireaddr.type) {
237 case ADDR_TYPE_IPV4:
238 case ADDR_TYPE_IPV6:
239 tlvs->remote_addr = tal_arr(tlvs, u8, 0);
240 towire_wireaddr(&tlvs->remote_addr, &addr->u.wireaddr);
241 break;
242 /* Only report IP addresses back for now */
243 case ADDR_TYPE_TOR_V2_REMOVED:
244 case ADDR_TYPE_TOR_V3:
245 case ADDR_TYPE_DNS:

Callers 2

handshake_in_successFunction · 0.85
handshake_out_successFunction · 0.85

Calls 9

address_routableFunction · 0.85
towire_wireaddrFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
dev_sabotage_fdFunction · 0.85
io_conn_fdFunction · 0.85
tal_bytelenFunction · 0.85
status_peer_ioFunction · 0.50
dev_disconnectFunction · 0.50
status_failedFunction · 0.50

Tested by

no test coverage detected