mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
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:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
4
irc.c
4
irc.c
@@ -7,7 +7,7 @@ void (*irc_command_cb)(struct ircstate *, const struct irccommand *) = NULL;
|
||||
void (*irc_connect_cb)(struct ircstate *) = NULL;
|
||||
void (*irc_disconnect_cb)(struct ircstate *) = NULL;
|
||||
|
||||
static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_state *dstate, struct ircstate *state);
|
||||
static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_state *dstate, const struct netaddr *netaddr, struct ircstate *state);
|
||||
static void irc_disconnected(struct io_conn *conn, struct ircstate *state);
|
||||
|
||||
bool irc_send_msg(struct ircstate *state, struct privmsg *m)
|
||||
@@ -167,7 +167,7 @@ void irc_connect(struct ircstate *state)
|
||||
dns_resolve_and_connect(state->dstate, state->server, "6667", irc_connected, irc_failed, state);
|
||||
}
|
||||
|
||||
static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_state *dstate, struct ircstate *state)
|
||||
static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_state *dstate, const struct netaddr *netaddr, struct ircstate *state)
|
||||
{
|
||||
io_set_finish(conn, irc_disconnected, state);
|
||||
state->conn = conn;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user