mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
common/wireaddr: fromwire_wireaddr_array helper.
This was previously internal to gossipd and was called "read_addresses". Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
79299a4780
commit
e734097125
11 changed files with 52 additions and 54 deletions
|
@ -691,6 +691,35 @@ struct addrinfo *wireaddr_to_addrinfo(const tal_t *ctx,
|
|||
abort();
|
||||
}
|
||||
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx, const u8 *ser)
|
||||
{
|
||||
const u8 *cursor = ser;
|
||||
size_t len = tal_count(ser);
|
||||
struct wireaddr *wireaddrs = tal_arr(ctx, struct wireaddr, 0);
|
||||
|
||||
while (cursor && len) {
|
||||
struct wireaddr wireaddr;
|
||||
|
||||
/* BOLT #7:
|
||||
*
|
||||
* The receiving node:
|
||||
*...
|
||||
* - SHOULD ignore the first `address descriptor` that does
|
||||
* NOT match the types defined above.
|
||||
*/
|
||||
if (!fromwire_wireaddr(&cursor, &len, &wireaddr)) {
|
||||
if (!cursor)
|
||||
/* Parsing address failed */
|
||||
return tal_free(wireaddrs);
|
||||
/* Unknown type, stop there. */
|
||||
break;
|
||||
}
|
||||
|
||||
tal_arr_expand(&wireaddrs, wireaddr);
|
||||
}
|
||||
return wireaddrs;
|
||||
}
|
||||
|
||||
bool all_tor_addresses(const struct wireaddr_internal *wireaddr)
|
||||
{
|
||||
for (int i = 0; i < tal_count(wireaddr); i++) {
|
||||
|
|
|
@ -165,4 +165,7 @@ struct addrinfo *wireaddr_internal_to_addrinfo(const tal_t *ctx,
|
|||
|
||||
bool all_tor_addresses(const struct wireaddr_internal *wireaddr);
|
||||
|
||||
/* Decode an array of serialized addresses from node_announcement */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx, const u8 *ser);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_WIREADDR_H */
|
||||
|
|
|
@ -193,7 +193,7 @@ static bool get_node_announcement(const tal_t *ctx,
|
|||
return false;
|
||||
}
|
||||
|
||||
*wireaddrs = read_addresses(ctx, addresses);
|
||||
*wireaddrs = fromwire_wireaddr_array(ctx, addresses);
|
||||
tal_free(addresses);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2383,37 +2383,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser)
|
||||
{
|
||||
const u8 *cursor = ser;
|
||||
size_t len = tal_count(ser);
|
||||
struct wireaddr *wireaddrs = tal_arr(ctx, struct wireaddr, 0);
|
||||
|
||||
while (cursor && len) {
|
||||
struct wireaddr wireaddr;
|
||||
|
||||
/* BOLT #7:
|
||||
*
|
||||
* The receiving node:
|
||||
*...
|
||||
* - SHOULD ignore the first `address descriptor` that does
|
||||
* NOT match the types defined above.
|
||||
*/
|
||||
if (!fromwire_wireaddr(&cursor, &len, &wireaddr)) {
|
||||
if (!cursor)
|
||||
/* Parsing address failed */
|
||||
return tal_free(wireaddrs);
|
||||
/* Unknown type, stop there. */
|
||||
status_debug("read_addresses: unknown address type %u",
|
||||
cursor[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
tal_arr_expand(&wireaddrs, wireaddr);
|
||||
}
|
||||
return wireaddrs;
|
||||
}
|
||||
|
||||
bool routing_add_node_announcement(struct routing_state *rstate,
|
||||
const u8 *msg TAKES,
|
||||
u32 index,
|
||||
|
@ -2619,7 +2588,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann,
|
|||
return err;
|
||||
}
|
||||
|
||||
wireaddrs = read_addresses(tmpctx, addresses);
|
||||
wireaddrs = fromwire_wireaddr_array(tmpctx, addresses);
|
||||
if (!wireaddrs) {
|
||||
/* BOLT #7:
|
||||
*
|
||||
|
|
|
@ -511,9 +511,6 @@ static inline void local_enable_chan(struct routing_state *rstate,
|
|||
local_chan->local_disabled = false;
|
||||
}
|
||||
|
||||
/* Helper to convert on-wire addresses format to wireaddrs array */
|
||||
struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser);
|
||||
|
||||
/* Remove channel from store: announcement and any updates. */
|
||||
void remove_channel_from_store(struct routing_state *rstate,
|
||||
struct chan *chan);
|
||||
|
|
|
@ -39,9 +39,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
|
|||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr */
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr_array */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); }
|
||||
/* Generated stub for json_add_member */
|
||||
void json_add_member(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
|
|
|
@ -42,9 +42,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
|
|||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr */
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr_array */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); }
|
||||
/* Generated stub for gossip_store_add */
|
||||
u64 gossip_store_add(struct gossip_store *gs UNNEEDED, const u8 *gossip_msg UNNEEDED,
|
||||
u32 timestamp UNNEEDED, bool push UNNEEDED, const u8 *addendum UNNEEDED)
|
||||
|
|
|
@ -25,9 +25,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
|
|||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr */
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr_array */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); }
|
||||
/* Generated stub for json_add_member */
|
||||
void json_add_member(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
|
|
|
@ -25,9 +25,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
|
|||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr */
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr_array */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); }
|
||||
/* Generated stub for json_add_member */
|
||||
void json_add_member(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
|
|
|
@ -25,9 +25,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
|
|||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr */
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr_array */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); }
|
||||
/* Generated stub for json_add_member */
|
||||
void json_add_member(struct json_stream *js UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
|
|
|
@ -13,9 +13,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED,
|
|||
/* Generated stub for fmt_wireaddr_without_port */
|
||||
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr */
|
||||
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_wireaddr_array */
|
||||
struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); }
|
||||
/* Generated stub for gossip_store_add */
|
||||
u64 gossip_store_add(struct gossip_store *gs UNNEEDED, const u8 *gossip_msg UNNEEDED,
|
||||
u32 timestamp UNNEEDED, bool push UNNEEDED, const u8 *addendum UNNEEDED)
|
||||
|
|
Loading…
Add table
Reference in a new issue