From 885a6f50aecf0debebdd62397caf539eb5910a2e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 4 Mar 2022 16:40:57 +1030 Subject: [PATCH] connectd: make sure we announce websocket addr which succeeded. By accessing `addr` after the loop, it's possible that it's one which failed, in complex scenarios. Also gives us a chance to warn if they specify a websocket but don't actually end up advertizing it (you *must* advertize a normal addr as well). Signed-off-by: Rusty Russell --- connectd/connectd.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index 38d98c28f..703660913 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -1419,20 +1419,34 @@ setup_listeners(const tal_t *ctx, if (!lfd) continue; - announced_some = true; + if (!announced_some) { + /* BOLT-websocket #7: + * - MUST NOT add a `type 6` address unless + * there is also at least one address of + * different type. + */ + if (tal_count(*announcable) != 0) { + wireaddr_from_websocket(&addr.u.wireaddr, + daemon->websocket_port); + add_announcable(announcable, + &addr.u.wireaddr); + } else { + status_unusual("Bound to websocket %s," + " but we cannot announce" + " the websocket as we don't" + " announce anything else!", + type_to_string(tmpctx, + struct wireaddr_internal, + &addr)); + } + announced_some = true; + } + tal_arr_expand(&listen_fds, tal_steal(listen_fds, lfd)); } - /* We add the websocket port to the announcement if we made one - * *and* we have other announced addresses. */ - /* BOLT-websocket #7: - * - MUST NOT add a `type 6` address unless there is also at - * least one address of different type. - */ - if (announced_some && tal_count(*announcable) != 0) { - wireaddr_from_websocket(&addr.u.wireaddr, daemon->websocket_port); - add_announcable(announcable, &addr.u.wireaddr); - } else + /* If none of those was possible, it's a configuration error? */ + if (tal_count(listen_fds) == num_nonws_listens) return NULL; }