Skip to content

Commit

Permalink
gossip: Add the struct exclude_entry and enum exclude_entry_type
Browse files Browse the repository at this point in the history
  • Loading branch information
trueptolemy authored and ZmnSCPxj committed Sep 16, 2019
1 parent 90fa2ae commit 090a43f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gossipd/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ struct route_hop {
u32 delay;
};

enum exclude_entry_type {
EXCLUDE_CHANNEL = 1,
EXCLUDE_NODE = 2
};

struct exclude_entry {
enum exclude_entry_type type;
union {
struct short_channel_id_dir chan_id;
struct node_id node_id;
} u;
};

struct routing_state *new_routing_state(const tal_t *ctx,
const struct chainparams *chainparams,
const struct node_id *local_id,
Expand Down
30 changes: 30 additions & 0 deletions lightningd/gossip_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,33 @@ void towire_peer_features(u8 **pptr, const struct peer_features *pf)
towire_u16(pptr, tal_count(pf->globalfeatures));
towire_u8_array(pptr, pf->globalfeatures, tal_count(pf->globalfeatures));
}

struct exclude_entry *fromwire_exclude_entry(const tal_t *ctx,
const u8 **pptr, size_t *max)
{
struct exclude_entry *entry = tal(ctx, struct exclude_entry);
entry->type = fromwire_u8(pptr, max);
switch (entry->type) {
case EXCLUDE_CHANNEL:
fromwire_short_channel_id_dir(pptr, max, &entry->u.chan_id);
return entry;
case EXCLUDE_NODE:
fromwire_node_id(pptr, max, &entry->u.node_id);
return entry;
default:
fromwire_fail(pptr, max);
return NULL;
}
}

void towire_exclude_entry(u8 **pptr, const struct exclude_entry *entry)
{
assert(entry->type == EXCLUDE_CHANNEL ||
entry->type == EXCLUDE_NODE);

towire_u8(pptr, entry->type);
if (entry->type == EXCLUDE_CHANNEL)
towire_short_channel_id_dir(pptr, &entry->u.chan_id);
else
towire_node_id(pptr, &entry->u.node_id);
}
5 changes: 5 additions & 0 deletions lightningd/gossip_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ fromwire_gossip_getchannels_entry(const tal_t *ctx,
void towire_gossip_getchannels_entry(
u8 **pptr, const struct gossip_getchannels_entry *entry);

struct exclude_entry *
fromwire_exclude_entry(const tal_t *ctx,
const u8 **pptr, size_t *max);
void towire_exclude_entry(u8 **pptr, const struct exclude_entry *entry);

#endif /* LIGHTNING_LIGHTNINGD_GOSSIP_MSG_H */
1 change: 1 addition & 0 deletions tools/generate-wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class Type(FieldSet):
'wirestring',
'per_peer_state',
'bitcoin_tx_output',
'exclude_entry',
]

# Some BOLT types are re-typed based on their field name
Expand Down

0 comments on commit 090a43f

Please sign in to comment.