Browse Source

routing: connections are now never null; simplify.

Failure and pruning were the two places where a node_connection could
be freed; now they both deal with entire channels, we can remove the
NULL checks, and the destructor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
be14b52423
  1. 9
      gossipd/gossip.c
  2. 38
      gossipd/routing.c
  3. 10
      gossipd/routing.h

9
gossipd/gossip.c

@ -1349,7 +1349,7 @@ static void gossip_refresh_network(struct daemon *daemon)
nc = connection_from(n, n->channels[i]);
if (!nc || !nc->channel_update) {
if (!nc->channel_update) {
/* Connection is not public yet, so don't even
* try to re-announce it */
continue;
@ -1826,11 +1826,10 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
}
chan = get_channel(daemon->rstate, &scid);
if (!chan || !chan->connections[direction]) {
if (!chan) {
status_trace(
"Unable to find channel %s/%d",
type_to_string(msg, struct short_channel_id, &scid),
direction);
"Unable to find channel %s",
type_to_string(msg, struct short_channel_id, &scid));
goto fail;
}
nc = chan->connections[direction];

38
gossipd/routing.c

@ -196,20 +196,6 @@ static void destroy_routing_channel(struct routing_channel *chan,
tal_free(chan->nodes[1]);
}
static void destroy_node_connection(struct node_connection *nc,
struct routing_channel *chan)
{
int dir = nc->flags & 0x1;
struct node_connection *c = chan->connections[dir];
assert(nc == c);
chan->connections[dir] = NULL;
/* Both sides deleted? Free channel */
if (!chan->connections[!dir])
tal_free(chan);
}
static struct node_connection *new_node_connection(struct routing_state *rstate,
struct routing_channel *chan,
struct node *from,
@ -237,8 +223,6 @@ static struct node_connection *new_node_connection(struct routing_state *rstate,
/* Hook it into in/out arrays. */
chan->connections[idx] = c;
tal_add_destructor2(c, destroy_node_connection, chan);
return c;
}
@ -380,7 +364,7 @@ static void bfg_one_edge(struct node *node,
/* Determine if the given node_connection is routable */
static bool nc_is_routable(const struct node_connection *nc, time_t now)
{
return nc && nc->active && nc->unroutable_until < now;
return nc->active && nc->unroutable_until < now;
}
/* riskfactor is already scaled to per-block amount */
@ -916,13 +900,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
c = chan->connections[direction];
/* Channel could have been pruned: re-add */
if (!c) {
c = new_node_connection(rstate, chan,
chan->nodes[direction],
chan->nodes[!direction],
direction);
} else if (c->last_timestamp >= timestamp) {
if (c->last_timestamp >= timestamp) {
SUPERVERBOSE("Ignoring outdated update.");
tal_free(tmpctx);
return;
@ -1164,11 +1142,7 @@ static void routing_failure_channel_out(const tal_t *disposal_context,
struct routing_channel *chan,
time_t now)
{
struct node_connection *nc;
nc = connection_from(node, chan);
if (!nc)
return;
struct node_connection *nc = connection_from(node, chan);
/* BOLT #4:
*
@ -1304,10 +1278,8 @@ void mark_channel_unroutable(struct routing_state *rstate,
tal_free(tmpctx);
return;
}
if (chan->connections[0])
chan->connections[0]->unroutable_until = now + 20;
if (chan->connections[1])
chan->connections[1]->unroutable_until = now + 20;
chan->connections[0]->unroutable_until = now + 20;
chan->connections[1]->unroutable_until = now + 20;
tal_free(tmpctx);
}

10
gossipd/routing.h

@ -94,7 +94,7 @@ struct routing_channel {
struct short_channel_id scid;
u8 *txout_script;
/* One of these might be NULL.
/*
* connections[0]->src == nodes[0] connections[0]->dst == nodes[1]
* connections[1]->src == nodes[1] connections[1]->dst == nodes[0]
*/
@ -124,8 +124,8 @@ static inline struct node_connection *connection_from(const struct node *n,
{
int idx = (chan->nodes[1] == n);
assert(!chan->connections[idx] || chan->connections[idx]->src == n);
assert(!chan->connections[!idx] || chan->connections[!idx]->dst == n);
assert(chan->connections[idx]->src == n);
assert(chan->connections[!idx]->dst == n);
return chan->connections[idx];
}
@ -134,8 +134,8 @@ static inline struct node_connection *connection_to(const struct node *n,
{
int idx = (chan->nodes[1] == n);
assert(!chan->connections[idx] || chan->connections[idx]->src == n);
assert(!chan->connections[!idx] || chan->connections[!idx]->dst == n);
assert(chan->connections[idx]->src == n);
assert(chan->connections[!idx]->dst == n);
return chan->connections[!idx];
}

Loading…
Cancel
Save