mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
lightningd: associate connect commands with peer, not channel.
Sure, we want to connect (usually) because of an active channel, but it's not specific to the channel itself. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
33abf93ec1
commit
b3438e9bba
6 changed files with 56 additions and 44 deletions
|
@ -931,7 +931,7 @@ static void err_and_reconnect(struct channel *channel,
|
|||
channel_set_owner(channel, NULL);
|
||||
|
||||
/* Their address only useful if we connected to them */
|
||||
try_reconnect(channel, seconds_before_reconnect,
|
||||
try_reconnect(channel, channel->peer, seconds_before_reconnect,
|
||||
channel->peer->connected_incoming
|
||||
? NULL
|
||||
: &channel->peer->addr);
|
||||
|
|
|
@ -77,7 +77,6 @@ static struct command_result *connect_cmd_succeed(struct command *cmd,
|
|||
static void try_connect(const tal_t *ctx,
|
||||
struct lightningd *ld,
|
||||
const struct node_id *id,
|
||||
struct channel *channel,
|
||||
u32 seconds_delay,
|
||||
const struct wireaddr_internal *addrhint);
|
||||
|
||||
|
@ -157,7 +156,7 @@ static struct command_result *json_connect(struct command *cmd,
|
|||
} else
|
||||
addr = NULL;
|
||||
|
||||
try_connect(cmd, cmd->ld, &id, NULL, 0, addr);
|
||||
try_connect(cmd, cmd->ld, &id, 0, addr);
|
||||
|
||||
/* Leave this here for peer_connected or connect_failed. */
|
||||
new_connect(cmd->ld, &id, cmd);
|
||||
|
@ -178,8 +177,6 @@ AUTODATA(json_command, &connect_command);
|
|||
struct delayed_reconnect {
|
||||
struct lightningd *ld;
|
||||
struct node_id id;
|
||||
/* May be unset if there's no associated channel */
|
||||
struct channel *channel;
|
||||
u32 seconds_delayed;
|
||||
struct wireaddr_internal *addrhint;
|
||||
};
|
||||
|
@ -196,12 +193,6 @@ static void gossipd_got_addrs(struct subd *subd,
|
|||
fatal("Gossipd gave bad GOSSIPD_GET_ADDRS_REPLY %s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
/* Might have gone onchain (if it was actually freed, we were too). */
|
||||
if (d->channel && !channel_active(d->channel)) {
|
||||
tal_free(d);
|
||||
return;
|
||||
}
|
||||
|
||||
connectmsg = towire_connectd_connect_to_peer(NULL,
|
||||
&d->id,
|
||||
d->seconds_delayed,
|
||||
|
@ -219,20 +210,19 @@ static void do_connect(struct delayed_reconnect *d)
|
|||
subd_req(d, d->ld->gossip, take(msg), -1, 0, gossipd_got_addrs, d);
|
||||
}
|
||||
|
||||
/* channel may be NULL here */
|
||||
/* peer may be NULL here */
|
||||
static void try_connect(const tal_t *ctx,
|
||||
struct lightningd *ld,
|
||||
const struct node_id *id,
|
||||
struct channel *channel,
|
||||
u32 seconds_delay,
|
||||
const struct wireaddr_internal *addrhint)
|
||||
{
|
||||
struct delayed_reconnect *d;
|
||||
struct peer *peer;
|
||||
|
||||
d = tal(ctx, struct delayed_reconnect);
|
||||
d->ld = ld;
|
||||
d->id = *id;
|
||||
d->channel = channel;
|
||||
d->seconds_delayed = seconds_delay;
|
||||
d->addrhint = tal_dup_or_null(d, struct wireaddr_internal, addrhint);
|
||||
|
||||
|
@ -241,14 +231,22 @@ static void try_connect(const tal_t *ctx,
|
|||
return;
|
||||
}
|
||||
|
||||
/* We never have a delay when connecting without a channel */
|
||||
assert(channel);
|
||||
channel_set_billboard(channel, false,
|
||||
tal_fmt(tmpctx,
|
||||
"Will attempt reconnect "
|
||||
"in %u seconds", seconds_delay));
|
||||
log_debug(channel->log, "Will try reconnect in %u seconds",
|
||||
seconds_delay);
|
||||
log_peer_debug(ld->log, id, "Will try reconnect in %u seconds",
|
||||
seconds_delay);
|
||||
/* Update any channel billboards */
|
||||
peer = peer_by_id(ld, id);
|
||||
if (peer) {
|
||||
struct channel *channel;
|
||||
list_for_each(&peer->channels, channel, list) {
|
||||
if (!channel_active(channel))
|
||||
continue;
|
||||
channel_set_billboard(channel, false,
|
||||
tal_fmt(tmpctx,
|
||||
"Will attempt reconnect "
|
||||
"in %u seconds",
|
||||
seconds_delay));
|
||||
}
|
||||
}
|
||||
|
||||
/* We fuzz the timer by up to 1 second, to avoid getting into
|
||||
* simultanous-reconnect deadlocks with peer. */
|
||||
|
@ -258,17 +256,17 @@ static void try_connect(const tal_t *ctx,
|
|||
do_connect, d));
|
||||
}
|
||||
|
||||
void try_reconnect(struct channel *channel,
|
||||
void try_reconnect(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
u32 seconds_delay,
|
||||
const struct wireaddr_internal *addrhint)
|
||||
{
|
||||
if (!channel->peer->ld->reconnect)
|
||||
if (!peer->ld->reconnect)
|
||||
return;
|
||||
|
||||
try_connect(channel,
|
||||
channel->peer->ld,
|
||||
&channel->peer->id,
|
||||
channel,
|
||||
try_connect(ctx,
|
||||
peer->ld,
|
||||
&peer->id,
|
||||
seconds_delay,
|
||||
addrhint);
|
||||
}
|
||||
|
@ -281,7 +279,7 @@ static void connect_failed(struct lightningd *ld, const u8 *msg)
|
|||
struct connect *c;
|
||||
u32 seconds_to_delay;
|
||||
struct wireaddr_internal *addrhint;
|
||||
struct channel *channel;
|
||||
struct peer *peer;
|
||||
|
||||
if (!fromwire_connectd_connect_failed(tmpctx, msg, &id, &errcode, &errmsg,
|
||||
&seconds_to_delay, &addrhint))
|
||||
|
@ -295,9 +293,12 @@ static void connect_failed(struct lightningd *ld, const u8 *msg)
|
|||
}
|
||||
|
||||
/* If we have an active channel, then reconnect. */
|
||||
channel = active_channel_by_id(ld, &id, NULL);
|
||||
if (channel)
|
||||
try_reconnect(channel, seconds_to_delay, addrhint);
|
||||
peer = peer_by_id(ld, &id);
|
||||
if (peer) {
|
||||
struct channel *channel = peer_active_channel(peer);
|
||||
if (channel)
|
||||
try_reconnect(peer, peer, seconds_to_delay, addrhint);
|
||||
}
|
||||
}
|
||||
|
||||
void connect_succeeded(struct lightningd *ld, const struct peer *peer,
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H
|
||||
#define LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
struct lightningd;
|
||||
struct peer;
|
||||
struct pubkey;
|
||||
struct wireaddr_internal;
|
||||
|
||||
|
@ -10,8 +13,10 @@ struct wireaddr_internal;
|
|||
int connectd_init(struct lightningd *ld);
|
||||
void connectd_activate(struct lightningd *ld);
|
||||
|
||||
void try_reconnect(struct channel *channel, u32 seconds_delay,
|
||||
const struct wireaddr_internal *addrhint TAKES);
|
||||
void try_reconnect(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
u32 seconds_delay,
|
||||
const struct wireaddr_internal *addrhint);
|
||||
void connect_succeeded(struct lightningd *ld, const struct peer *peer,
|
||||
bool incoming,
|
||||
const struct wireaddr_internal *addr);
|
||||
|
|
|
@ -1789,12 +1789,7 @@ static void setup_peer(struct peer *peer, u32 delay)
|
|||
struct channel *channel;
|
||||
struct channel_inflight *inflight;
|
||||
struct lightningd *ld = peer->ld;
|
||||
|
||||
/* We can only have one active channel: make sure connectd
|
||||
* knows to try reconnecting. */
|
||||
channel = peer_active_channel(peer);
|
||||
if (channel)
|
||||
try_reconnect(channel, delay, &peer->addr);
|
||||
bool connect = false;
|
||||
|
||||
list_for_each(&peer->channels, channel, list) {
|
||||
if (channel_unsaved(channel))
|
||||
|
@ -1812,7 +1807,14 @@ static void setup_peer(struct peer *peer, u32 delay)
|
|||
|
||||
channel_watch_inflight(ld, channel, inflight);
|
||||
}
|
||||
if (channel_active(channel))
|
||||
connect = true;
|
||||
}
|
||||
|
||||
/* Make sure connectd knows to try reconnecting. */
|
||||
if (connect)
|
||||
try_reconnect(peer, peer, delay, &peer->addr);
|
||||
|
||||
}
|
||||
|
||||
void setup_peers(struct lightningd *ld)
|
||||
|
|
|
@ -700,8 +700,10 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
|
|||
const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
|
||||
/* Generated stub for try_reconnect */
|
||||
void try_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED,
|
||||
const struct wireaddr_internal *addrhint TAKES UNNEEDED)
|
||||
void try_reconnect(const tal_t *ctx UNNEEDED,
|
||||
struct peer *peer UNNEEDED,
|
||||
u32 seconds_delay UNNEEDED,
|
||||
const struct wireaddr_internal *addrhint UNNEEDED)
|
||||
{ fprintf(stderr, "try_reconnect called!\n"); abort(); }
|
||||
/* Generated stub for version */
|
||||
const char *version(void)
|
||||
|
|
|
@ -829,8 +829,10 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
|
|||
const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
|
||||
/* Generated stub for try_reconnect */
|
||||
void try_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED,
|
||||
const struct wireaddr_internal *addrhint TAKES UNNEEDED)
|
||||
void try_reconnect(const tal_t *ctx UNNEEDED,
|
||||
struct peer *peer UNNEEDED,
|
||||
u32 seconds_delay UNNEEDED,
|
||||
const struct wireaddr_internal *addrhint UNNEEDED)
|
||||
{ fprintf(stderr, "try_reconnect called!\n"); abort(); }
|
||||
/* Generated stub for watch_txid */
|
||||
struct txwatch *watch_txid(const tal_t *ctx UNNEEDED,
|
||||
|
|
Loading…
Add table
Reference in a new issue