daemon/dns: hand netaddr we connected to through to callback.

That way it doesn't have to extract it from fd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-05-22 20:56:50 +09:30
parent f6495d3310
commit 0c8b24cf97
6 changed files with 23 additions and 11 deletions

View File

@@ -18,6 +18,7 @@
struct dns_async {
struct lightningd_state *dstate;
struct io_plan *(*init)(struct io_conn *, struct lightningd_state *,
const struct netaddr *,
void *);
void (*fail)(struct lightningd_state *, void *arg);
const char *name;
@@ -76,7 +77,7 @@ static struct io_plan *connected(struct io_conn *conn, struct dns_async *d)
/* No longer need to try more connections via connect_failed. */
io_set_finish(conn, NULL, NULL);
plan = d->init(conn, d->dstate, d->arg);
plan = d->init(conn, d->dstate, &d->addresses[-1], d->arg);
tal_free(d);
return plan;
@@ -178,6 +179,7 @@ struct dns_async *dns_resolve_and_connect_(struct lightningd_state *dstate,
const char *name, const char *port,
struct io_plan *(*init)(struct io_conn *,
struct lightningd_state *,
const struct netaddr *,
void *arg),
void (*fail)(struct lightningd_state *, void *arg),
void *arg)

View File

@@ -14,7 +14,8 @@ struct netaddr;
typesafe_cb_preargs(struct io_plan *, void *, \
(initfn), (arg), \
struct io_conn *, \
struct lightningd_state *), \
struct lightningd_state *, \
const struct netaddr *), \
typesafe_cb_preargs(void, void *, (failfn), (arg), \
struct lightningd_state *), \
(arg))
@@ -23,6 +24,7 @@ struct dns_async *dns_resolve_and_connect_(struct lightningd_state *dstate,
const char *name, const char *port,
struct io_plan *(*init)(struct io_conn *,
struct lightningd_state *,
const struct netaddr *,
void *arg),
void (*fail)(struct lightningd_state *, void *arg),
void *arg);

View File

@@ -2996,20 +2996,15 @@ static struct io_plan *crypto_on_out(struct io_conn *conn,
static struct io_plan *peer_connected_out(struct io_conn *conn,
struct lightningd_state *dstate,
const struct netaddr *netaddr,
struct json_connecting *connect)
{
struct log *l;
struct netaddr addr;
l = new_log(conn, dstate->log_book, "OUT-%s:%s:",
connect->name, connect->port);
if (!netaddr_from_fd(io_conn_fd(conn), SOCK_STREAM, IPPROTO_TCP, &addr)) {
log_unusual(l, "Failed to get netaddr: %s", strerror(errno));
return io_close(conn);
}
log_debug_struct(l, "Connected out to %s", struct netaddr, &addr);
log_debug_struct(l, "Connected out to %s", struct netaddr, netaddr);
return peer_crypto_setup(conn, dstate, NULL, l, crypto_on_out, connect);
}