This is also called when we reconnect, but we don't fail connect attempts */
| 2384 | |
| 2385 | /* This is also called when we reconnect, but we don't fail connect attempts */ |
| 2386 | static void peer_disconnected(struct lightningd *ld, |
| 2387 | const struct node_id *id, |
| 2388 | u64 connectd_counter, |
| 2389 | u64 connected_time_nsec, |
| 2390 | bool fail_connect_attempts) |
| 2391 | { |
| 2392 | struct disconnect_command *i, *next; |
| 2393 | struct peer *p; |
| 2394 | |
| 2395 | wallet_save_network_event(ld, id, |
| 2396 | NETWORK_EVENT_DISCONNECT, |
| 2397 | NULL, connected_time_nsec, false); |
| 2398 | |
| 2399 | /* If we still have peer, it's disconnected now */ |
| 2400 | p = peer_by_id(ld, id); |
| 2401 | if (p) { |
| 2402 | struct channel *channel; |
| 2403 | assert(p->connectd_counter == connectd_counter); |
| 2404 | log_peer_debug(ld->log, id, "peer_disconnected"); |
| 2405 | p->connected = PEER_DISCONNECTED; |
| 2406 | |
| 2407 | /* Note: we don't force subds to stop. They should exit soon, |
| 2408 | * but if we get a (re)connection we'll force them to stop */ |
| 2409 | list_for_each(&p->channels, channel, list) |
| 2410 | channel_gossip_channel_disconnect(channel); |
| 2411 | } |
| 2412 | |
| 2413 | /* If you were trying to connect, it failed. */ |
| 2414 | if (fail_connect_attempts) |
| 2415 | connect_failed_disconnect(ld, id, |
| 2416 | p && !p->connected_incoming ? &p->addr : NULL); |
| 2417 | |
| 2418 | /* Fire off plugin notifications */ |
| 2419 | notify_disconnect(ld, id); |
| 2420 | |
| 2421 | /* Wake any disconnect commands (removes self from list) */ |
| 2422 | list_for_each_safe(&ld->disconnect_commands, i, next, list) { |
| 2423 | if (!node_id_eq(&i->id, id)) |
| 2424 | continue; |
| 2425 | |
| 2426 | was_pending(command_success(i->cmd, |
| 2427 | json_stream_success(i->cmd))); |
| 2428 | } |
| 2429 | |
| 2430 | /* If connection was only thing keeping it, this will delete it. */ |
| 2431 | if (p) |
| 2432 | maybe_delete_peer(p); |
| 2433 | |
| 2434 | /* Maybe graceful wants to know? */ |
| 2435 | check_graceful_shutdown(ld); |
| 2436 | } |
| 2437 | |
| 2438 | void handle_peer_disconnected(struct lightningd *ld, const u8 *msg) |
| 2439 | { |
no test coverage detected