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

Function peer_connected_hook_final

lightningd/peer_control.c:1502–1593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1500}
1501
1502static void peer_connected_hook_final(struct peer_connected_hook_payload *payload STEALS)
1503{
1504 struct lightningd *ld = payload->ld;
1505 struct channel *channel;
1506 struct wireaddr_internal addr = payload->addr;
1507 struct peer *peer;
1508 u8 *error;
1509
1510 /* Whatever happens, we free payload (it's currently a child
1511 * of the peer, which may be freed if we fail to start
1512 * subd). */
1513 tal_steal(tmpctx, payload);
1514
1515 /* Peer might have gone away while we were waiting for plugin! */
1516 peer = peer_by_id(ld, &payload->peer_id);
1517 if (!peer)
1518 return;
1519
1520 /* If we disconnected in the meantime, forget about it.
1521 * (disconnect will have failed any connect commands).
1522 * And if it has reconnected, and we're the second time the
1523 * hook has been called, it'll be PEER_CONNECTED. */
1524 if (peer->connected != PEER_CONNECTING)
1525 return;
1526
1527 /* Check for specific errors of a hook */
1528 if (payload->error) {
1529 error = payload->error;
1530 goto send_error;
1531 }
1532
1533 /* Now we finally consider ourselves connected! */
1534 assert(peer->connected == PEER_CONNECTING);
1535 peer->connected = PEER_CONNECTED;
1536
1537 /* Succeed any connect() commands */
1538 connect_succeeded(ld, peer, payload->incoming, &payload->addr);
1539
1540 /* Notify anyone who cares */
1541 notify_connect(ld, &peer->id, payload->incoming, &addr);
1542
1543 /* Developer hack to fail all channels on permfail line. */
1544 if (dev_disconnect_permanent(ld)) {
1545 struct channel *c;
1546 list_for_each(&peer->channels, c, list) {
1547 subd_send_msg(ld->connectd,
1548 take(towire_connectd_peer_send_msg(NULL, &peer->id,
1549 peer->connectd_counter,
1550 /* cppcheck-suppress uninitvar - false positive on c */
1551 c->error)));
1552 subd_send_msg(ld->connectd,
1553 take(towire_connectd_disconnect_peer(NULL,
1554 &peer->id,
1555 peer->connectd_counter)));
1556 channel_fail_permanent(c, REASON_LOCAL,
1557 "dev_disconnect permfail");
1558 }
1559 return;

Callers 1

Calls 13

peer_by_idFunction · 0.85
ignore_idle_channelFunction · 0.85
connect_activate_subdFunction · 0.85
tal_hexFunction · 0.85
connect_succeededFunction · 0.70
notify_connectFunction · 0.70
dev_disconnect_permanentFunction · 0.70
subd_send_msgFunction · 0.70
channel_fail_permanentFunction · 0.70
channel_state_nameFunction · 0.70

Tested by

no test coverage detected