common: add peer_failed_warn_nodisconnect routine for non-disconnecting warnings
We generalize the current df-only "aborted" flag (and invert it) to a "disconnected" flag in the peer status message. We convert it back to the aborted flag for now inside subd.c, but that's next. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -25,6 +25,7 @@ peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps)
|
|||||||
/* We only support one channel per peer anyway */
|
/* We only support one channel per peer anyway */
|
||||||
static void NORETURN
|
static void NORETURN
|
||||||
peer_failed(struct per_peer_state *pps,
|
peer_failed(struct per_peer_state *pps,
|
||||||
|
bool disconnect,
|
||||||
bool warn,
|
bool warn,
|
||||||
const struct channel_id *channel_id,
|
const struct channel_id *channel_id,
|
||||||
const char *desc)
|
const char *desc)
|
||||||
@@ -40,9 +41,9 @@ peer_failed(struct per_peer_state *pps,
|
|||||||
|
|
||||||
/* Tell master the error so it can re-xmit. */
|
/* Tell master the error so it can re-xmit. */
|
||||||
msg = towire_status_peer_error(NULL,
|
msg = towire_status_peer_error(NULL,
|
||||||
|
disconnect,
|
||||||
desc,
|
desc,
|
||||||
warn,
|
warn,
|
||||||
false,
|
|
||||||
msg);
|
msg);
|
||||||
peer_billboard(true, desc);
|
peer_billboard(true, desc);
|
||||||
peer_fatal_continue(take(msg), pps);
|
peer_fatal_continue(take(msg), pps);
|
||||||
@@ -59,7 +60,21 @@ void peer_failed_warn(struct per_peer_state *pps,
|
|||||||
desc = tal_vfmt(tmpctx, fmt, ap);
|
desc = tal_vfmt(tmpctx, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
peer_failed(pps, true, channel_id, desc);
|
peer_failed(pps, true, true, channel_id, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void peer_failed_warn_nodisconnect(struct per_peer_state *pps,
|
||||||
|
const struct channel_id *channel_id,
|
||||||
|
const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
const char *desc;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
desc = tal_vfmt(tmpctx, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
peer_failed(pps, false, true, channel_id, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void peer_failed_err(struct per_peer_state *pps,
|
void peer_failed_err(struct per_peer_state *pps,
|
||||||
@@ -74,17 +89,17 @@ void peer_failed_err(struct per_peer_state *pps,
|
|||||||
desc = tal_vfmt(tmpctx, fmt, ap);
|
desc = tal_vfmt(tmpctx, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
peer_failed(pps, false, channel_id, desc);
|
peer_failed(pps, true, false, channel_id, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're failing because peer sent us an error/warning message */
|
/* We're failing because peer sent us an error/warning message */
|
||||||
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
||||||
const char *desc,
|
bool disconnect,
|
||||||
bool abort_restart)
|
const char *desc)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
|
||||||
msg = towire_status_peer_error(NULL, desc, false, abort_restart, NULL);
|
msg = towire_status_peer_error(NULL, disconnect, desc, false, NULL);
|
||||||
peer_billboard(true, "Received %s", desc);
|
peer_billboard(true, "Received %s", desc);
|
||||||
peer_fatal_continue(take(msg), pps);
|
peer_fatal_continue(take(msg), pps);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,17 @@ void peer_failed_warn(struct per_peer_state *pps,
|
|||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
PRINTF_FMT(3,4) NORETURN;
|
PRINTF_FMT(3,4) NORETURN;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* peer_failed_warn_nodisconnect - Send a warning msg, don't close.
|
||||||
|
* @pps: the per-peer state.
|
||||||
|
* @channel_id: channel with error, or NULL for no particular channel.
|
||||||
|
* @fmt...: format as per status_failed(STATUS_FAIL_PEER_BAD)
|
||||||
|
*/
|
||||||
|
void peer_failed_warn_nodisconnect(struct per_peer_state *pps,
|
||||||
|
const struct channel_id *channel_id,
|
||||||
|
const char *fmt, ...)
|
||||||
|
PRINTF_FMT(3,4) NORETURN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* peer_failed_err - Send a warning msg and close the channel.
|
* peer_failed_err - Send a warning msg and close the channel.
|
||||||
* @pps: the per-peer state.
|
* @pps: the per-peer state.
|
||||||
@@ -35,8 +46,8 @@ void peer_failed_err(struct per_peer_state *pps,
|
|||||||
/* We're failing because peer sent us an error message: NULL
|
/* We're failing because peer sent us an error message: NULL
|
||||||
* channel_id means all channels. */
|
* channel_id means all channels. */
|
||||||
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
||||||
const char *desc,
|
bool disconnect,
|
||||||
bool abort_restart)
|
const char *desc)
|
||||||
NORETURN;
|
NORETURN;
|
||||||
|
|
||||||
/* I/O error */
|
/* I/O error */
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
|
|
||||||
# An error occurred: if error_for_them, that to go to them.
|
# An error occurred: if error_for_them, that to go to them.
|
||||||
msgtype,status_peer_error,0xFFF4
|
msgtype,status_peer_error,0xFFF4
|
||||||
|
# Do we force a disconnect from the peer?
|
||||||
|
msgdata,status_peer_error,disconnect,bool,
|
||||||
|
# The error string
|
||||||
msgdata,status_peer_error,desc,wirestring,
|
msgdata,status_peer_error,desc,wirestring,
|
||||||
# Take a deep breath, then try reconnecting to the precious little snowflake.
|
# Actually a warning, not a (fatal!) error.
|
||||||
# (Means we sent it, since we don't hang up if they send one)
|
|
||||||
msgdata,status_peer_error,warning,bool,
|
msgdata,status_peer_error,warning,bool,
|
||||||
# From an abort, no reconnect but restart daemon
|
# The error to send to them in future if they try to talk to us about
|
||||||
msgdata,status_peer_error,abort_do_restart,bool,
|
# this channel.
|
||||||
msgdata,status_peer_error,len,u16,
|
msgdata,status_peer_error,len,u16,
|
||||||
msgdata,status_peer_error,error_for_them,u8,len
|
msgdata,status_peer_error,error_for_them,u8,len
|
||||||
|
|||||||
|
@@ -35,7 +35,7 @@ bool handle_peer_error_or_warning(struct per_peer_state *pps,
|
|||||||
|
|
||||||
err = is_peer_error(tmpctx, msg);
|
err = is_peer_error(tmpctx, msg);
|
||||||
if (err)
|
if (err)
|
||||||
peer_failed_received_errmsg(pps, err, false);
|
peer_failed_received_errmsg(pps, true, err);
|
||||||
|
|
||||||
/* Simply log incoming warnings */
|
/* Simply log incoming warnings */
|
||||||
err = is_peer_warning(tmpctx, msg);
|
err = is_peer_warning(tmpctx, msg);
|
||||||
|
|||||||
@@ -422,18 +422,18 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[1])
|
|||||||
struct peer_fd *peer_fd;
|
struct peer_fd *peer_fd;
|
||||||
u8 *err_for_them;
|
u8 *err_for_them;
|
||||||
bool warning;
|
bool warning;
|
||||||
bool aborted;
|
bool disconnect;
|
||||||
|
|
||||||
if (!fromwire_status_peer_error(msg, msg,
|
if (!fromwire_status_peer_error(msg, msg,
|
||||||
&desc, &warning,
|
&disconnect, &desc, &warning,
|
||||||
&aborted, &err_for_them))
|
&err_for_them))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
peer_fd = new_peer_fd_arr(msg, fds);
|
peer_fd = new_peer_fd_arr(msg, fds);
|
||||||
|
|
||||||
/* Don't free sd; we may be about to free channel. */
|
/* Don't free sd; we may be about to free channel. */
|
||||||
sd->channel = NULL;
|
sd->channel = NULL;
|
||||||
sd->errcb(channel, peer_fd, desc, warning, aborted, err_for_them);
|
sd->errcb(channel, peer_fd, desc, warning, !disconnect, err_for_them);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ bool fromwire_status_fail(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, enu
|
|||||||
bool fromwire_status_peer_billboard(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *perm UNNEEDED, wirestring **happenings UNNEEDED)
|
bool fromwire_status_peer_billboard(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *perm UNNEEDED, wirestring **happenings UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_status_peer_billboard called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_status_peer_billboard called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_status_peer_error */
|
/* Generated stub for fromwire_status_peer_error */
|
||||||
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **desc UNNEEDED, bool *warning UNNEEDED, bool *abort_do_restart UNNEEDED, u8 **error_for_them UNNEEDED)
|
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *disconnect UNNEEDED, wirestring **desc UNNEEDED, bool *warning UNNEEDED, u8 **error_for_them UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_status_peer_error called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_status_peer_error called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_status_version */
|
/* Generated stub for fromwire_status_version */
|
||||||
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
|
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ bool fromwire_status_fail(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, enu
|
|||||||
bool fromwire_status_peer_billboard(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *perm UNNEEDED, wirestring **happenings UNNEEDED)
|
bool fromwire_status_peer_billboard(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *perm UNNEEDED, wirestring **happenings UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_status_peer_billboard called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_status_peer_billboard called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_status_peer_error */
|
/* Generated stub for fromwire_status_peer_error */
|
||||||
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **desc UNNEEDED, bool *warning UNNEEDED, bool *abort_do_restart UNNEEDED, u8 **error_for_them UNNEEDED)
|
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *disconnect UNNEEDED, wirestring **desc UNNEEDED, bool *warning UNNEEDED, u8 **error_for_them UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_status_peer_error called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_status_peer_error called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_status_version */
|
/* Generated stub for fromwire_status_version */
|
||||||
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
|
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
|
||||||
|
|||||||
@@ -333,8 +333,8 @@ static void negotiation_aborted(struct state *state, const char *why, bool abort
|
|||||||
{
|
{
|
||||||
status_debug("aborted opening negotiation: %s", why);
|
status_debug("aborted opening negotiation: %s", why);
|
||||||
|
|
||||||
/* Tell master that funding failed. */
|
/* Tell master that funding failed (don't disconnect if we aborted) */
|
||||||
peer_failed_received_errmsg(state->pps, why, aborted);
|
peer_failed_received_errmsg(state->pps, !aborted, why);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Softer version of 'warning' (we don't disconnect)
|
/* Softer version of 'warning' (we don't disconnect)
|
||||||
|
|||||||
Reference in New Issue
Block a user