mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
netaddr: remove.
We use ipaddr everywhere now, so we can remove this. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
dfd60a2047
commit
bd1cac34ce
8 changed files with 26 additions and 168 deletions
|
@ -18,7 +18,6 @@ union printable_types {
|
|||
const struct preimage *preimage;
|
||||
const struct channel_state *channel_state;
|
||||
const struct channel_oneside *channel_oneside;
|
||||
const struct netaddr *netaddr;
|
||||
const secp256k1_pubkey *secp256k1_pubkey;
|
||||
const struct channel_id *channel_id;
|
||||
const struct short_channel_id *short_channel_id;
|
||||
|
|
|
@ -52,8 +52,7 @@ GOSSIPD_COMMON_OBJS := \
|
|||
common/wire_error.o \
|
||||
hsmd/client.o \
|
||||
hsmd/gen_hsm_client_wire.o \
|
||||
lightningd/gossip_msg.o \
|
||||
lightningd/netaddr.o
|
||||
lightningd/gossip_msg.o
|
||||
|
||||
$(LIGHTNINGD_GOSSIP_OBJS) $(LIGHTNINGD_GOSSIP_CLIENT_OBJS): $(LIGHTNINGD_HEADERS)
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ LIGHTNINGD_SRC := \
|
|||
lightningd/jsonrpc.c \
|
||||
lightningd/lightningd.c \
|
||||
lightningd/log.c \
|
||||
lightningd/netaddr.c \
|
||||
lightningd/opt_time.c \
|
||||
lightningd/options.c \
|
||||
lightningd/pay.c \
|
||||
|
|
|
@ -248,7 +248,7 @@ static void json_getinfo(struct command *cmd,
|
|||
|
||||
json_object_start(response, NULL);
|
||||
json_add_pubkey(response, "id", &cmd->ld->id);
|
||||
/* FIXME: Keep netaddrs and list them all. */
|
||||
/* FIXME: Keep ipaddr and list them all. */
|
||||
if (cmd->ld->portnum)
|
||||
json_add_num(response, "port", cmd->ld->portnum);
|
||||
json_add_string(response, "network",
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
#include "bitcoin/pullpush.h"
|
||||
#include "netaddr.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <ccan/endian/endian.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <common/utils.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void netaddr_to_addrinfo(struct addrinfo *ai, const struct netaddr *a)
|
||||
{
|
||||
ai->ai_flags = 0;
|
||||
ai->ai_family = a->saddr.s.sa_family;
|
||||
ai->ai_socktype = a->type;
|
||||
ai->ai_protocol = a->protocol;
|
||||
ai->ai_addrlen = a->addrlen;
|
||||
ai->ai_addr = cast_const(struct sockaddr *, &a->saddr.s);
|
||||
ai->ai_canonname = NULL;
|
||||
ai->ai_next = NULL;
|
||||
}
|
||||
|
||||
char *netaddr_name(const tal_t *ctx, const struct netaddr *a)
|
||||
{
|
||||
char name[INET6_ADDRSTRLEN];
|
||||
const void *sockaddr;
|
||||
uint16_t port;
|
||||
|
||||
switch (a->saddr.s.sa_family) {
|
||||
case AF_INET:
|
||||
sockaddr = &a->saddr.ipv4.sin_addr;
|
||||
port = ntohs(a->saddr.ipv4.sin_port);
|
||||
break;
|
||||
case AF_INET6:
|
||||
sockaddr = &a->saddr.ipv6.sin6_addr;
|
||||
port = ntohs(a->saddr.ipv6.sin6_port);
|
||||
break;
|
||||
default:
|
||||
return tal_fmt(ctx, "Unknown protocol %u", a->saddr.s.sa_family);
|
||||
}
|
||||
|
||||
if (!inet_ntop(a->saddr.s.sa_family, sockaddr, name, sizeof(name)))
|
||||
sprintf(name, "Unprintable-%u-address", a->saddr.s.sa_family);
|
||||
|
||||
return tal_fmt(ctx, "%s:%u", name, port);
|
||||
}
|
||||
|
||||
char *netaddr_to_hex(const tal_t *ctx, const struct netaddr *a)
|
||||
{
|
||||
u8 *blob = tal_arr(ctx, u8, 0);
|
||||
char *hex;
|
||||
|
||||
push_le32(a->type, push, &blob);
|
||||
push_le32(a->protocol, push, &blob);
|
||||
push_le32(a->addrlen, push, &blob);
|
||||
assert(a->addrlen <= sizeof(a->saddr));
|
||||
push(&a->saddr, a->addrlen, &blob);
|
||||
|
||||
hex = tal_hex(ctx, blob);
|
||||
tal_free(blob);
|
||||
return hex;
|
||||
}
|
||||
|
||||
bool netaddr_from_blob(const void *linear, size_t len, struct netaddr *a)
|
||||
{
|
||||
const u8 *p = linear;
|
||||
|
||||
a->type = pull_le32(&p, &len);
|
||||
a->protocol = pull_le32(&p, &len);
|
||||
a->addrlen = pull_le32(&p, &len);
|
||||
if (a->addrlen > sizeof(a->saddr))
|
||||
return false;
|
||||
pull(&p, &len, &a->saddr, a->addrlen);
|
||||
return p != NULL && len == 0;
|
||||
}
|
||||
|
||||
bool netaddr_from_fd(int fd, int type, int protocol, struct netaddr *a)
|
||||
{
|
||||
a->type = type;
|
||||
a->protocol = protocol;
|
||||
a->addrlen = sizeof(a->saddr);
|
||||
return getpeername(fd, &a->saddr.s, &a->addrlen) == 0;
|
||||
}
|
||||
|
||||
REGISTER_TYPE_TO_STRING(netaddr, netaddr_name);
|
|
@ -1,35 +0,0 @@
|
|||
/* FIXME: We should deprecate this in favor of BOLT7 address descriptor */
|
||||
#ifndef LIGHTNING_LIGHTNINGD_NETADDR_H
|
||||
#define LIGHTNING_LIGHTNINGD_NETADDR_H
|
||||
#include "config.h"
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
struct addrinfo;
|
||||
|
||||
/* This can be extended to support other protocols in future. */
|
||||
struct netaddr {
|
||||
int type; /* See socket(2): SOCK_STREAM currently */
|
||||
int protocol; /* See socket(2): 0 currently */
|
||||
socklen_t addrlen;
|
||||
union {
|
||||
struct sockaddr s;
|
||||
struct sockaddr_in ipv4;
|
||||
struct sockaddr_in6 ipv6;
|
||||
} saddr;
|
||||
};
|
||||
|
||||
/* Get the name for this netaddr. */
|
||||
char *netaddr_name(const tal_t *ctx, const struct netaddr *a);
|
||||
|
||||
/* Create a addrinfo (as wanted by io_connect) for this address. */
|
||||
void netaddr_to_addrinfo(struct addrinfo *ai, const struct netaddr *a);
|
||||
|
||||
bool netaddr_from_fd(int fd, int type, int protocol, struct netaddr *a);
|
||||
|
||||
bool netaddr_from_blob(const void *linear, size_t len, struct netaddr *a);
|
||||
char *netaddr_to_hex(const tal_t *ctx, const struct netaddr *a);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_NETADDR_H */
|
|
@ -1,6 +1,7 @@
|
|||
#include "lightningd.h"
|
||||
#include "peer_control.h"
|
||||
#include "subd.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/fdpass/fdpass.h>
|
||||
|
@ -347,12 +348,6 @@ static struct peer *new_peer(struct lightningd *ld,
|
|||
/* peer->channel gets populated as soon as we start opening a channel */
|
||||
peer->channel = NULL;
|
||||
|
||||
/* FIXME: Don't assume protocol here! */
|
||||
if (!netaddr_from_fd(peer_fd, SOCK_STREAM, IPPROTO_TCP, &peer->netaddr)) {
|
||||
log_unusual(ld->log, "Failed to get netaddr for outgoing: %s",
|
||||
strerror(errno));
|
||||
return tal_free(peer);
|
||||
}
|
||||
list_add_tail(&ld->peers, &peer->list);
|
||||
populate_peer(ld, peer);
|
||||
|
||||
|
@ -790,6 +785,28 @@ static void log_to_json(unsigned int skipped,
|
|||
json_add_string(info->response, NULL, log);
|
||||
}
|
||||
|
||||
static const char *ipaddr_name(const tal_t *ctx, const struct ipaddr *a)
|
||||
{
|
||||
char name[INET6_ADDRSTRLEN];
|
||||
int af;
|
||||
|
||||
switch (a->type) {
|
||||
case ADDR_TYPE_IPV4:
|
||||
af = AF_INET;
|
||||
break;
|
||||
case ADDR_TYPE_IPV6:
|
||||
af = AF_INET6;
|
||||
break;
|
||||
default:
|
||||
return tal_fmt(ctx, "Unknown type %u", a->type);
|
||||
}
|
||||
|
||||
if (!inet_ntop(af, a->addr, name, sizeof(name)))
|
||||
sprintf(name, "Unprintable-%u-address", a->type);
|
||||
|
||||
return tal_fmt(ctx, "%s:%u", name, a->port);
|
||||
}
|
||||
|
||||
static void json_getpeers(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
|
@ -821,7 +838,7 @@ static void json_getpeers(struct command *cmd,
|
|||
json_object_start(response, NULL);
|
||||
json_add_string(response, "state", peer_state_name(p->state));
|
||||
json_add_string(response, "netaddr",
|
||||
netaddr_name(response, &p->netaddr));
|
||||
ipaddr_name(response, &p->addr));
|
||||
json_add_pubkey(response, "peerid", &p->id);
|
||||
json_add_bool(response, "connected", p->owner != NULL);
|
||||
if (p->owner)
|
||||
|
@ -2221,7 +2238,6 @@ static void peer_accept_channel(struct lightningd *ld,
|
|||
{
|
||||
u32 max_to_self_delay, max_minimum_depth;
|
||||
u64 min_effective_htlc_capacity_msat;
|
||||
u8 *errmsg;
|
||||
u8 *msg;
|
||||
struct peer *peer;
|
||||
|
||||
|
@ -2229,13 +2245,6 @@ static void peer_accept_channel(struct lightningd *ld,
|
|||
|
||||
/* We make a new peer. */
|
||||
peer = new_peer(ld, peer_id, addr, gfeatures, lfeatures, peer_fd);
|
||||
|
||||
/* FIXME: Only happens due to netaddr fail. */
|
||||
if (!peer) {
|
||||
errmsg = towire_errorfmt(ld, NULL, "Can't resolve your address");
|
||||
goto peer_to_gossipd;
|
||||
}
|
||||
|
||||
peer_set_condition(peer, UNINITIALIZED, OPENINGD);
|
||||
peer_set_owner(peer,
|
||||
new_peer_subd(ld, "lightning_openingd", peer,
|
||||
|
@ -2285,17 +2294,6 @@ static void peer_accept_channel(struct lightningd *ld,
|
|||
|
||||
subd_req(peer, peer->owner, take(msg), -1, 2,
|
||||
opening_fundee_finished, peer);
|
||||
return;
|
||||
|
||||
peer_to_gossipd:
|
||||
/* Return to gossipd, with optional error msg to send. */
|
||||
msg = towire_gossipctl_handle_peer(ld, peer_id, addr, cs,
|
||||
gfeatures, lfeatures, errmsg);
|
||||
subd_send_msg(ld->gossip, take(msg));
|
||||
subd_send_fd(ld->gossip, peer_fd);
|
||||
close(gossip_fd);
|
||||
tal_free(errmsg);
|
||||
return;
|
||||
}
|
||||
|
||||
static void peer_offer_channel(struct lightningd *ld,
|
||||
|
@ -2313,16 +2311,6 @@ static void peer_offer_channel(struct lightningd *ld,
|
|||
/* We make a new peer. */
|
||||
fc->peer = new_peer(ld, &fc->peerid, addr,
|
||||
gfeatures, lfeatures, peer_fd);
|
||||
|
||||
/* FIXME: Only happens due to netaddr fail. */
|
||||
if (!fc->peer) {
|
||||
command_fail(fc->cmd,
|
||||
"Failed to make peer: Can't resolve address: %s",
|
||||
strerror(errno));
|
||||
close(peer_fd);
|
||||
close(gossip_fd);
|
||||
return;
|
||||
}
|
||||
fc->peer->funding_satoshi = fc->funding_satoshi;
|
||||
fc->peer->push_msat = fc->push_msat;
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <common/channel_config.h>
|
||||
#include <common/htlc.h>
|
||||
#include <common/json.h>
|
||||
#include <lightningd/netaddr.h>
|
||||
#include <lightningd/peer_state.h>
|
||||
#include <stdbool.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
@ -55,7 +54,6 @@ struct peer {
|
|||
u8 channel_flags;
|
||||
|
||||
/* Where we connected to, or it connected from. */
|
||||
struct netaddr netaddr;
|
||||
struct ipaddr addr;
|
||||
|
||||
/* Our channel config. */
|
||||
|
|
Loading…
Add table
Reference in a new issue