Browse Source

routing: expose setter for struct node_connection fields.

And use it in gossip's handle_local_add_channel.

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

20
gossipd/gossip.c

@ -765,7 +765,6 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
u32 fee_base_msat, fee_proportional_millionths; u32 fee_base_msat, fee_proportional_millionths;
u64 htlc_minimum_msat; u64 htlc_minimum_msat;
int idx; int idx;
struct node_connection *c;
struct routing_channel *chan; struct routing_channel *chan;
if (!fromwire_gossip_local_add_channel( if (!fromwire_gossip_local_add_channel(
@ -792,16 +791,15 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
chan = new_routing_channel(rstate, &scid, chan = new_routing_channel(rstate, &scid,
&rstate->local_id, &remote_node_id); &rstate->local_id, &remote_node_id);
idx = pubkey_idx(&rstate->local_id, &remote_node_id); idx = pubkey_idx(&rstate->local_id, &remote_node_id),
c = chan->connections[idx]; /* Activate the node_connection from us to them. */
set_connection_values(chan, idx,
/* FIXME: Deduplicate with code in routing.c */ fee_base_msat,
c->active = true; fee_proportional_millionths,
c->last_timestamp = 0; cltv_expiry_delta,
c->delay = cltv_expiry_delta; true,
c->htlc_minimum_msat = htlc_minimum_msat; 0,
c->base_fee = fee_base_msat; htlc_minimum_msat);
c->proportional_fee = fee_proportional_millionths;
/* Designed to match msg in handle_channel_update, for easy testing */ /* Designed to match msg in handle_channel_update, for easy testing */
status_trace("Received local update for channel %s(%d) now ACTIVE", status_trace("Received local update for channel %s(%d) now ACTIVE",
type_to_string(msg, struct short_channel_id, &scid), type_to_string(msg, struct short_channel_id, &scid),

65
gossipd/routing.c

@ -825,6 +825,43 @@ static void update_pending(struct pending_cannouncement *pending,
} }
} }
void set_connection_values(struct routing_channel *chan,
int idx,
u32 base_fee,
u32 proportional_fee,
u32 delay,
bool active,
u64 timestamp,
u32 htlc_minimum_msat)
{
struct node_connection *c = chan->connections[idx];
c->delay = delay;
c->htlc_minimum_msat = htlc_minimum_msat;
c->base_fee = base_fee;
c->proportional_fee = proportional_fee;
c->active = active;
c->last_timestamp = timestamp;
assert((c->flags & 0x1) == idx);
/* If it was temporarily unroutable, re-enable */
c->unroutable_until = 0;
SUPERVERBOSE("Channel %s(%d) was updated.",
type_to_string(trc, struct short_channel_id, &chan->scid),
idx);
if (c->proportional_fee >= MAX_PROPORTIONAL_FEE) {
status_trace("Channel %s(%d) massive proportional fee %u:"
" disabling.",
type_to_string(trc, struct short_channel_id,
&chan->scid),
idx,
c->proportional_fee);
c->active = false;
}
}
void handle_channel_update(struct routing_state *rstate, const u8 *update) void handle_channel_update(struct routing_state *rstate, const u8 *update)
{ {
u8 *serialized; u8 *serialized;
@ -916,27 +953,13 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
flags & 0x01, flags & 0x01,
flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE"); flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE");
c->last_timestamp = timestamp; set_connection_values(chan, direction,
c->delay = expiry; fee_base_msat,
c->htlc_minimum_msat = htlc_minimum_msat; fee_proportional_millionths,
c->base_fee = fee_base_msat; expiry,
c->proportional_fee = fee_proportional_millionths; (flags & ROUTING_FLAGS_DISABLED) == 0,
c->active = (flags & ROUTING_FLAGS_DISABLED) == 0; timestamp,
c->unroutable_until = 0; htlc_minimum_msat);
SUPERVERBOSE("Channel %s(%d) was updated.",
type_to_string(trc, struct short_channel_id,
&short_channel_id),
direction);
if (c->proportional_fee >= MAX_PROPORTIONAL_FEE) {
status_trace("Channel %s(%d) massive proportional fee %u:"
" disabling.",
type_to_string(trc, struct short_channel_id,
&short_channel_id),
direction,
fee_proportional_millionths);
c->active = false;
}
u8 *tag = tal_arr(tmpctx, u8, 0); u8 *tag = tal_arr(tmpctx, u8, 0);
towire_short_channel_id(&tag, &short_channel_id); towire_short_channel_id(&tag, &short_channel_id);

10
gossipd/routing.h

@ -219,6 +219,16 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
void handle_channel_update(struct routing_state *rstate, const u8 *update); void handle_channel_update(struct routing_state *rstate, const u8 *update);
void handle_node_announcement(struct routing_state *rstate, const u8 *node); void handle_node_announcement(struct routing_state *rstate, const u8 *node);
/* Set values on the struct node_connection */
void set_connection_values(struct routing_channel *chan,
int idx,
u32 base_fee,
u32 proportional_fee,
u32 delay,
bool active,
u64 timestamp,
u32 htlc_minimum_msat);
/* Get a node: use this instead of node_map_get() */ /* Get a node: use this instead of node_map_get() */
struct node *get_node(struct routing_state *rstate, const struct pubkey *id); struct node *get_node(struct routing_state *rstate, const struct pubkey *id);

Loading…
Cancel
Save