~ When we free a peer, we remove it from the daemon's hashtable. * We also call this manually if we want to elegantly drain peer's * queues. */
| 205 | * We also call this manually if we want to elegantly drain peer's |
| 206 | * queues. */ |
| 207 | void destroy_peer(struct peer *peer) |
| 208 | { |
| 209 | assert(!peer->draining); |
| 210 | |
| 211 | if (!peer_htable_del(&peer->daemon->peers, peer)) |
| 212 | abort(); |
| 213 | |
| 214 | /* Tell gossipd to stop asking this peer gossip queries */ |
| 215 | daemon_conn_send(peer->daemon->gossipd, |
| 216 | take(towire_gossipd_peer_gone(NULL, &peer->id))); |
| 217 | |
| 218 | /* Tell lightningd it's really disconnected */ |
| 219 | daemon_conn_send(peer->daemon->master, |
| 220 | take(towire_connectd_peer_disconnect_done(NULL, |
| 221 | &peer->id, |
| 222 | peer->counter))); |
| 223 | /* This makes multiplex.c routines not feed us more, but |
| 224 | * *also* means that if we're freed directly, the ->to_peer |
| 225 | * destructor won't call drain_peer(). */ |
| 226 | peer->draining = true; |
| 227 | } |
| 228 | |
| 229 | /*~ This is where we create a new peer. */ |
| 230 | static struct peer *new_peer(struct daemon *daemon, |
no test coverage detected