mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
wireaddr: clean up option parsing, support dns:
prefix directly.
This is a major cleanup to how we parse addresses. 1. parse_wireaddr now supports the "dns:" prefix to support dns records (type 5). 2. We are less reliant on separate_address_and_port() which gets confused by that colon. 3. We explicitly test every possible address type we can get back from parsing, and handle them appropriately. We update the documentation to use the clearer HOSTNAME vs DNS prefixes now we also have `dns:` as a prefix. Changelog-Added: Config: `bind` can now take `dns:` prefix to advertize DNS records. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3f35d48fe4
commit
6d0b46c9b1
3 changed files with 173 additions and 144 deletions
|
@ -506,28 +506,52 @@ const char *parse_wireaddr(const tal_t *ctx,
|
||||||
char *ip;
|
char *ip;
|
||||||
const char *err_msg;
|
const char *err_msg;
|
||||||
struct wireaddr *addresses;
|
struct wireaddr *addresses;
|
||||||
|
bool is_dns_waddr;
|
||||||
|
|
||||||
port = defport;
|
port = defport;
|
||||||
|
|
||||||
|
if (strstarts(arg, "dns:")) {
|
||||||
|
is_dns_waddr = true;
|
||||||
|
arg += 4;
|
||||||
|
} else
|
||||||
|
is_dns_waddr = false;
|
||||||
|
|
||||||
if (!separate_address_and_port(tmpctx, arg, &ip, &port))
|
if (!separate_address_and_port(tmpctx, arg, &ip, &port))
|
||||||
return tal_strdup(ctx, "Error parsing hostname");
|
return tal_strdup(ctx, "Error parsing hostname");
|
||||||
|
|
||||||
/* We resolved these even without DNS */
|
if (!is_dns_waddr) {
|
||||||
if (streq(ip, "localhost"))
|
/* We resolved these even without DNS */
|
||||||
ip = "127.0.0.1";
|
if (streq(ip, "localhost"))
|
||||||
else if (streq(ip, "ip6-localhost"))
|
ip = "127.0.0.1";
|
||||||
ip = "::1";
|
else if (streq(ip, "ip6-localhost"))
|
||||||
|
ip = "::1";
|
||||||
|
}
|
||||||
|
|
||||||
memset(&addr->addr, 0, sizeof(addr->addr));
|
memset(&addr->addr, 0, sizeof(addr->addr));
|
||||||
|
|
||||||
if (inet_pton(AF_INET, ip, &v4) == 1) {
|
if (inet_pton(AF_INET, ip, &v4) == 1) {
|
||||||
|
if (is_dns_waddr)
|
||||||
|
return tal_strdup(ctx, "dns: must be followed by a name");
|
||||||
wireaddr_from_ipv4(addr, &v4, port);
|
wireaddr_from_ipv4(addr, &v4, port);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (inet_pton(AF_INET6, ip, &v6) == 1) {
|
} else if (inet_pton(AF_INET6, ip, &v6) == 1) {
|
||||||
|
if (is_dns_waddr)
|
||||||
|
return tal_strdup(ctx, "dns: must be followed by a name");
|
||||||
wireaddr_from_ipv6(addr, &v6, port);
|
wireaddr_from_ipv6(addr, &v6, port);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_dns_waddr) {
|
||||||
|
addr->type = ADDR_TYPE_DNS;
|
||||||
|
if (strlen(ip) > DNS_ADDRLEN)
|
||||||
|
return "DNS address too long";
|
||||||
|
|
||||||
|
addr->addrlen = strlen(ip);
|
||||||
|
memcpy(addr->addr, ip, addr->addrlen);
|
||||||
|
addr->port = port;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Resolve with getaddrinfo */
|
/* Resolve with getaddrinfo */
|
||||||
addresses = wireaddr_from_hostname(NULL, ip, port, no_dns, NULL, &err_msg);
|
addresses = wireaddr_from_hostname(NULL, ip, port, no_dns, NULL, &err_msg);
|
||||||
if (!addresses)
|
if (!addresses)
|
||||||
|
@ -577,7 +601,7 @@ const char *parse_wireaddr_internal(const tal_t *ctx,
|
||||||
struct wireaddr_internal *addr)
|
struct wireaddr_internal *addr)
|
||||||
{
|
{
|
||||||
u16 splitport;
|
u16 splitport;
|
||||||
char *ip = NULL;
|
char *ip;
|
||||||
char *service_addr;
|
char *service_addr;
|
||||||
const char *err;
|
const char *err;
|
||||||
bool needed_dns;
|
bool needed_dns;
|
||||||
|
@ -663,13 +687,14 @@ const char *parse_wireaddr_internal(const tal_t *ctx,
|
||||||
&addr->u.torservice.address);
|
&addr->u.torservice.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This can fail, but that may be OK! */
|
||||||
splitport = default_port;
|
splitport = default_port;
|
||||||
if (!separate_address_and_port(tmpctx, arg, &ip, &splitport))
|
if (!separate_address_and_port(tmpctx, arg, &ip, &splitport))
|
||||||
return tal_fmt(ctx, "Error parsing hostname %s %s", (char *)arg, ip);
|
ip = NULL;
|
||||||
|
|
||||||
/* An empty string means IPv4 and IPv6 (which under Linux by default
|
/* An empty string means IPv4 and IPv6 (which under Linux by default
|
||||||
* means just IPv6, and IPv4 gets autobound). */
|
* means just IPv6, and IPv4 gets autobound). */
|
||||||
if (streq(ip, "")) {
|
if (ip && streq(ip, "")) {
|
||||||
addr->itype = ADDR_INTERNAL_ALLPROTO;
|
addr->itype = ADDR_INTERNAL_ALLPROTO;
|
||||||
addr->u.port = splitport;
|
addr->u.port = splitport;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -688,6 +713,10 @@ const char *parse_wireaddr_internal(const tal_t *ctx,
|
||||||
if (!needed_dns)
|
if (!needed_dns)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
/* Invalid port, like foo:xxx or foo:0 */
|
||||||
|
if (!ip)
|
||||||
|
return "Malformed port";
|
||||||
|
|
||||||
/* Keep unresolved. */
|
/* Keep unresolved. */
|
||||||
tal_free(err);
|
tal_free(err);
|
||||||
if (!wireaddr_from_unresolved(addr, ip, splitport))
|
if (!wireaddr_from_unresolved(addr, ip, splitport))
|
||||||
|
|
|
@ -497,7 +497,7 @@ precisely control where to bind and what to announce with the
|
||||||
*bind-addr* and *announce-addr* options. These will **disable** the
|
*bind-addr* and *announce-addr* options. These will **disable** the
|
||||||
*autolisten* logic, so you must specifiy exactly what you want!
|
*autolisten* logic, so you must specifiy exactly what you want!
|
||||||
|
|
||||||
* **addr**=*\[IPADDRESS\[:PORT\]\]|autotor:TORIPADDRESS\[:SERVICEPORT\]\[/torport=TORPORT\]|statictor:TORIPADDRESS\[:SERVICEPORT\]\[/torport=TORPORT\]\[/torblob=\[blob\]\]|DNS\[:PORT\]*
|
* **addr**=*\[IPADDRESS\[:PORT\]\]|autotor:TORIPADDRESS\[:SERVICEPORT\]\[/torport=TORPORT\]|statictor:TORIPADDRESS\[:SERVICEPORT\]\[/torport=TORPORT\]\[/torblob=\[blob\]\]|HOSTNAME\[:PORT\]*
|
||||||
|
|
||||||
Set an IP address (v4 or v6) or automatic Tor address to listen on and
|
Set an IP address (v4 or v6) or automatic Tor address to listen on and
|
||||||
(maybe) announce as our node address.
|
(maybe) announce as our node address.
|
||||||
|
@ -534,12 +534,12 @@ defined by you and possibly different from your local node port assignment.
|
||||||
|
|
||||||
This option can be used multiple times to add more addresses, and
|
This option can be used multiple times to add more addresses, and
|
||||||
its use disables autolisten. If necessary, and 'always-use-proxy'
|
its use disables autolisten. If necessary, and 'always-use-proxy'
|
||||||
is not specified, a DNS lookup may be done to resolve 'DNS' or 'TORIPADDRESS'.
|
is not specified, a DNS lookup may be done to resolve `HOSTNAME` or `TORIPADDRESS'`.
|
||||||
|
|
||||||
If a 'DNS' hostname was given that resolves to a local interface, the daemon
|
If `HOSTNAME` was given that resolves to a local interface, the daemon
|
||||||
will bind to that interface: if **announce-addr-dns** is true then it will also announce that as type 'DNS' (rather than announcing the IP address).
|
will bind to that interface.
|
||||||
|
|
||||||
* **bind-addr**=*\[IPADDRESS\[:PORT\]\]|SOCKETPATH|DNS\[:PORT\]|DNS\[:PORT\]*
|
* **bind-addr**=*\[IPADDRESS\[:PORT\]\]|SOCKETPATH|HOSTNAME\[:PORT\]*
|
||||||
|
|
||||||
Set an IP address or UNIX domain socket to listen to, but do not
|
Set an IP address or UNIX domain socket to listen to, but do not
|
||||||
announce. A UNIX domain socket is distinguished from an IP address by
|
announce. A UNIX domain socket is distinguished from an IP address by
|
||||||
|
@ -554,10 +554,10 @@ not specified, 9735 is used.
|
||||||
its use disables autolisten. If necessary, and 'always-use-proxy'
|
its use disables autolisten. If necessary, and 'always-use-proxy'
|
||||||
is not specified, a DNS lookup may be done to resolve 'IPADDRESS'.
|
is not specified, a DNS lookup may be done to resolve 'IPADDRESS'.
|
||||||
|
|
||||||
If a 'DNS' hostname was given and 'always-use-proxy' is not specified,
|
If a HOSTNAME was given and `always-use-proxy` is not specified,
|
||||||
a lookup may be done to resolve it and bind to a local interface (if found).
|
a DNS lookup may be done to resolve it and bind to a local interface (if found).
|
||||||
|
|
||||||
* **announce-addr**=*IPADDRESS\[:PORT\]|TORADDRESS.onion\[:PORT\]|DNS\[:PORT\]*
|
* **announce-addr**=*IPADDRESS\[:PORT\]|TORADDRESS.onion\[:PORT\]|dns:HOSTNAME\[:PORT\]*
|
||||||
|
|
||||||
Set an IP (v4 or v6) address or Tor address to announce; a Tor address
|
Set an IP (v4 or v6) address or Tor address to announce; a Tor address
|
||||||
is distinguished by ending in *.onion*. *PORT* defaults to 9735.
|
is distinguished by ending in *.onion*. *PORT* defaults to 9735.
|
||||||
|
@ -569,12 +569,11 @@ announced addresses are public (e.g. not localhost).
|
||||||
This option can be used multiple times to add more addresses, and
|
This option can be used multiple times to add more addresses, and
|
||||||
its use disables autolisten.
|
its use disables autolisten.
|
||||||
|
|
||||||
Since v22.11 'DNS' hostnames can be used for announcement: see **announce-addr-dns**.
|
Since v23.058, the `dns:` prefix can be used to indicate that this hostname and port should be announced as a DNS hostname entry. Please note that most mainnet nodes do not yet use, read or propagate this information correctly.
|
||||||
|
|
||||||
* **announce-addr-dns**=*BOOL*
|
* **announce-addr-dns**=*BOOL*
|
||||||
|
|
||||||
Set to *true* (default is *false), this so that names given as arguments to **addr** and **announce-addr** are published in node announcement messages as names, rather than IP addresses. Please note that most mainnet nodes do not yet use, read or propagate this information correctly.
|
When set to *true* (default is *false*), prefixes all `HOSTNAME` in **announce-addr** with `dns:`.
|
||||||
|
|
||||||
|
|
||||||
* **offline**
|
* **offline**
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,6 @@ static void opt_log_stderr_exitcode(const char *fmt, ...)
|
||||||
exit(opt_exitcode);
|
exit(opt_exitcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Declare opt_add_addr here, because we we call opt_add_addr
|
|
||||||
* and opt_announce_addr vice versa
|
|
||||||
*/
|
|
||||||
static char *opt_add_addr(const char *arg, struct lightningd *ld);
|
|
||||||
|
|
||||||
/* FIXME: Put into ccan/time. */
|
/* FIXME: Put into ccan/time. */
|
||||||
#define TIME_FROM_SEC(sec) { { .tv_nsec = 0, .tv_sec = sec } }
|
#define TIME_FROM_SEC(sec) { { .tv_nsec = 0, .tv_sec = sec } }
|
||||||
#define TIME_FROM_MSEC(msec) \
|
#define TIME_FROM_MSEC(msec) \
|
||||||
|
@ -246,135 +241,160 @@ static size_t num_announced_types(enum wire_addr_type type, struct lightningd *l
|
||||||
|
|
||||||
static char *opt_add_addr_withtype(const char *arg,
|
static char *opt_add_addr_withtype(const char *arg,
|
||||||
struct lightningd *ld,
|
struct lightningd *ld,
|
||||||
enum addr_listen_announce ala,
|
enum addr_listen_announce ala)
|
||||||
bool wildcard_ok)
|
|
||||||
{
|
{
|
||||||
char const *err_msg;
|
char const *err_msg;
|
||||||
struct wireaddr_internal wi;
|
struct wireaddr_internal wi;
|
||||||
bool dns_ok;
|
bool dns_lookup_ok;
|
||||||
char *address;
|
char *address;
|
||||||
u16 port;
|
u16 port;
|
||||||
|
|
||||||
assert(arg != NULL);
|
assert(arg != NULL);
|
||||||
dns_ok = !ld->always_use_proxy && ld->config.use_dns;
|
dns_lookup_ok = !ld->always_use_proxy && ld->config.use_dns;
|
||||||
|
|
||||||
/* Will be overridden in next call, if it has a port */
|
/* Deprecated announce-addr-dns: autodetect DNS addresses. */
|
||||||
port = 0;
|
if (ld->announce_dns && (ala == ADDR_ANNOUNCE)
|
||||||
if (!separate_address_and_port(tmpctx, arg, &address, &port))
|
&& separate_address_and_port(tmpctx, arg, &address, &port)
|
||||||
return tal_fmt(NULL, "Unable to parse address:port '%s'", arg);
|
&& is_dnsaddr(address)) {
|
||||||
|
log_unusual(ld->log, "Adding dns prefix to %s!", arg);
|
||||||
|
arg = tal_fmt(tmpctx, "dns:%s", arg);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_ipaddr(address)
|
err_msg = parse_wireaddr_internal(tmpctx, arg, ld->portnum,
|
||||||
|| is_toraddr(address)
|
dns_lookup_ok, &wi);
|
||||||
|| is_wildcardaddr(address)
|
if (err_msg)
|
||||||
|| (is_dnsaddr(address) && !ld->announce_dns)
|
return tal_fmt(NULL, "Unable to parse address '%s': %s", arg, err_msg);
|
||||||
|| ala != ADDR_ANNOUNCE) {
|
|
||||||
err_msg = parse_wireaddr_internal(tmpctx, arg, ld->portnum,
|
/* Check they didn't specify some weird type! */
|
||||||
dns_ok, &wi);
|
switch (wi.itype) {
|
||||||
if (err_msg) {
|
case ADDR_INTERNAL_WIREADDR:
|
||||||
return tal_fmt(NULL, "Unable to parse address '%s': %s", arg, err_msg);
|
switch (wi.u.wireaddr.type) {
|
||||||
}
|
case ADDR_TYPE_IPV4:
|
||||||
/* Check they didn't specify some weird type! */
|
case ADDR_TYPE_IPV6:
|
||||||
switch (wi.itype) {
|
/* These can be either bind or announce */
|
||||||
case ADDR_INTERNAL_SOCKNAME:
|
|
||||||
case ADDR_INTERNAL_WIREADDR:
|
|
||||||
case ADDR_INTERNAL_AUTOTOR:
|
|
||||||
case ADDR_INTERNAL_STATICTOR:
|
|
||||||
break;
|
break;
|
||||||
case ADDR_INTERNAL_ALLPROTO:
|
case ADDR_TYPE_TOR_V2_REMOVED:
|
||||||
if (!wildcard_ok)
|
/* Can't happen any more */
|
||||||
|
abort();
|
||||||
|
case ADDR_TYPE_TOR_V3:
|
||||||
|
/* I'm not sure why we allow this abuse, but we fix it up. */
|
||||||
|
switch (ala) {
|
||||||
|
case ADDR_LISTEN:
|
||||||
|
log_unusual(ld->log,
|
||||||
|
"You used `--bind-addr=%s` option with an .onion address,"
|
||||||
|
" You are lucky in this node live some wizards and"
|
||||||
|
" fairies, we have done this for you and don't announce, Be as hidden as wished",
|
||||||
|
arg);
|
||||||
|
/* And we ignore it */
|
||||||
|
return NULL;
|
||||||
|
case ADDR_LISTEN_AND_ANNOUNCE:
|
||||||
|
log_unusual(ld->log,
|
||||||
|
"You used `--addr=%s` option with an .onion address,"
|
||||||
|
" You are lucky in this node live some wizards and"
|
||||||
|
" fairies, we have done this for you and don't announce, Be as hidden as wished",
|
||||||
|
arg);
|
||||||
|
ala = ADDR_LISTEN;
|
||||||
|
break;
|
||||||
|
case ADDR_ANNOUNCE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ADDR_TYPE_DNS:
|
||||||
|
/* Can only announce this */
|
||||||
|
switch (ala) {
|
||||||
|
case ADDR_ANNOUNCE:
|
||||||
|
break;
|
||||||
|
case ADDR_LISTEN:
|
||||||
|
return tal_fmt(NULL,
|
||||||
|
"Cannot use dns: prefix with --bind-addr, use --bind-addr=%s", arg + strlen("dns:"));
|
||||||
|
case ADDR_LISTEN_AND_ANNOUNCE:
|
||||||
|
return tal_fmt(NULL,
|
||||||
|
"Cannot use dns: prefix with --addr, use --bind-addr=%s and --addr=%s",
|
||||||
|
arg + strlen("dns:"),
|
||||||
|
arg);
|
||||||
|
}
|
||||||
|
/* BOLT-hostnames #7:
|
||||||
|
* The origin node:
|
||||||
|
* ...
|
||||||
|
* - MUST NOT announce more than one `type 5` DNS hostname.
|
||||||
|
*/
|
||||||
|
if (num_announced_types(ADDR_TYPE_DNS, ld) > 0)
|
||||||
|
return tal_fmt(NULL, "Only one DNS can be announced");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ADDR_INTERNAL_SOCKNAME:
|
||||||
|
/* We turn --addr into --bind-addr */
|
||||||
|
switch (ala) {
|
||||||
|
case ADDR_ANNOUNCE:
|
||||||
|
return tal_fmt(NULL,
|
||||||
|
"Cannot announce sockets, try --bind-addr=%s", arg);
|
||||||
|
case ADDR_LISTEN_AND_ANNOUNCE:
|
||||||
|
ala = ADDR_LISTEN;
|
||||||
|
/* Fall thru */
|
||||||
|
case ADDR_LISTEN:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ADDR_INTERNAL_AUTOTOR:
|
||||||
|
case ADDR_INTERNAL_STATICTOR:
|
||||||
|
/* We turn --announce-addr into --addr */
|
||||||
|
switch (ala) {
|
||||||
|
case ADDR_ANNOUNCE:
|
||||||
|
ala = ADDR_LISTEN_AND_ANNOUNCE;
|
||||||
|
break;
|
||||||
|
case ADDR_LISTEN_AND_ANNOUNCE:
|
||||||
|
case ADDR_LISTEN:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ADDR_INTERNAL_ALLPROTO:
|
||||||
|
/* You can only bind to wildcard, and optionally announce */
|
||||||
|
switch (ala) {
|
||||||
|
case ADDR_ANNOUNCE:
|
||||||
return tal_fmt(NULL, "Cannot use wildcard address '%s'", arg);
|
return tal_fmt(NULL, "Cannot use wildcard address '%s'", arg);
|
||||||
break;
|
case ADDR_LISTEN_AND_ANNOUNCE:
|
||||||
case ADDR_INTERNAL_FORPROXY:
|
case ADDR_LISTEN:
|
||||||
return tal_fmt(NULL, "Cannot resolve address '%s' (not using DNS!)", arg);
|
break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
/* Sanity check for exact duplicates. */
|
case ADDR_INTERNAL_FORPROXY:
|
||||||
for (size_t i = 0; i < tal_count(ld->proposed_wireaddr); i++) {
|
/* You can't use these addresses here at all: this means we've
|
||||||
/* Only compare announce vs announce and bind vs bind */
|
* suppressed DNS and given a string-style name */
|
||||||
if ((ld->proposed_listen_announce[i] & ala) == 0)
|
return tal_fmt(NULL, "Cannot resolve address '%s' (not using DNS!)", arg);
|
||||||
continue;
|
|
||||||
|
|
||||||
if (wireaddr_internal_eq(&ld->proposed_wireaddr[i], &wi))
|
|
||||||
return tal_fmt(NULL, "Duplicate %s address %s",
|
|
||||||
ala & ADDR_ANNOUNCE ? "announce" : "listen",
|
|
||||||
type_to_string(tmpctx, struct wireaddr_internal, &wi));
|
|
||||||
}
|
|
||||||
|
|
||||||
tal_arr_expand(&ld->proposed_listen_announce, ala);
|
|
||||||
tal_arr_expand(&ld->proposed_wireaddr, wi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add ADDR_TYPE_DNS to announce DNS hostnames */
|
/* Sanity check for exact duplicates. */
|
||||||
if (is_dnsaddr(address) && ld->announce_dns && (ala & ADDR_ANNOUNCE)) {
|
for (size_t i = 0; i < tal_count(ld->proposed_wireaddr); i++) {
|
||||||
/* BOLT-hostnames #7:
|
/* Only compare announce vs announce and bind vs bind */
|
||||||
* The origin node:
|
if ((ld->proposed_listen_announce[i] & ala) == 0)
|
||||||
* ...
|
continue;
|
||||||
* - MUST NOT announce more than one `type 5` DNS hostname.
|
|
||||||
*/
|
|
||||||
if (num_announced_types(ADDR_TYPE_DNS, ld) > 0) {
|
|
||||||
return tal_fmt(NULL, "Only one DNS can be announced");
|
|
||||||
}
|
|
||||||
memset(&wi, 0, sizeof(wi));
|
|
||||||
wi.itype = ADDR_INTERNAL_WIREADDR;
|
|
||||||
wi.u.wireaddr.type = ADDR_TYPE_DNS;
|
|
||||||
wi.u.wireaddr.addrlen = strlen(address);
|
|
||||||
strncpy((char * restrict)&wi.u.wireaddr.addr,
|
|
||||||
address, sizeof(wi.u.wireaddr.addr) - 1);
|
|
||||||
if (port == 0)
|
|
||||||
wi.u.wireaddr.port = ld->portnum;
|
|
||||||
else
|
|
||||||
wi.u.wireaddr.port = port;
|
|
||||||
|
|
||||||
tal_arr_expand(&ld->proposed_listen_announce, ADDR_ANNOUNCE);
|
if (wireaddr_internal_eq(&ld->proposed_wireaddr[i], &wi))
|
||||||
tal_arr_expand(&ld->proposed_wireaddr, wi);
|
return tal_fmt(NULL, "Duplicate %s address %s",
|
||||||
|
ala & ADDR_ANNOUNCE ? "announce" : "listen",
|
||||||
|
type_to_string(tmpctx, struct wireaddr_internal, &wi));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tal_arr_expand(&ld->proposed_listen_announce, ala);
|
||||||
|
tal_arr_expand(&ld->proposed_wireaddr, wi);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *opt_add_announce_addr(const char *arg, struct lightningd *ld)
|
static char *opt_add_announce_addr(const char *arg, struct lightningd *ld)
|
||||||
{
|
{
|
||||||
size_t n = tal_count(ld->proposed_wireaddr);
|
return opt_add_addr_withtype(arg, ld, ADDR_ANNOUNCE);
|
||||||
char *err;
|
|
||||||
|
|
||||||
/* Check for autotor and reroute the call to --addr */
|
|
||||||
if (strstarts(arg, "autotor:"))
|
|
||||||
return opt_add_addr(arg, ld);
|
|
||||||
|
|
||||||
/* Check for statictor and reroute the call to --addr */
|
|
||||||
if (strstarts(arg, "statictor:"))
|
|
||||||
return opt_add_addr(arg, ld);
|
|
||||||
|
|
||||||
err = opt_add_addr_withtype(arg, ld, ADDR_ANNOUNCE, false);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
/* Can't announce anything that's not a normal wireaddr. */
|
|
||||||
if (ld->proposed_wireaddr[n].itype != ADDR_INTERNAL_WIREADDR)
|
|
||||||
return tal_fmt(NULL, "address '%s' is not announceable",
|
|
||||||
arg);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *opt_add_addr(const char *arg, struct lightningd *ld)
|
static char *opt_add_addr(const char *arg, struct lightningd *ld)
|
||||||
{
|
{
|
||||||
struct wireaddr_internal addr;
|
return opt_add_addr_withtype(arg, ld, ADDR_LISTEN_AND_ANNOUNCE);
|
||||||
|
}
|
||||||
|
|
||||||
/* handle in case you used the addr option with an .onion */
|
static char *opt_add_bind_addr(const char *arg, struct lightningd *ld)
|
||||||
if (parse_wireaddr_internal(tmpctx, arg, 0, false, &addr) == NULL) {
|
{
|
||||||
if (addr.itype == ADDR_INTERNAL_WIREADDR &&
|
return opt_add_addr_withtype(arg, ld, ADDR_LISTEN);
|
||||||
addr.u.wireaddr.type == ADDR_TYPE_TOR_V3) {
|
|
||||||
log_unusual(ld->log, "You used `--addr=%s` option with an .onion address, please use"
|
|
||||||
" `--announce-addr` ! You are lucky in this node live some wizards and"
|
|
||||||
" fairies, we have done this for you and announce, Be as hidden as wished",
|
|
||||||
arg);
|
|
||||||
return opt_add_announce_addr(arg, ld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* the intended call */
|
|
||||||
return opt_add_addr_withtype(arg, ld, ADDR_LISTEN_AND_ANNOUNCE, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *opt_subdaemon(const char *arg, struct lightningd *ld)
|
static char *opt_subdaemon(const char *arg, struct lightningd *ld)
|
||||||
|
@ -404,25 +424,6 @@ static char *opt_subdaemon(const char *arg, struct lightningd *ld)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *opt_add_bind_addr(const char *arg, struct lightningd *ld)
|
|
||||||
{
|
|
||||||
struct wireaddr_internal addr;
|
|
||||||
|
|
||||||
/* handle in case you used the bind option with an .onion */
|
|
||||||
if (parse_wireaddr_internal(tmpctx, arg, 0, false, &addr) == NULL) {
|
|
||||||
if (addr.itype == ADDR_INTERNAL_WIREADDR &&
|
|
||||||
addr.u.wireaddr.type == ADDR_TYPE_TOR_V3) {
|
|
||||||
log_unusual(ld->log, "You used `--bind-addr=%s` option with an .onion address,"
|
|
||||||
" You are lucky in this node live some wizards and"
|
|
||||||
" fairies, we have done this for you and don't announce, Be as hidden as wished",
|
|
||||||
arg);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* the intended call */
|
|
||||||
return opt_add_addr_withtype(arg, ld, ADDR_LISTEN, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u)
|
static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u)
|
||||||
{
|
{
|
||||||
snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u);
|
snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u);
|
||||||
|
|
Loading…
Add table
Reference in a new issue