2018-09-24 03:41:39 +02:00
|
|
|
#include <ccan/array_size/array_size.h>
|
2018-09-27 07:29:11 +02:00
|
|
|
#include <common/bolt11.h>
|
2017-10-23 06:17:38 +02:00
|
|
|
#include <common/wireaddr.h>
|
2017-03-15 10:43:03 +01:00
|
|
|
#include <lightningd/gossip_msg.h>
|
|
|
|
#include <wire/wire.h>
|
|
|
|
|
2018-04-20 10:09:50 +02:00
|
|
|
struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
|
|
|
const u8 **pptr, size_t *max)
|
2017-03-15 10:43:03 +01:00
|
|
|
{
|
2017-05-08 23:22:59 +02:00
|
|
|
u8 numaddresses, i;
|
2018-02-08 02:23:46 +01:00
|
|
|
struct gossip_getnodes_entry *entry;
|
2018-06-22 01:53:57 +02:00
|
|
|
u16 flen;
|
2018-02-08 02:23:46 +01:00
|
|
|
|
|
|
|
entry = tal(ctx, struct gossip_getnodes_entry);
|
2019-04-08 11:58:32 +02:00
|
|
|
fromwire_node_id(pptr, max, &entry->nodeid);
|
2018-06-22 01:53:57 +02:00
|
|
|
|
|
|
|
entry->last_timestamp = fromwire_u64(pptr, max);
|
2018-01-16 20:44:32 +01:00
|
|
|
if (entry->last_timestamp < 0) {
|
|
|
|
entry->addresses = NULL;
|
2018-02-08 02:23:46 +01:00
|
|
|
return entry;
|
2018-01-16 20:44:32 +01:00
|
|
|
}
|
2018-09-29 08:33:47 +02:00
|
|
|
|
|
|
|
flen = fromwire_u16(pptr, max);
|
2020-03-04 05:13:00 +01:00
|
|
|
entry->features = fromwire_tal_arrn(entry, pptr, max, flen);
|
2018-09-29 08:33:47 +02:00
|
|
|
|
2017-05-08 23:22:59 +02:00
|
|
|
numaddresses = fromwire_u8(pptr, max);
|
|
|
|
|
2018-02-08 02:23:46 +01:00
|
|
|
entry->addresses = tal_arr(entry, struct wireaddr, numaddresses);
|
2017-05-08 23:22:59 +02:00
|
|
|
for (i=0; i<numaddresses; i++) {
|
2017-09-01 06:18:55 +02:00
|
|
|
/* Gossipd doesn't hand us addresses we can't understand. */
|
2020-05-19 03:05:40 +02:00
|
|
|
if (!fromwire_wireaddr(pptr, max, &entry->addresses[i]))
|
|
|
|
return fromwire_fail(pptr, max);
|
2017-05-08 23:22:59 +02:00
|
|
|
}
|
2018-09-24 03:41:39 +02:00
|
|
|
fromwire(pptr, max, entry->alias, ARRAY_SIZE(entry->alias));
|
|
|
|
fromwire(pptr, max, entry->color, ARRAY_SIZE(entry->color));
|
2018-06-22 01:53:57 +02:00
|
|
|
|
2018-02-08 02:23:46 +01:00
|
|
|
return entry;
|
2017-03-15 10:43:03 +01:00
|
|
|
}
|
2018-02-08 02:23:46 +01:00
|
|
|
|
2018-04-20 10:09:50 +02:00
|
|
|
void towire_gossip_getnodes_entry(u8 **pptr,
|
|
|
|
const struct gossip_getnodes_entry *entry)
|
2017-03-15 10:43:03 +01:00
|
|
|
{
|
2019-04-08 11:58:32 +02:00
|
|
|
towire_node_id(pptr, &entry->nodeid);
|
2018-01-16 20:44:32 +01:00
|
|
|
towire_u64(pptr, entry->last_timestamp);
|
2017-05-08 23:22:59 +02:00
|
|
|
|
2018-01-16 20:44:32 +01:00
|
|
|
if (entry->last_timestamp < 0)
|
|
|
|
return;
|
|
|
|
|
2019-10-11 04:52:04 +02:00
|
|
|
towire_u16(pptr, tal_count(entry->features));
|
|
|
|
towire_u8_array(pptr, entry->features, tal_count(entry->features));
|
2018-09-29 08:33:47 +02:00
|
|
|
towire_u8(pptr, tal_count(entry->addresses));
|
|
|
|
for (size_t i = 0; i < tal_count(entry->addresses); i++) {
|
2017-10-23 06:17:38 +02:00
|
|
|
towire_wireaddr(pptr, &entry->addresses[i]);
|
2017-05-08 23:22:59 +02:00
|
|
|
}
|
2018-09-24 03:41:39 +02:00
|
|
|
towire(pptr, entry->alias, ARRAY_SIZE(entry->alias));
|
|
|
|
towire(pptr, entry->color, ARRAY_SIZE(entry->color));
|
2017-03-15 10:43:03 +01:00
|
|
|
}
|
2017-03-15 13:36:35 +01:00
|
|
|
|
2020-04-11 05:22:43 +02:00
|
|
|
struct route_hop *fromwire_route_hop(const tal_t *ctx,
|
|
|
|
const u8 **pptr, size_t *max)
|
2017-03-15 13:36:35 +01:00
|
|
|
{
|
2020-04-11 05:22:43 +02:00
|
|
|
struct route_hop *entry = tal(ctx, struct route_hop);
|
|
|
|
size_t enclen;
|
|
|
|
|
2019-04-08 11:58:32 +02:00
|
|
|
fromwire_node_id(pptr, max, &entry->nodeid);
|
2017-04-29 10:52:40 +02:00
|
|
|
fromwire_short_channel_id(pptr, max, &entry->channel_id);
|
2019-01-15 11:04:07 +01:00
|
|
|
entry->direction = fromwire_u8(pptr, max);
|
2019-02-21 03:39:21 +01:00
|
|
|
entry->amount = fromwire_amount_msat(pptr, max);
|
2017-03-15 13:36:35 +01:00
|
|
|
entry->delay = fromwire_u32(pptr, max);
|
2019-11-14 01:16:53 +01:00
|
|
|
entry->style = fromwire_u8(pptr, max);
|
2020-04-11 05:22:43 +02:00
|
|
|
if (fromwire_bool(pptr, max)) {
|
|
|
|
entry->blinding = tal(entry, struct pubkey);
|
|
|
|
fromwire_pubkey(pptr, max, entry->blinding);
|
|
|
|
}
|
|
|
|
enclen = fromwire_u16(pptr, max);
|
|
|
|
if (enclen)
|
|
|
|
entry->enctlv = fromwire_tal_arrn(entry, pptr, max, enclen);
|
|
|
|
else
|
|
|
|
entry->enctlv = NULL;
|
|
|
|
return entry;
|
2017-03-15 13:36:35 +01:00
|
|
|
}
|
2019-01-15 11:04:07 +01:00
|
|
|
|
2017-03-15 13:36:35 +01:00
|
|
|
void towire_route_hop(u8 **pptr, const struct route_hop *entry)
|
|
|
|
{
|
2019-04-08 11:58:32 +02:00
|
|
|
towire_node_id(pptr, &entry->nodeid);
|
2017-04-29 10:52:40 +02:00
|
|
|
towire_short_channel_id(pptr, &entry->channel_id);
|
2019-01-15 11:04:07 +01:00
|
|
|
towire_u8(pptr, entry->direction);
|
2019-02-21 03:39:21 +01:00
|
|
|
towire_amount_msat(pptr, entry->amount);
|
2017-03-15 13:36:35 +01:00
|
|
|
towire_u32(pptr, entry->delay);
|
2019-11-14 01:16:53 +01:00
|
|
|
towire_u8(pptr, entry->style);
|
2020-04-11 05:22:43 +02:00
|
|
|
if (entry->blinding) {
|
|
|
|
towire_bool(pptr, true);
|
|
|
|
towire_pubkey(pptr, entry->blinding);
|
|
|
|
} else
|
|
|
|
towire_bool(pptr, false);
|
|
|
|
towire_u16(pptr, tal_bytelen(entry->enctlv));
|
|
|
|
towire_u8_array(pptr, entry->enctlv, tal_bytelen(entry->enctlv));
|
2017-03-15 13:36:35 +01:00
|
|
|
}
|
|
|
|
|
2018-09-27 07:29:11 +02:00
|
|
|
void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry)
|
|
|
|
{
|
2019-04-08 11:58:32 +02:00
|
|
|
fromwire_node_id(pptr, max, &entry->pubkey);
|
2018-09-27 07:29:11 +02:00
|
|
|
fromwire_short_channel_id(pptr, max, &entry->short_channel_id);
|
|
|
|
entry->fee_base_msat = fromwire_u32(pptr, max);
|
|
|
|
entry->fee_proportional_millionths = fromwire_u32(pptr, max);
|
|
|
|
entry->cltv_expiry_delta = fromwire_u16(pptr, max);
|
|
|
|
}
|
|
|
|
|
|
|
|
void towire_route_info(u8 **pptr, const struct route_info *entry)
|
|
|
|
{
|
2019-04-08 11:58:32 +02:00
|
|
|
towire_node_id(pptr, &entry->pubkey);
|
2018-09-27 07:29:11 +02:00
|
|
|
towire_short_channel_id(pptr, &entry->short_channel_id);
|
|
|
|
towire_u32(pptr, entry->fee_base_msat);
|
|
|
|
towire_u32(pptr, entry->fee_proportional_millionths);
|
|
|
|
towire_u16(pptr, entry->cltv_expiry_delta);
|
|
|
|
}
|
|
|
|
|
2019-04-08 11:58:44 +02:00
|
|
|
static void fromwire_gossip_halfchannel_entry(const u8 **pptr, size_t *max,
|
|
|
|
struct gossip_halfchannel_entry *entry)
|
2017-03-22 13:30:09 +01:00
|
|
|
{
|
2018-09-20 02:59:46 +02:00
|
|
|
entry->message_flags = fromwire_u8(pptr, max);
|
|
|
|
entry->channel_flags = fromwire_u8(pptr, max);
|
2018-05-10 16:00:38 +02:00
|
|
|
entry->last_update_timestamp = fromwire_u32(pptr, max);
|
2019-04-08 11:58:44 +02:00
|
|
|
entry->delay = fromwire_u32(pptr, max);
|
2018-05-10 16:00:38 +02:00
|
|
|
entry->base_fee_msat = fromwire_u32(pptr, max);
|
|
|
|
entry->fee_per_millionth = fromwire_u32(pptr, max);
|
2019-05-31 09:28:06 +02:00
|
|
|
entry->min = fromwire_amount_msat(pptr, max);
|
|
|
|
entry->max = fromwire_amount_msat(pptr, max);
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|
|
|
|
|
2019-04-08 11:58:44 +02:00
|
|
|
struct gossip_getchannels_entry *
|
|
|
|
fromwire_gossip_getchannels_entry(const tal_t *ctx,
|
|
|
|
const u8 **pptr, size_t *max)
|
|
|
|
{
|
|
|
|
struct gossip_getchannels_entry *entry;
|
|
|
|
|
|
|
|
entry= tal(ctx, struct gossip_getchannels_entry);
|
|
|
|
fromwire_node_id(pptr, max, &entry->node[0]);
|
|
|
|
fromwire_node_id(pptr, max, &entry->node[1]);
|
|
|
|
entry->sat = fromwire_amount_sat(pptr, max);
|
|
|
|
fromwire_short_channel_id(pptr, max, &entry->short_channel_id);
|
|
|
|
entry->public = fromwire_bool(pptr, max);
|
|
|
|
entry->local_disabled = fromwire_bool(pptr, max);
|
2020-05-04 02:19:32 +02:00
|
|
|
entry->features = fromwire_tal_arrn(entry,
|
|
|
|
pptr, max, fromwire_u16(pptr, max));
|
2019-04-08 11:58:44 +02:00
|
|
|
|
|
|
|
if (fromwire_bool(pptr, max)) {
|
|
|
|
entry->e[0] = tal(entry, struct gossip_halfchannel_entry);
|
|
|
|
fromwire_gossip_halfchannel_entry(pptr, max, entry->e[0]);
|
|
|
|
} else
|
|
|
|
entry->e[0] = NULL;
|
|
|
|
if (fromwire_bool(pptr, max)) {
|
|
|
|
entry->e[1] = tal(entry, struct gossip_halfchannel_entry);
|
|
|
|
fromwire_gossip_halfchannel_entry(pptr, max, entry->e[1]);
|
|
|
|
} else
|
|
|
|
entry->e[1] = NULL;
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void towire_gossip_halfchannel_entry(u8 **pptr,
|
|
|
|
const struct gossip_halfchannel_entry *entry)
|
2017-03-22 13:30:09 +01:00
|
|
|
{
|
2018-09-20 02:59:46 +02:00
|
|
|
towire_u8(pptr, entry->message_flags);
|
|
|
|
towire_u8(pptr, entry->channel_flags);
|
2018-05-10 16:00:38 +02:00
|
|
|
towire_u32(pptr, entry->last_update_timestamp);
|
2019-04-08 11:58:44 +02:00
|
|
|
towire_u32(pptr, entry->delay);
|
2018-05-10 16:00:38 +02:00
|
|
|
towire_u32(pptr, entry->base_fee_msat);
|
|
|
|
towire_u32(pptr, entry->fee_per_millionth);
|
2019-05-31 09:28:06 +02:00
|
|
|
towire_amount_msat(pptr, entry->min);
|
|
|
|
towire_amount_msat(pptr, entry->max);
|
2019-04-08 11:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void towire_gossip_getchannels_entry(u8 **pptr,
|
|
|
|
const struct gossip_getchannels_entry *entry)
|
|
|
|
{
|
|
|
|
towire_node_id(pptr, &entry->node[0]);
|
|
|
|
towire_node_id(pptr, &entry->node[1]);
|
|
|
|
towire_amount_sat(pptr, entry->sat);
|
|
|
|
towire_short_channel_id(pptr, &entry->short_channel_id);
|
|
|
|
towire_bool(pptr, entry->public);
|
|
|
|
towire_bool(pptr, entry->local_disabled);
|
2020-05-04 02:19:32 +02:00
|
|
|
towire_u16(pptr, tal_bytelen(entry->features));
|
|
|
|
towire_u8_array(pptr, entry->features, tal_bytelen(entry->features));
|
2019-04-08 11:58:44 +02:00
|
|
|
if (entry->e[0]) {
|
|
|
|
towire_bool(pptr, true);
|
|
|
|
towire_gossip_halfchannel_entry(pptr, entry->e[0]);
|
|
|
|
} else
|
|
|
|
towire_bool(pptr, false);
|
|
|
|
|
|
|
|
if (entry->e[1]) {
|
|
|
|
towire_bool(pptr, true);
|
|
|
|
towire_gossip_halfchannel_entry(pptr, entry->e[1]);
|
|
|
|
} else
|
|
|
|
towire_bool(pptr, false);
|
2017-03-22 13:30:09 +01:00
|
|
|
}
|
2018-07-24 08:18:59 +02:00
|
|
|
|
2019-08-31 14:52:35 +02:00
|
|
|
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:
|
2020-05-19 03:05:40 +02:00
|
|
|
return fromwire_fail(pptr, max);
|
2019-08-31 14:52:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|