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

Function peer_connected_hook_final

lightningd/peer_control.c:1562–1653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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