Browse Source

routing: move struct node_connection into struct routing_channel.

No need to have pointers since they're always there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
fd9c0c8543
  1. 21
      gossipd/gossip.c
  2. 39
      gossipd/routing.c
  3. 14
      gossipd/routing.h
  4. 2
      gossipd/test/run-bench-find_route.c
  5. 2
      gossipd/test/run-find_route-specific.c
  6. 4
      gossipd/test/run-find_route.c

21
gossipd/gossip.c

@ -726,13 +726,11 @@ static void handle_get_update(struct peer *peer, const u8 *msg)
&scid));
update = NULL;
} else {
struct node_connection *c;
/* We want update than comes from our end. */
/* We want update that comes from our end. */
if (pubkey_eq(&chan->nodes[0]->id, &peer->daemon->id))
c = chan->connections[0];
update = chan->connections[0].channel_update;
else if (pubkey_eq(&chan->nodes[1]->id, &peer->daemon->id))
c = chan->connections[1];
update = chan->connections[1].channel_update;
else {
status_unusual("peer %s scid %s: not our channel?",
type_to_string(trc, struct pubkey,
@ -740,11 +738,8 @@ static void handle_get_update(struct peer *peer, const u8 *msg)
type_to_string(trc,
struct short_channel_id,
&scid));
c = NULL;
update = NULL;
}
if (c)
update = c->channel_update;
}
status_trace("peer %s schanid %s: %s update",
type_to_string(trc, struct pubkey, &peer->id),
@ -1110,8 +1105,8 @@ static void append_half_channel(struct gossip_getchannels_entry **entries,
static void append_channel(struct gossip_getchannels_entry **entries,
const struct routing_channel *chan)
{
append_half_channel(entries, chan->connections[0]);
append_half_channel(entries, chan->connections[1]);
append_half_channel(entries, &chan->connections[0]);
append_half_channel(entries, &chan->connections[1]);
}
static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daemon,
@ -1280,7 +1275,7 @@ fail:
static void gossip_send_keepalive_update(struct routing_state *rstate,
struct node_connection *nc)
{
tal_t *tmpctx = tal_tmpctx(nc);
tal_t *tmpctx = tal_tmpctx(rstate);
secp256k1_ecdsa_signature sig;
struct bitcoin_blkid chain_hash;
struct short_channel_id scid;
@ -1832,7 +1827,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
type_to_string(msg, struct short_channel_id, &scid));
goto fail;
}
nc = chan->connections[direction];
nc = &chan->connections[direction];
status_trace("Disabling channel %s/%d, active %d -> %d",
type_to_string(msg, struct short_channel_id, &scid),

39
gossipd/routing.c

@ -196,20 +196,19 @@ static void destroy_routing_channel(struct routing_channel *chan,
tal_free(chan->nodes[1]);
}
static struct node_connection *new_node_connection(struct routing_state *rstate,
struct routing_channel *chan,
struct node *from,
struct node *to,
int idx)
static void init_node_connection(struct routing_state *rstate,
struct routing_channel *chan,
struct node *from,
struct node *to,
int idx)
{
struct node_connection *c;
struct node_connection *c = &chan->connections[idx];
/* We are going to put this in the right way? */
assert(idx == pubkey_idx(&from->id, &to->id));
assert(from == chan->nodes[idx]);
assert(to == chan->nodes[!idx]);
c = tal(rstate, struct node_connection);
c->src = from;
c->dst = to;
c->short_channel_id = chan->scid;
@ -220,10 +219,6 @@ static struct node_connection *new_node_connection(struct routing_state *rstate,
/* We haven't seen channel_update: make it halfway to prune time,
* which should be older than any update we'd see. */
c->last_timestamp = time_now().ts.tv_sec - rstate->prune_timeout/2;
/* Hook it into in/out arrays. */
chan->connections[idx] = c;
return c;
}
struct routing_channel *new_routing_channel(struct routing_state *rstate,
@ -260,8 +255,8 @@ struct routing_channel *new_routing_channel(struct routing_state *rstate,
n1->channels[n] = chan;
/* Populate with (inactive) connections */
new_node_connection(rstate, chan, n1, n2, n1idx);
new_node_connection(rstate, chan, n2, n1, !n1idx);
init_node_connection(rstate, chan, n1, n2, n1idx);
init_node_connection(rstate, chan, n2, n1, !n1idx);
uintmap_add(&rstate->channels, scid->u64, chan);
@ -805,7 +800,7 @@ void set_connection_values(struct routing_channel *chan,
u64 timestamp,
u32 htlc_minimum_msat)
{
struct node_connection *c = chan->connections[idx];
struct node_connection *c = &chan->connections[idx];
c->delay = delay;
c->htlc_minimum_msat = htlc_minimum_msat;
@ -898,7 +893,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
}
}
c = chan->connections[direction];
c = &chan->connections[direction];
if (c->last_timestamp >= timestamp) {
SUPERVERBOSE("Ignoring outdated update.");
@ -936,7 +931,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
serialized);
tal_free(c->channel_update);
c->channel_update = tal_steal(c, serialized);
c->channel_update = tal_steal(chan, serialized);
tal_free(tmpctx);
}
@ -1278,8 +1273,8 @@ void mark_channel_unroutable(struct routing_state *rstate,
tal_free(tmpctx);
return;
}
chan->connections[0]->unroutable_until = now + 20;
chan->connections[1]->unroutable_until = now + 20;
chan->connections[0].unroutable_until = now + 20;
chan->connections[1].unroutable_until = now + 20;
tal_free(tmpctx);
}
@ -1300,14 +1295,14 @@ void route_prune(struct routing_state *rstate)
if (!chan->public)
continue;
if (chan->connections[0]->last_timestamp < highwater
&& chan->connections[1]->last_timestamp < highwater) {
if (chan->connections[0].last_timestamp < highwater
&& chan->connections[1].last_timestamp < highwater) {
status_trace(
"Pruning channel %s from network view (ages %"PRIu64" and %"PRIu64"s)",
type_to_string(trc, struct short_channel_id,
&chan->scid),
now - chan->connections[0]->last_timestamp,
now - chan->connections[1]->last_timestamp);
now - chan->connections[0].last_timestamp,
now - chan->connections[1].last_timestamp);
/* This may perturb iteration so do outside loop. */
tal_steal(pruned, chan);

14
gossipd/routing.h

@ -98,7 +98,7 @@ struct routing_channel {
* connections[0]->src == nodes[0] connections[0]->dst == nodes[1]
* connections[1]->src == nodes[1] connections[1]->dst == nodes[0]
*/
struct node_connection *connections[2];
struct node_connection connections[2];
/* nodes[0].id < nodes[1].id */
struct node *nodes[2];
@ -124,9 +124,9 @@ static inline struct node_connection *connection_from(const struct node *n,
{
int idx = (chan->nodes[1] == n);
assert(chan->connections[idx]->src == n);
assert(chan->connections[!idx]->dst == n);
return chan->connections[idx];
assert(chan->connections[idx].src == n);
assert(chan->connections[!idx].dst == n);
return &chan->connections[idx];
}
static inline struct node_connection *connection_to(const struct node *n,
@ -134,9 +134,9 @@ static inline struct node_connection *connection_to(const struct node *n,
{
int idx = (chan->nodes[1] == n);
assert(chan->connections[idx]->src == n);
assert(chan->connections[!idx]->dst == n);
return chan->connections[!idx];
assert(chan->connections[idx].src == n);
assert(chan->connections[!idx].dst == n);
return &chan->connections[!idx];
}
struct routing_state {

2
gossipd/test/run-bench-find_route.c

@ -117,7 +117,7 @@ static struct node_connection *add_connection(struct routing_state *rstate,
if (!chan)
chan = new_routing_channel(rstate, &scid, from, to);
c = chan->connections[pubkey_idx(from, to)];
c = &chan->connections[pubkey_idx(from, to)];
c->base_fee = base_fee;
c->proportional_fee = proportional_fee;
c->delay = delay;

2
gossipd/test/run-find_route-specific.c

@ -83,7 +83,7 @@ get_or_make_connection(struct routing_state *rstate,
if (!chan)
chan = new_routing_channel(rstate, &scid, from_id, to_id);
return chan->connections[pubkey_idx(from_id, to_id)];
return &chan->connections[pubkey_idx(from_id, to_id)];
}
int main(void)

4
gossipd/test/run-find_route.c

@ -82,7 +82,7 @@ static struct node_connection *add_connection(struct routing_state *rstate,
if (!chan)
chan = new_routing_channel(rstate, &scid, from, to);
c = chan->connections[pubkey_idx(from, to)];
c = &chan->connections[pubkey_idx(from, to)];
c->base_fee = base_fee;
c->proportional_fee = proportional_fee;
c->delay = delay;
@ -127,7 +127,7 @@ static struct node_connection *get_connection(struct routing_state *rstate,
c = find_channel(rstate, from, to, &idx);
if (!c)
return NULL;
return c->connections[idx];
return &c->connections[idx];
}
int main(void)

Loading…
Cancel
Save