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

Function peer_connected

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

~ Note the lack of static: this is called by peer_exchange_initmsg.c once the * INIT messages are exchanged, and also by the retry code above. */

Source from the content-addressed store, hash-verified

295/*~ Note the lack of static: this is called by peer_exchange_initmsg.c once the
296 * INIT messages are exchanged, and also by the retry code above. */
297struct io_plan *peer_connected(struct io_conn *conn,
298 struct daemon *daemon,
299 const struct node_id *id,
300 const struct wireaddr_internal *addr,
301 const struct wireaddr *remote_addr,
302 struct crypto_state *cs,
303 const u8 *their_features TAKES,
304 enum is_websocket is_websocket,
305 struct timemono starttime,
306 bool incoming)
307{
308 u8 *msg;
309 struct peer *peer, *oldpeer;
310 int unsup;
311 size_t depender, missing;
312 int subd_fd;
313 bool option_gossip_queries;
314 struct connecting *connect;
315 const char *connect_reason;
316 u64 connect_time_nsec;
317 u64 prev_connectd_counter;
318 struct timemono prev_connect_start;
319
320 /* We remove any previous connection immediately, on the assumption it's dead */
321 oldpeer = peer_htable_get(daemon->peers, id);
322 if (oldpeer) {
323 prev_connectd_counter = oldpeer->counter;
324 prev_connect_start = oldpeer->connect_starttime;
325 destroy_peer_immediately(oldpeer);
326 }
327
328 /* BOLT #1:
329 *
330 * The receiving node:
331 * ...
332 * - upon receiving unknown _odd_ feature bits that are non-zero:
333 * - MUST ignore the bit.
334 * - upon receiving unknown _even_ feature bits that are non-zero:
335 * - MUST close the connection.
336 */
337 unsup = features_unsupported(daemon->our_features, their_features,
338 INIT_FEATURE);
339 if (unsup != -1) {
340 if (taken(their_features))
341 tal_free(their_features);
342
343 /* We were going to send a reconnect message, but not now! */
344 if (oldpeer)
345 send_disconnected(daemon, id, prev_connectd_counter,
346 prev_connect_start);
347 status_peer_unusual(id, "Unsupported feature %u", unsup);
348 msg = towire_warningfmt(NULL, NULL, "Unsupported feature %u",
349 unsup);
350 msg = cryptomsg_encrypt_msg(NULL, cs, take(msg));
351 return io_write_wire(conn, take(msg), io_close_cb, NULL);
352 }
353
354 if (!feature_check_depends(their_features, &depender, &missing)) {

Callers 1

peer_init_receivedFunction · 0.70

Calls 15

destroy_peer_immediatelyFunction · 0.85
takenFunction · 0.85
tal_freeFunction · 0.85
send_disconnectedFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
feature_check_dependsFunction · 0.85
find_connectingFunction · 0.85
time_to_nsecFunction · 0.85
timemono_sinceFunction · 0.85
io_closeFunction · 0.85
feature_negotiatedFunction · 0.85
setup_peer_gossip_storeFunction · 0.85

Tested by

no test coverage detected