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

Function peer_connected_hook_final

lightningd/peer_control.c:1542–1633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1540}
1541
1542static void peer_connected_hook_final(struct peer_connected_hook_payload *payload STEALS)
1543{
1544 struct lightningd *ld = payload->ld;
1545 struct channel *channel;
1546 struct wireaddr_internal addr = payload->addr;
1547 struct peer *peer;
1548 u8 *error;
1549
1550 /* Whatever happens, we free payload (it's currently a child
1551 * of the peer, which may be freed if we fail to start
1552 * subd). */
1553 tal_steal(tmpctx, payload);
1554
1555 /* Peer might have gone away while we were waiting for plugin! */
1556 peer = peer_by_id(ld, &payload->peer_id);
1557 if (!peer)
1558 return;
1559
1560 /* If we disconnected in the meantime, forget about it.
1561 * (disconnect will have failed any connect commands).
1562 * And if it has reconnected, and we're the second time the
1563 * hook has been called, it'll be PEER_CONNECTED. */
1564 if (peer->connected != PEER_CONNECTING)
1565 return;
1566
1567 /* Check for specific errors of a hook */
1568 if (payload->error) {
1569 error = payload->error;
1570 goto send_error;
1571 }
1572
1573 /* Now we finally consider ourselves connected! */
1574 assert(peer->connected == PEER_CONNECTING);
1575 peer->connected = PEER_CONNECTED;
1576
1577 /* Succeed any connect() commands */
1578 connect_succeeded(ld, peer, payload->incoming, &payload->addr);
1579
1580 /* Notify anyone who cares */
1581 notify_connect(ld, &peer->id, payload->incoming, &addr);
1582
1583 /* Developer hack to fail all channels on permfail line. */
1584 if (dev_disconnect_permanent(ld)) {
1585 struct channel *c;
1586 list_for_each(&peer->channels, c, list) {
1587 subd_send_msg(ld->connectd,
1588 take(towire_connectd_peer_send_msg(NULL, &peer->id,
1589 peer->connectd_counter,
1590 /* cppcheck-suppress uninitvar - false positive on c */
1591 c->error)));
1592 subd_send_msg(ld->connectd,
1593 take(towire_connectd_disconnect_peer(NULL,
1594 &peer->id,
1595 peer->connectd_counter)));
1596 channel_fail_permanent(c, REASON_LOCAL,
1597 "dev_disconnect permfail");
1598 }
1599 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