mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 09:04:22 +01:00
gossip: Give up connecting after 10 attempts
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
f5147f27c9
commit
932dbd8c2c
@@ -100,6 +100,15 @@ struct reaching {
|
|||||||
|
|
||||||
/* Did we succeed? */
|
/* Did we succeed? */
|
||||||
bool succeeded;
|
bool succeeded;
|
||||||
|
|
||||||
|
/* How many times have we attempted to connect? */
|
||||||
|
u32 attempts;
|
||||||
|
|
||||||
|
/* How many timest to attempt */
|
||||||
|
u32 max_attempts;
|
||||||
|
|
||||||
|
/* Timestamp of the first attempt */
|
||||||
|
u32 first_attempt;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Things we need when we're talking direct to the peer. */
|
/* Things we need when we're talking direct to the peer. */
|
||||||
@@ -1557,13 +1566,24 @@ static void try_connect(struct reaching *reach);
|
|||||||
|
|
||||||
static void connect_failed(struct io_conn *conn, struct reaching *reach)
|
static void connect_failed(struct io_conn *conn, struct reaching *reach)
|
||||||
{
|
{
|
||||||
status_trace("Failed connected out for %s, will try again",
|
u32 diff = time_now().ts.tv_sec - reach->first_attempt;
|
||||||
type_to_string(trc, struct pubkey, &reach->id));
|
reach->attempts++;
|
||||||
|
|
||||||
/* FIXME: Configurable timer! */
|
if (reach->attempts >= reach->max_attempts) {
|
||||||
new_reltimer(&reach->daemon->timers, reach,
|
status_trace("Failed to connect after %d attempts, giving up "
|
||||||
time_from_sec(5),
|
"after %d seconds",
|
||||||
try_connect, reach);
|
reach->attempts, diff);
|
||||||
|
daemon_conn_send(&reach->daemon->master,
|
||||||
|
take(towire_gossip_peer_connection_failed(
|
||||||
|
conn, &reach->id, diff, reach->attempts)));
|
||||||
|
tal_free(reach);
|
||||||
|
} else {
|
||||||
|
status_trace("Failed connected out for %s, will try again",
|
||||||
|
type_to_string(trc, struct pubkey, &reach->id));
|
||||||
|
/* FIXME: Configurable timer! */
|
||||||
|
new_reltimer(&reach->daemon->timers, reach, time_from_sec(5),
|
||||||
|
try_connect, reach);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct io_plan *conn_init(struct io_conn *conn, struct reaching *reach)
|
static struct io_plan *conn_init(struct io_conn *conn, struct reaching *reach)
|
||||||
@@ -1683,6 +1703,9 @@ static bool try_reach_peer(struct daemon *daemon, const struct pubkey *id)
|
|||||||
reach->succeeded = false;
|
reach->succeeded = false;
|
||||||
reach->daemon = daemon;
|
reach->daemon = daemon;
|
||||||
reach->id = *id;
|
reach->id = *id;
|
||||||
|
reach->first_attempt = time_now().ts.tv_sec;
|
||||||
|
reach->attempts = 0;
|
||||||
|
reach->max_attempts = 10;
|
||||||
list_add_tail(&daemon->reaching, &reach->list);
|
list_add_tail(&daemon->reaching, &reach->list);
|
||||||
tal_add_destructor(reach, destroy_reaching);
|
tal_add_destructor(reach, destroy_reaching);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user