Browse Source
In future it will have TOR support, so the name will be awkward. We collect the to/fromwire functions in common/wireaddr.c, and the parsing functions in lightningd/netaddress.c. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
7 years ago
32 changed files with 220 additions and 193 deletions
@ -0,0 +1,30 @@ |
|||
#include <common/wireaddr.h> |
|||
#include <wire/wire.h> |
|||
|
|||
/* Returns false if we didn't parse it, and *cursor == NULL if malformed. */ |
|||
bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr) |
|||
{ |
|||
addr->type = fromwire_u8(cursor, max); |
|||
|
|||
switch (addr->type) { |
|||
case ADDR_TYPE_IPV4: |
|||
addr->addrlen = 4; |
|||
break; |
|||
case ADDR_TYPE_IPV6: |
|||
addr->addrlen = 16; |
|||
break; |
|||
default: |
|||
return false; |
|||
} |
|||
fromwire(cursor, max, addr->addr, addr->addrlen); |
|||
addr->port = fromwire_u16(cursor, max); |
|||
|
|||
return *cursor != NULL; |
|||
} |
|||
|
|||
void towire_wireaddr(u8 **pptr, const struct wireaddr *addr) |
|||
{ |
|||
towire_u8(pptr, addr->type); |
|||
towire(pptr, addr->addr, addr->addrlen); |
|||
towire_u16(pptr, addr->port); |
|||
} |
@ -0,0 +1,41 @@ |
|||
#ifndef LIGHTNING_COMMON_WIREADDR_H |
|||
#define LIGHTNING_COMMON_WIREADDR_H |
|||
#include "config.h" |
|||
#include <ccan/short_types/short_types.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; |
|||
}; |
|||
|
|||
void towire_wireaddr(u8 **pptr, const struct wireaddr *addr); |
|||
bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr); |
|||
#endif /* LIGHTNING_COMMON_WIREADDR_H */ |
Can't render this file because it has a wrong number of fields in line 4.
|
@ -1,9 +1,12 @@ |
|||
#ifndef LIGHTNING_LIGHTNINGD_NETADDRESS_H |
|||
#define LIGHTNING_LIGHTNINGD_NETADDRESS_H |
|||
#include "config.h" |
|||
#include <ccan/short_types/short_types.h> |
|||
|
|||
struct lightningd; |
|||
|
|||
void guess_addresses(struct lightningd *ld); |
|||
|
|||
bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 port); |
|||
|
|||
#endif /* LIGHTNING_LIGHTNINGD_NETADDRESS_H */ |
|||
|
Loading…
Reference in new issue