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

Function peer_disconnected

lightningd/peer_control.c:2222–2272  ·  view source on GitHub ↗

This is also called when we reconnect, but we don't fail connect attempts */

Source from the content-addressed store, hash-verified

2220
2221/* This is also called when we reconnect, but we don't fail connect attempts */
2222static void peer_disconnected(struct lightningd *ld,
2223 const struct node_id *id,
2224 u64 connectd_counter,
2225 u64 connected_time_nsec,
2226 bool fail_connect_attempts)
2227{
2228 struct disconnect_command *i, *next;
2229 struct peer *p;
2230
2231 wallet_save_network_event(ld, id,
2232 NETWORK_EVENT_DISCONNECT,
2233 NULL, connected_time_nsec, false);
2234
2235 /* If we still have peer, it's disconnected now */
2236 p = peer_by_id(ld, id);
2237 if (p) {
2238 struct channel *channel;
2239 assert(p->connectd_counter == connectd_counter);
2240 log_peer_debug(ld->log, id, "peer_disconnected");
2241 p->connected = PEER_DISCONNECTED;
2242
2243 /* Note: we don't force subds to stop. They should exit soon,
2244 * but if we get a (re)connection we'll force them to stop */
2245 list_for_each(&p->channels, channel, list)
2246 channel_gossip_channel_disconnect(channel);
2247 }
2248
2249 /* If you were trying to connect, it failed. */
2250 if (fail_connect_attempts)
2251 connect_failed_disconnect(ld, id,
2252 p && !p->connected_incoming ? &p->addr : NULL);
2253
2254 /* Fire off plugin notifications */
2255 notify_disconnect(ld, id);
2256
2257 /* Wake any disconnect commands (removes self from list) */
2258 list_for_each_safe(&ld->disconnect_commands, i, next, list) {
2259 if (!node_id_eq(&i->id, id))
2260 continue;
2261
2262 was_pending(command_success(i->cmd,
2263 json_stream_success(i->cmd)));
2264 }
2265
2266 /* If connection was only thing keeping it, this will delete it. */
2267 if (p)
2268 maybe_delete_peer(p);
2269
2270 /* Maybe graceful wants to know? */
2271 check_graceful_shutdown(ld);
2272}
2273
2274void handle_peer_disconnected(struct lightningd *ld, const u8 *msg)
2275{

Callers 2

handle_peer_connectedFunction · 0.85
handle_peer_disconnectedFunction · 0.85

Calls 11

peer_by_idFunction · 0.85
node_id_eqFunction · 0.85
maybe_delete_peerFunction · 0.85
check_graceful_shutdownFunction · 0.85
notify_disconnectFunction · 0.70
was_pendingFunction · 0.70
command_successFunction · 0.70
json_stream_successFunction · 0.70

Tested by

no test coverage detected