mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
lightningd: peer_fail helper to fail/reconnect peer.
This will eventually hook into restart logic. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -38,9 +38,8 @@ static void peer_bad_message(struct subd *gossip, const u8 *msg)
|
|||||||
log_debug(gossip->log, "Peer %s gave bad msg %s",
|
log_debug(gossip->log, "Peer %s gave bad msg %s",
|
||||||
type_to_string(msg, struct pubkey, peer->id),
|
type_to_string(msg, struct pubkey, peer->id),
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
peer_set_condition(peer, "Bad message %s during gossip phase",
|
peer_fail(peer, "Bad message %s during gossip phase",
|
||||||
gossip_wire_type_name(fromwire_peektype(msg)));
|
gossip_wire_type_name(fromwire_peektype(msg)));
|
||||||
tal_free(peer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peer_failed(struct subd *gossip, const u8 *msg)
|
static void peer_failed(struct subd *gossip, const u8 *msg)
|
||||||
@@ -61,8 +60,7 @@ static void peer_failed(struct subd *gossip, const u8 *msg)
|
|||||||
log_unusual(gossip->log, "Peer %s failed: %.*s",
|
log_unusual(gossip->log, "Peer %s failed: %.*s",
|
||||||
type_to_string(msg, struct pubkey, peer->id),
|
type_to_string(msg, struct pubkey, peer->id),
|
||||||
(int)tal_len(err), (const char *)err);
|
(int)tal_len(err), (const char *)err);
|
||||||
peer_set_condition(peer, "Error during gossip phase");
|
peer_fail(peer, "Error during gossip phase");
|
||||||
tal_free(peer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peer_nongossip(struct subd *gossip, const u8 *msg,
|
static void peer_nongossip(struct subd *gossip, const u8 *msg,
|
||||||
|
|||||||
@@ -43,6 +43,18 @@ static void destroy_peer(struct peer *peer)
|
|||||||
peer->condition);
|
peer->condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void peer_fail(struct peer *peer, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
log_unusual(peer->log, "Peer has failed: ");
|
||||||
|
logv(peer->log, -1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
tal_free(peer);
|
||||||
|
}
|
||||||
|
|
||||||
void peer_set_condition(struct peer *peer, const char *fmt, ...)
|
void peer_set_condition(struct peer *peer, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@@ -169,8 +181,8 @@ static bool peer_got_handshake_hsmfd(struct subd *hsm, const u8 *msg,
|
|||||||
|
|
||||||
assert(tal_count(fds) == 1);
|
assert(tal_count(fds) == 1);
|
||||||
if (!fromwire_hsmctl_hsmfd_ecdh_fd_reply(msg, NULL)) {
|
if (!fromwire_hsmctl_hsmfd_ecdh_fd_reply(msg, NULL)) {
|
||||||
log_unusual(peer->ld->log, "Malformed hsmfd response: %s",
|
peer_fail(peer, "Malformed hsmfd response: %s",
|
||||||
tal_hex(peer, msg));
|
tal_hex(peer, msg));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,9 +194,8 @@ static bool peer_got_handshake_hsmfd(struct subd *hsm, const u8 *msg,
|
|||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
fds[0], peer->fd, -1);
|
fds[0], peer->fd, -1);
|
||||||
if (!peer->owner) {
|
if (!peer->owner) {
|
||||||
log_unusual(peer->ld->log, "Could not subdaemon handshake: %s",
|
peer_fail(peer, "Could not subdaemon handshake: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
peer_set_condition(peer, "Failed to subdaemon handshake");
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +218,6 @@ static bool peer_got_handshake_hsmfd(struct subd *hsm, const u8 *msg,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
tal_free(peer);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1391,8 +1401,7 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
|
|||||||
if (!cds->peer->owner) {
|
if (!cds->peer->owner) {
|
||||||
log_unusual(cds->peer->log, "Could not subdaemon channel: %s",
|
log_unusual(cds->peer->log, "Could not subdaemon channel: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
peer_set_condition(cds->peer, "Failed to subdaemon channel");
|
peer_fail(cds->peer, "Failed to subdaemon channel");
|
||||||
tal_free(cds->peer);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
cds->peer->fd = -1;
|
cds->peer->fd = -1;
|
||||||
@@ -1672,8 +1681,8 @@ void peer_accept_open(struct peer *peer,
|
|||||||
if (fromwire_peektype(from_peer) != WIRE_OPEN_CHANNEL) {
|
if (fromwire_peektype(from_peer) != WIRE_OPEN_CHANNEL) {
|
||||||
log_unusual(peer->log, "Strange message to exit gossip: %u",
|
log_unusual(peer->log, "Strange message to exit gossip: %u",
|
||||||
fromwire_peektype(from_peer));
|
fromwire_peektype(from_peer));
|
||||||
peer_set_condition(peer, "Bad message during gossiping");
|
peer_fail(peer, "Bad message during gossiping: %s",
|
||||||
tal_free(peer);
|
tal_hex(peer, from_peer));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1683,10 +1692,8 @@ void peer_accept_open(struct peer *peer,
|
|||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
peer->fd, -1);
|
peer->fd, -1);
|
||||||
if (!peer->owner) {
|
if (!peer->owner) {
|
||||||
log_unusual(ld->log, "Could not subdaemon opening: %s",
|
peer_fail(peer, "Failed to subdaemon opening: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
peer_set_condition(peer, "Failed to subdaemon opening");
|
|
||||||
tal_free(peer);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* We handed off peer fd */
|
/* We handed off peer fd */
|
||||||
@@ -1716,8 +1723,7 @@ void peer_accept_open(struct peer *peer,
|
|||||||
|
|
||||||
/* Careful here! Their message could push us overlength! */
|
/* Careful here! Their message could push us overlength! */
|
||||||
if (tal_len(msg) >= 65536) {
|
if (tal_len(msg) >= 65536) {
|
||||||
peer_set_condition(peer, "Unacceptably long open_channel");
|
peer_fail(peer, "Unacceptably long open_channel");
|
||||||
tal_free(peer);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
subd_req(peer, peer->owner, take(msg), -1, 0, opening_accept_reply, peer);
|
subd_req(peer, peer->owner, take(msg), -1, 0, opening_accept_reply, peer);
|
||||||
@@ -1756,10 +1762,8 @@ static bool gossip_peer_released(struct subd *gossip,
|
|||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
fc->peer->fd, -1);
|
fc->peer->fd, -1);
|
||||||
if (!opening) {
|
if (!opening) {
|
||||||
log_unusual(ld->log, "Could not subdaemon opening: %s",
|
peer_fail(fc->peer, "Failed to subdaemon opening: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
peer_set_condition(fc->peer, "Failed to subdaemon opening");
|
|
||||||
tal_free(fc->peer);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fc->peer->owner = opening;
|
fc->peer->owner = opening;
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ struct peer *peer_from_json(struct lightningd *ld,
|
|||||||
void peer_accept_open(struct peer *peer,
|
void peer_accept_open(struct peer *peer,
|
||||||
const struct crypto_state *cs, const u8 *msg);
|
const struct crypto_state *cs, const u8 *msg);
|
||||||
|
|
||||||
|
/* Peer has failed. */
|
||||||
|
PRINTF_FMT(2,3) void peer_fail(struct peer *peer, const char *fmt, ...);
|
||||||
|
|
||||||
PRINTF_FMT(2,3) void peer_set_condition(struct peer *peer, const char *fmt, ...);
|
PRINTF_FMT(2,3) void peer_set_condition(struct peer *peer, const char *fmt, ...);
|
||||||
void setup_listeners(struct lightningd *ld);
|
void setup_listeners(struct lightningd *ld);
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */
|
#endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ void peer_failed(int peer_fd, struct crypto_state *cs,
|
|||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
errmsg = tal_vfmt(NULL, fmt, ap);
|
errmsg = tal_vfmt(NULL, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
/* Make sure it's correct length for error. */
|
||||||
|
tal_resize(&errmsg, strlen(errmsg)+1);
|
||||||
msg = towire_error(errmsg, channel_id, (const u8 *)errmsg);
|
msg = towire_error(errmsg, channel_id, (const u8 *)errmsg);
|
||||||
|
|
||||||
/* This is only best-effort; don't block. */
|
/* This is only best-effort; don't block. */
|
||||||
|
|||||||
Reference in New Issue
Block a user