mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
routing: Reading multiple addresses from node_announcements
This commit is contained in:
committed by
Rusty Russell
parent
ed9668339d
commit
26892e79bb
@@ -79,6 +79,7 @@ struct node *new_node(struct routing_state *rstate,
|
|||||||
n->hostname = NULL;
|
n->hostname = NULL;
|
||||||
n->node_announcement = NULL;
|
n->node_announcement = NULL;
|
||||||
n->last_timestamp = 0;
|
n->last_timestamp = 0;
|
||||||
|
n->addresses = tal_arr(n, struct ipaddr, 0);
|
||||||
node_map_add(rstate->nodes, n);
|
node_map_add(rstate->nodes, n);
|
||||||
tal_add_destructor(n, destroy_node);
|
tal_add_destructor(n, destroy_node);
|
||||||
|
|
||||||
@@ -836,6 +837,25 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update, size_
|
|||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct ipaddr *read_addresses(const tal_t *ctx, u8 *ser)
|
||||||
|
{
|
||||||
|
const u8 *cursor = ser;
|
||||||
|
size_t max = tal_len(ser);
|
||||||
|
struct ipaddr *ipaddrs = tal_arr(ctx, struct ipaddr, 0);
|
||||||
|
int numaddrs = 0;
|
||||||
|
while (cursor < ser + max) {
|
||||||
|
numaddrs += 1;
|
||||||
|
tal_resize(&ipaddrs, numaddrs);
|
||||||
|
fromwire_ipaddr(&cursor, &max, &ipaddrs[numaddrs-1]);
|
||||||
|
if (cursor == NULL) {
|
||||||
|
/* Parsing address failed */
|
||||||
|
tal_free(ipaddrs);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ipaddrs;
|
||||||
|
}
|
||||||
|
|
||||||
void handle_node_announcement(
|
void handle_node_announcement(
|
||||||
struct routing_state *rstate, const u8 *node_ann, size_t len)
|
struct routing_state *rstate, const u8 *node_ann, size_t len)
|
||||||
{
|
{
|
||||||
@@ -849,6 +869,7 @@ void handle_node_announcement(
|
|||||||
u8 alias[32];
|
u8 alias[32];
|
||||||
u8 *features, *addresses;
|
u8 *features, *addresses;
|
||||||
const tal_t *tmpctx = tal_tmpctx(rstate);
|
const tal_t *tmpctx = tal_tmpctx(rstate);
|
||||||
|
struct ipaddr *ipaddrs;
|
||||||
|
|
||||||
serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0);
|
serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0);
|
||||||
if (!fromwire_node_announcement(tmpctx, serialized, NULL,
|
if (!fromwire_node_announcement(tmpctx, serialized, NULL,
|
||||||
@@ -885,13 +906,24 @@ void handle_node_announcement(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipaddrs = read_addresses(tmpctx, addresses);
|
||||||
|
if (!ipaddrs) {
|
||||||
|
log_debug(rstate->base_log, "Unable to parse addresses.");
|
||||||
|
tal_free(serialized);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tal_free(node->addresses);
|
||||||
|
node->addresses = tal_steal(node, ipaddrs);
|
||||||
|
|
||||||
node->last_timestamp = timestamp;
|
node->last_timestamp = timestamp;
|
||||||
node->hostname = tal_free(node->hostname);
|
node->hostname = tal_free(node->hostname);
|
||||||
|
|
||||||
if (!read_ip(node, addresses, &node->hostname, &node->port)) {
|
if (!read_ip(node, addresses, &node->hostname, &node->port)) {
|
||||||
/* FIXME: SHOULD fail connection here. */
|
/* FIXME: SHOULD fail connection here. */
|
||||||
tal_free(serialized);
|
tal_free(serialized);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(node->rgb_color, rgb_color, 3);
|
memcpy(node->rgb_color, rgb_color, 3);
|
||||||
|
|
||||||
u8 *tag = tal_arr(tmpctx, u8, 0);
|
u8 *tag = tal_arr(tmpctx, u8, 0);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ struct node {
|
|||||||
struct pubkey id;
|
struct pubkey id;
|
||||||
|
|
||||||
/* IP/Hostname and port of this node (may be NULL) */
|
/* IP/Hostname and port of this node (may be NULL) */
|
||||||
|
struct ipaddr *addresses;
|
||||||
char *hostname;
|
char *hostname;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
|
|||||||
@@ -1259,12 +1259,15 @@ static u8 *create_node_announcement(const tal_t *ctx, struct lightningd *ld,
|
|||||||
u8 rgb[3] = {0x77, 0x88, 0x99};
|
u8 rgb[3] = {0x77, 0x88, 0x99};
|
||||||
u8 alias[32];
|
u8 alias[32];
|
||||||
u8 *features = NULL;
|
u8 *features = NULL;
|
||||||
u8 *addresses = NULL;
|
u8 *addresses = tal_arr(ctx, u8, 0);
|
||||||
u8 *announcement;
|
u8 *announcement;
|
||||||
if (!sig) {
|
if (!sig) {
|
||||||
sig = tal(ctx, secp256k1_ecdsa_signature);
|
sig = tal(ctx, secp256k1_ecdsa_signature);
|
||||||
memset(sig, 0, sizeof(*sig));
|
memset(sig, 0, sizeof(*sig));
|
||||||
}
|
}
|
||||||
|
if (ld->dstate.config.ipaddr.type != ADDR_TYPE_PADDING) {
|
||||||
|
towire_ipaddr(&addresses, &ld->dstate.config.ipaddr);
|
||||||
|
}
|
||||||
memset(alias, 0, sizeof(alias));
|
memset(alias, 0, sizeof(alias));
|
||||||
announcement =
|
announcement =
|
||||||
towire_node_announcement(ctx, sig, timestamp, &ld->dstate.id, rgb,
|
towire_node_announcement(ctx, sig, timestamp, &ld->dstate.id, rgb,
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ void fromwire_ipaddr(const u8 **cursor, size_t *max, struct ipaddr *addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
addr->type = **cursor;
|
addr->type = **cursor;
|
||||||
|
*cursor += 1;
|
||||||
switch (addr->type) {
|
switch (addr->type) {
|
||||||
case 1:
|
case 1:
|
||||||
addr->addrlen = 4;
|
addr->addrlen = 4;
|
||||||
|
|||||||
Reference in New Issue
Block a user