Files
lightning/common/wireaddr.h
Rusty Russell fe96fe10c7 Clean up network options.
It's become clear that our network options are insufficient, with the coming
addition of Tor and unix domain support.

Currently:

1. We always bind to local IPv4 and IPv6 sockets, unless --port=0, --offline,
   or any address is specified explicitly.  If they're routable, we announce.
2. --addr is used to announce, but not to control binding.

After this change:

1. --port is deprecated.
2. --addr controls what we bind to and announce.
3. --bind-addr/--announce-addr can be used to control one and not the other.
4. Unless --autolisten=0, we add local IPv4 & IPv6 port 9735 (and announce if they are routable).
5. --offline still overrides listening (though announcing is still the same).

This means we can bind to as many ports/interfaces as we want, and for
special effects we can announce different things (eg. we're sitting
behind a port forward or a proxy).

What remains to implement is semi-automatic binding: we should be able
to say '--addr=0.0.0.0:9999' and have the address resolve at bind
time, or even '--addr=0.0.0.0:0' and have the port autoresolve too
(you could determine what it was from 'lightning-cli getinfo'.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00

64 lines
2.2 KiB
C

#ifndef LIGHTNING_COMMON_WIREADDR_H
#define LIGHTNING_COMMON_WIREADDR_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <stdbool.h>
#include <stdlib.h>
/* BOLT #7:
*
* The following `address descriptor` types are defined:
*
* * `0`: padding. data = none (length 0).
* * `1`: ipv4. data = `[4:ipv4_addr][2:port]` (length 6)
* * `2`: ipv6. data = `[16:ipv6_addr][2:port]` (length 18)
* * `3`: tor v2 onion service. data = `[10:onion_addr][2:port]` (length 12)
* * Version 2 onion service addresses. Encodes an 80-bit truncated `SHA-1` hash
* of a 1024-bit `RSA` public key for the onion service.
* * `4`: tor v3 onion service. data `[35:onion_addr][2:port]` (length 37)
* * Version 3 ([prop224](https://gitweb.torproject.org/torspec.git/tree/proposals/224-rend-spec-ng.txt))
* onion service addresses. Encodes: `[32:32_byte_ed25519_pubkey] || [2:checksum] || [1:version]`.
* where `checksum = sha3(".onion checksum" | pubkey || version)[:2]`
*/
enum wire_addr_type {
ADDR_TYPE_PADDING = 0,
ADDR_TYPE_IPV4 = 1,
ADDR_TYPE_IPV6 = 2,
};
/* FIXME(cdecker) Extend this once we have defined how TOR addresses
* should look like */
struct wireaddr {
enum wire_addr_type type;
u8 addrlen;
u8 addr[16];
u16 port;
};
/* We use wireaddr to tell gossipd both what to listen on, and what to
* announce */
enum addr_listen_announce {
ADDR_LISTEN = (1 << 0),
ADDR_ANNOUNCE = (1 << 1),
ADDR_LISTEN_AND_ANNOUNCE = ADDR_LISTEN|ADDR_ANNOUNCE
};
/* Inserts a single ADDR_TYPE_PADDING if addr is NULL */
void towire_wireaddr(u8 **pptr, const struct wireaddr *addr);
bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr);
enum addr_listen_announce fromwire_addr_listen_announce(const u8 **cursor,
size_t *max);
void towire_addr_listen_announce(u8 **pptr, enum addr_listen_announce ala);
bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 port, const char **err_msg);
char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a);
bool wireaddr_from_hostname(struct wireaddr *addr, const char *hostname,
const u16 port, const char **err_msg);
#endif /* LIGHTNING_COMMON_WIREADDR_H */