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

Function peer_connect_subd

connectd/multiplex.c:1685–1736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1683}
1684
1685void peer_connect_subd(struct daemon *daemon, const u8 *msg, int fd)
1686{
1687 struct node_id id;
1688 u64 counter;
1689 struct peer *peer;
1690 struct channel_id channel_id;
1691 struct subd *subd;
1692
1693 if (!fromwire_connectd_peer_connect_subd(msg, &id, &counter, &channel_id))
1694 master_badmsg(WIRE_CONNECTD_PEER_CONNECT_SUBD, msg);
1695
1696 /* If receiving fd failed, fd will be -1. Log and ignore
1697 * (subd will see immediate hangup). */
1698 if (fd == -1) {
1699 static bool recvfd_logged = false;
1700 status_broken_once(&recvfd_logged,
1701 "receiving lightningd fd failed for %s: %s",
1702 fmt_node_id(tmpctx, &id),
1703 strerror(errno));
1704 /* Maybe free up some fds by closing something. */
1705 close_random_connection(daemon);
1706 return;
1707 }
1708
1709 /* Races can happen: this might be gone by now (or reconnected!). */
1710 peer = peer_htable_get(daemon->peers, &id);
1711 if (!peer || peer->counter != counter) {
1712 close(fd);
1713 return;
1714 }
1715
1716 /* Could be disconnecting now */
1717 if (!peer->to_peer || peer->draining_state != NOT_DRAINING) {
1718 close(fd);
1719 return;
1720 }
1721
1722 /* If peer said something, we created this and queued msg. */
1723 subd = find_subd(peer, &channel_id);
1724 if (!subd) {
1725 subd = new_subd(peer, &channel_id);
1726 /* Implies lightningd is ready for another peer. */
1727 release_one_waiting_connection(peer->daemon,
1728 tal_fmt(tmpctx, "%s given a subd",
1729 fmt_node_id(tmpctx, &id)));
1730 }
1731
1732 assert(!subd->conn);
1733
1734 /* This sets subd->conn inside subd_conn_init, and reparents subd! */
1735 io_new_conn(peer, fd, subd_conn_init, subd);
1736}
1737
1738/* Lightningd says to send a ping */
1739void send_manual_ping(struct daemon *daemon, const u8 *msg)

Callers 1

recv_peer_connect_subdFunction · 0.85

Calls 6

fmt_node_idFunction · 0.85
close_random_connectionFunction · 0.85
find_subdFunction · 0.85
new_subdFunction · 0.70
master_badmsgFunction · 0.50

Tested by

no test coverage detected