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

Function drain_peer

connectd/multiplex.c:112–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static void drain_peer(struct peer *peer)
113{
114 status_debug("drain_peer");
115 assert(!peer->draining);
116
117 /* Since we immediately free any subds we didn't connect yet,
118 * we need peer->to_peer set so it won't free peer! */
119 assert(peer->to_peer);
120
121 /* Give the subds 5 seconds to close their fds to us. */
122 for (size_t i = 0; i < tal_count(peer->subds); i++) {
123 if (!peer->subds[i]->conn) {
124 /* Deletes itself from array, so be careful! */
125 tal_free(peer->subds[i]);
126 i--;
127 continue;
128 }
129 status_debug("drain_peer draining subd!");
130 notleak(new_reltimer(&peer->daemon->timers,
131 peer->subds[i], time_from_sec(5),
132 close_subd_timeout, peer->subds[i]));
133 /* Wake any outgoing queued on subd */
134 io_wake(peer->subds[i]->outq);
135 }
136
137 /* Wake them to ensure they notice the close! */
138 io_wake(&peer->subds);
139
140 if (peer->to_peer) {
141 /* You have 5 seconds to drain... */
142 notleak(new_reltimer(&peer->daemon->timers,
143 peer->to_peer, time_from_sec(5),
144 close_peer_io_timeout, peer));
145 }
146
147 /* Clean peer from hashtable; we no longer exist. */
148 destroy_peer(peer);
149 tal_del_destructor(peer, destroy_peer);
150
151 /* This is a 5-second leak, worst case! */
152 notleak(peer);
153
154 /* Start draining process! */
155 io_wake(peer->peer_outq);
156}
157
158void inject_peer_msg(struct peer *peer, const u8 *msg TAKES)
159{

Callers 3

multiplex_final_msgFunction · 0.85
encrypt_and_sendFunction · 0.85
destroy_peer_connFunction · 0.85

Calls 4

tal_freeFunction · 0.85
time_from_secFunction · 0.85
io_wakeFunction · 0.85
destroy_peerFunction · 0.70

Tested by

no test coverage detected