gossip: Forget nodes that have no associated channels anymore

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-01-13 12:30:52 +01:00 committed by Rusty Russell
parent 3a42e52bcd
commit 8f16f6ca09

View file

@ -1254,6 +1254,8 @@ static void gossip_prune_network(struct daemon *daemon)
struct node_map_iter it;
/* Anything below this highwater mark ought to be pruned */
s64 highwater = now - 2*daemon->update_channel_interval;
struct node *n;
struct node **prunednodes;
/* Schedule next run now */
new_reltimer(&daemon->timers, daemon,
@ -1261,7 +1263,7 @@ static void gossip_prune_network(struct daemon *daemon)
gossip_prune_network, daemon);
/* Find myself in the network */
struct node *n = node_map_get(daemon->rstate->nodes, &daemon->id.pubkey);
n = node_map_get(daemon->rstate->nodes, &daemon->id.pubkey);
if (!n) {
status_trace("Could not find myself in the nodemap, do we have a channel yet?");
return;
@ -1318,6 +1320,26 @@ static void gossip_prune_network(struct daemon *daemon)
tal_free(nc);
}
}
/* Finally remove all nodes that do not have any edges
* anymore. Accumulate into prunednodes, and delete in the
* second loop. */
prunednodes = tal_arr(n, struct node*, 0);
for (n = node_map_first(daemon->rstate->nodes, &it); n;
n = node_map_next(daemon->rstate->nodes, &it)) {
if (tal_count(n->in) == 0 && tal_count(n->out) == 0) {
size_t count = tal_count(prunednodes);
tal_resize(&prunednodes, count + 1);
prunednodes[count] = n;
}
}
for (size_t i=0; i<tal_count(prunednodes); i++) {
node_map_del(daemon->rstate->nodes, prunednodes[i]);
tal_free(prunednodes[i]);
}
tal_free(prunednodes);
}
static struct io_plan *connection_in(struct io_conn *conn, struct daemon *daemon)