gossip: Add the `struct exclude_entry` and `enum exclude_entry_type`

This commit is contained in:
trueptolemy 2019-08-31 20:52:35 +08:00 committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent 90fa2ae3fd
commit 090a43fd3d
4 changed files with 49 additions and 0 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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 */

View File

@ -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