|
@ -2573,6 +2573,45 @@ static void add_binding(struct wireaddr_internal **binding, |
|
|
(*binding)[n] = *addr; |
|
|
(*binding)[n] = *addr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int wireaddr_cmp_type(const struct wireaddr *a, |
|
|
|
|
|
const struct wireaddr *b, void *unused) |
|
|
|
|
|
{ |
|
|
|
|
|
return (int)a->type - (int)b->type; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void finalize_announcable(struct daemon *daemon) |
|
|
|
|
|
{ |
|
|
|
|
|
size_t n = tal_count(daemon->announcable); |
|
|
|
|
|
|
|
|
|
|
|
/* BOLT #7:
|
|
|
|
|
|
* |
|
|
|
|
|
* The origin node: |
|
|
|
|
|
*... |
|
|
|
|
|
* - MUST place non-zero typed address descriptors in ascending order. |
|
|
|
|
|
*... |
|
|
|
|
|
* - MUST NOT include more than one `address descriptor` of the same |
|
|
|
|
|
* type. |
|
|
|
|
|
*/ |
|
|
|
|
|
asort(daemon->announcable, n, wireaddr_cmp_type, NULL); |
|
|
|
|
|
for (size_t i = 1; i < n; i++) { |
|
|
|
|
|
/* Note we use > instead of !=: catches asort bugs too. */ |
|
|
|
|
|
if (daemon->announcable[i].type > daemon->announcable[i-1].type) |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
status_unusual("WARNING: Cannot announce address %s," |
|
|
|
|
|
" already announcing %s", |
|
|
|
|
|
type_to_string(tmpctx, struct wireaddr, |
|
|
|
|
|
&daemon->announcable[i]), |
|
|
|
|
|
type_to_string(tmpctx, struct wireaddr, |
|
|
|
|
|
&daemon->announcable[i-1])); |
|
|
|
|
|
memmove(daemon->announcable + i, |
|
|
|
|
|
daemon->announcable + i + 1, |
|
|
|
|
|
(n - i - 1) * sizeof(daemon->announcable[0])); |
|
|
|
|
|
tal_resize(&daemon->announcable, --n); |
|
|
|
|
|
--i; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* Initializes daemon->announcable array, returns addresses we bound to. */ |
|
|
/* Initializes daemon->announcable array, returns addresses we bound to. */ |
|
|
static struct wireaddr_internal *setup_listeners(const tal_t *ctx, |
|
|
static struct wireaddr_internal *setup_listeners(const tal_t *ctx, |
|
|
struct daemon *daemon) |
|
|
struct daemon *daemon) |
|
@ -2584,20 +2623,30 @@ static struct wireaddr_internal *setup_listeners(const tal_t *ctx, |
|
|
binding = tal_arr(ctx, struct wireaddr_internal, 0); |
|
|
binding = tal_arr(ctx, struct wireaddr_internal, 0); |
|
|
daemon->announcable = tal_arr(daemon, struct wireaddr, 0); |
|
|
daemon->announcable = tal_arr(daemon, struct wireaddr, 0); |
|
|
|
|
|
|
|
|
|
|
|
/* Add addresses we've explicitly been told to *first*: implicit
|
|
|
|
|
|
* addresses will be discarded then if we have multiple. */ |
|
|
for (size_t i = 0; i < tal_count(daemon->proposed_wireaddr); i++) { |
|
|
for (size_t i = 0; i < tal_count(daemon->proposed_wireaddr); i++) { |
|
|
struct wireaddr_internal wa = daemon->proposed_wireaddr[i]; |
|
|
struct wireaddr_internal wa = daemon->proposed_wireaddr[i]; |
|
|
bool announce = (daemon->proposed_listen_announce[i] |
|
|
|
|
|
& ADDR_ANNOUNCE); |
|
|
|
|
|
|
|
|
|
|
|
if (!(daemon->proposed_listen_announce[i] & ADDR_LISTEN)) { |
|
|
if (daemon->proposed_listen_announce[i] & ADDR_LISTEN) |
|
|
assert(announce); |
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
assert(daemon->proposed_listen_announce[i] & ADDR_ANNOUNCE); |
|
|
/* You can only announce wiretypes! */ |
|
|
/* You can only announce wiretypes! */ |
|
|
assert(daemon->proposed_wireaddr[i].itype |
|
|
assert(daemon->proposed_wireaddr[i].itype |
|
|
== ADDR_INTERNAL_WIREADDR); |
|
|
== ADDR_INTERNAL_WIREADDR); |
|
|
add_announcable(daemon, &wa.u.wireaddr); |
|
|
add_announcable(daemon, &wa.u.wireaddr); |
|
|
continue; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Now look for listening addresses. */ |
|
|
|
|
|
for (size_t i = 0; i < tal_count(daemon->proposed_wireaddr); i++) { |
|
|
|
|
|
struct wireaddr_internal wa = daemon->proposed_wireaddr[i]; |
|
|
|
|
|
bool announce = (daemon->proposed_listen_announce[i] |
|
|
|
|
|
& ADDR_ANNOUNCE); |
|
|
|
|
|
|
|
|
|
|
|
if (!(daemon->proposed_listen_announce[i] & ADDR_LISTEN)) |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
switch (wa.itype) { |
|
|
switch (wa.itype) { |
|
|
case ADDR_INTERNAL_SOCKNAME: |
|
|
case ADDR_INTERNAL_SOCKNAME: |
|
|
addrun.sun_family = AF_UNIX; |
|
|
addrun.sun_family = AF_UNIX; |
|
@ -2679,6 +2728,9 @@ static struct wireaddr_internal *setup_listeners(const tal_t *ctx, |
|
|
daemon->tor_password, |
|
|
daemon->tor_password, |
|
|
binding)); |
|
|
binding)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
finalize_announcable(daemon); |
|
|
|
|
|
|
|
|
return binding; |
|
|
return binding; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|