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

@@ -14,6 +14,9 @@ struct connection {
/* Lightning daemon, for when we're handed through callbacks. */
struct lightningd *ld;
/* Where we connected to/from. */
struct netaddr netaddr;
/* Unique identifier for handshaked. */
u64 unique_id;
@@ -166,8 +169,10 @@ static struct io_plan *hsm_then_handshake(struct io_conn *conn,
struct io_plan *connection_out(struct io_conn *conn,
struct lightningd_state *dstate,
const struct netaddr *netaddr,
struct connection *c)
{
c->netaddr = *netaddr;
return hsm_then_handshake(conn, ld_from_dstate(dstate), c);
}
@@ -175,5 +180,11 @@ struct io_plan *connection_in(struct io_conn *conn, struct lightningd *ld)
{
struct connection *c = new_connection(ld, ld, NULL, NULL);
/* FIXME: Don't assume TCP here. */
if (!netaddr_from_fd(io_conn_fd(conn), SOCK_STREAM, IPPROTO_TCP,
&c->netaddr)) {
log_unusual(ld->log, "Could not get address of incoming fd");
return io_close(conn);
}
return hsm_then_handshake(conn, ld, c);
}

View File

@@ -7,6 +7,7 @@ struct command;
struct io_conn;
struct lightningd;
struct lightningd_state;
struct netaddr;
struct pubkey;
struct connection *new_connection(const tal_t *ctx,
@@ -16,6 +17,7 @@ struct connection *new_connection(const tal_t *ctx,
struct io_plan *connection_out(struct io_conn *conn,
struct lightningd_state *dstate,
const struct netaddr *netaddr,
struct connection *c);
struct io_plan *connection_in(struct io_conn *conn, struct lightningd *ld);