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

Function peer_disconnected

lightningd/peer_control.c:2328–2378  ·  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

2326
2327/* This is also called when we reconnect, but we don't fail connect attempts */
2328static void peer_disconnected(struct lightningd *ld,
2329 const struct node_id *id,
2330 u64 connectd_counter,
2331 u64 connected_time_nsec,
2332 bool fail_connect_attempts)
2333{
2334 struct disconnect_command *i, *next;
2335 struct peer *p;
2336
2337 wallet_save_network_event(ld, id,
2338 NETWORK_EVENT_DISCONNECT,
2339 NULL, connected_time_nsec, false);
2340
2341 /* If we still have peer, it's disconnected now */
2342 p = peer_by_id(ld, id);
2343 if (p) {
2344 struct channel *channel;
2345 assert(p->connectd_counter == connectd_counter);
2346 log_peer_debug(ld->log, id, "peer_disconnected");
2347 p->connected = PEER_DISCONNECTED;
2348
2349 /* Note: we don't force subds to stop. They should exit soon,
2350 * but if we get a (re)connection we'll force them to stop */
2351 list_for_each(&p->channels, channel, list)
2352 channel_gossip_channel_disconnect(channel);
2353 }
2354
2355 /* If you were trying to connect, it failed. */
2356 if (fail_connect_attempts)
2357 connect_failed_disconnect(ld, id,
2358 p && !p->connected_incoming ? &p->addr : NULL);
2359
2360 /* Fire off plugin notifications */
2361 notify_disconnect(ld, id);
2362
2363 /* Wake any disconnect commands (removes self from list) */
2364 list_for_each_safe(&ld->disconnect_commands, i, next, list) {
2365 if (!node_id_eq(&i->id, id))
2366 continue;
2367
2368 was_pending(command_success(i->cmd,
2369 json_stream_success(i->cmd)));
2370 }
2371
2372 /* If connection was only thing keeping it, this will delete it. */
2373 if (p)
2374 maybe_delete_peer(p);
2375
2376 /* Maybe graceful wants to know? */
2377 check_graceful_shutdown(ld);
2378}
2379
2380void handle_peer_disconnected(struct lightningd *ld, const u8 *msg)
2381{

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