dns: expose multiaddress connect code.

Internally the dns code has the ability to try connecting to multiple
addresses in a sequence.  Expose this, as we'll want it for reconnection.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-05-23 21:47:34 +09:30
parent f4722e93a0
commit 58bf67c310
2 changed files with 44 additions and 0 deletions

View File

@ -154,6 +154,29 @@ static struct io_plan *start_connecting(struct io_conn *conn,
return io_close(conn);
}
struct dns_async *multiaddress_connect_(struct lightningd_state *dstate,
const struct netaddr *addresses,
struct io_plan *(*init)(struct io_conn *,
struct lightningd_state *,
const struct netaddr *,
void *arg),
void (*fail)(struct lightningd_state *, void *arg),
void *arg)
{
struct dns_async *d = tal(dstate, struct dns_async);
d->dstate = dstate;
d->init = init;
d->fail = fail;
d->arg = arg;
d->name = "names from address list";
d->num_addresses = tal_count(addresses);
d->addresses = tal_dup_arr(d, struct netaddr, addresses,
d->num_addresses, 0);
try_connect_one(d);
return d;
}
static struct io_plan *read_addresses(struct io_conn *conn, struct dns_async *d)
{
d->addresses = tal_arr(d, struct netaddr, d->num_addresses);

View File

@ -29,4 +29,25 @@ struct dns_async *dns_resolve_and_connect_(struct lightningd_state *dstate,
void (*fail)(struct lightningd_state *, void *arg),
void *arg);
/* Don't do lookup, just try to connect to these addresses. */
#define multiaddress_connect(dstate, addresses, initfn, failfn, arg) \
multiaddress_connect_((dstate), (addresses), \
typesafe_cb_preargs(struct io_plan *, void *, \
(initfn), (arg), \
struct io_conn *, \
struct lightningd_state *, \
const struct netaddr *), \
typesafe_cb_preargs(void, void *, (failfn), (arg), \
struct lightningd_state *), \
(arg))
struct dns_async *multiaddress_connect_(struct lightningd_state *dstate,
const struct netaddr *addresses,
struct io_plan *(*init)(struct io_conn *,
struct lightningd_state *,
const struct netaddr *,
void *arg),
void (*fail)(struct lightningd_state *, void *arg),
void *arg);
#endif /* PETTYCOIN_DNS_H */