2021-12-04 21:53:56 +10:30
|
|
|
#include "config.h"
|
2021-02-02 23:19:01 +10:30
|
|
|
#include <assert.h>
|
2019-06-04 03:41:25 +09:30
|
|
|
#include <ccan/breakpoint/breakpoint.h>
|
2017-02-24 16:22:55 +10:30
|
|
|
#include <ccan/tal/str/str.h>
|
2018-02-23 16:23:47 +10:30
|
|
|
#include <common/peer_billboard.h>
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/peer_failed.h>
|
2022-01-08 23:53:29 +10:30
|
|
|
#include <common/peer_io.h>
|
2020-08-25 11:49:38 +09:30
|
|
|
#include <common/peer_status_wiregen.h>
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/status.h>
|
2020-08-25 11:49:38 +09:30
|
|
|
#include <common/status_wiregen.h>
|
2018-01-10 15:16:54 +10:30
|
|
|
#include <common/wire_error.h>
|
2017-02-24 16:22:55 +10:30
|
|
|
|
2019-06-04 03:41:25 +09:30
|
|
|
/* Fatal error here, return peer control to lightningd */
|
2022-12-01 15:36:06 -06:00
|
|
|
void NORETURN
|
2019-06-04 03:41:25 +09:30
|
|
|
peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps)
|
|
|
|
{
|
|
|
|
int reason = fromwire_peektype(msg);
|
|
|
|
breakpoint();
|
|
|
|
status_send(msg);
|
|
|
|
|
|
|
|
status_send_fd(pps->peer_fd);
|
|
|
|
exit(0x80 | (reason & 0xFF));
|
|
|
|
}
|
|
|
|
|
2017-02-24 16:22:55 +10:30
|
|
|
/* We only support one channel per peer anyway */
|
2021-02-02 23:19:01 +10:30
|
|
|
static void NORETURN
|
|
|
|
peer_failed(struct per_peer_state *pps,
|
2023-10-22 14:37:31 +10:30
|
|
|
bool disconnect,
|
2021-02-02 23:19:01 +10:30
|
|
|
bool warn,
|
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *desc)
|
2017-02-24 16:22:55 +10:30
|
|
|
{
|
2021-02-02 23:19:01 +10:30
|
|
|
u8 *msg;
|
2018-01-10 15:16:54 +10:30
|
|
|
|
2021-02-02 23:19:01 +10:30
|
|
|
if (warn) {
|
|
|
|
msg = towire_warningfmt(desc, channel_id, "%s", desc);
|
|
|
|
} else {
|
|
|
|
msg = towire_errorfmt(desc, channel_id, "%s", desc);
|
|
|
|
}
|
2022-01-08 23:53:29 +10:30
|
|
|
peer_write(pps, msg);
|
2018-08-09 09:55:29 +09:30
|
|
|
|
|
|
|
/* Tell master the error so it can re-xmit. */
|
2023-09-12 10:13:04 +09:30
|
|
|
msg = towire_status_peer_error(NULL,
|
2023-10-22 14:37:31 +10:30
|
|
|
disconnect,
|
2021-02-02 23:17:01 +10:30
|
|
|
desc,
|
2021-02-02 23:19:01 +10:30
|
|
|
warn,
|
|
|
|
msg);
|
2018-02-23 16:23:47 +10:30
|
|
|
peer_billboard(true, desc);
|
2019-06-04 03:41:25 +09:30
|
|
|
peer_fatal_continue(take(msg), pps);
|
2018-02-19 11:36:15 +10:30
|
|
|
}
|
|
|
|
|
2021-02-02 23:19:01 +10:30
|
|
|
void peer_failed_warn(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);
|
|
|
|
|
2023-10-22 14:37:31 +10:30
|
|
|
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);
|
2021-02-02 23:19:01 +10:30
|
|
|
}
|
|
|
|
|
|
|
|
void peer_failed_err(struct per_peer_state *pps,
|
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
const char *desc;
|
|
|
|
|
2021-02-03 13:21:41 +10:30
|
|
|
assert(channel_id);
|
2021-02-02 23:19:01 +10:30
|
|
|
va_start(ap, fmt);
|
|
|
|
desc = tal_vfmt(tmpctx, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2023-10-22 14:37:31 +10:30
|
|
|
peer_failed(pps, true, false, channel_id, desc);
|
2021-02-02 23:19:01 +10:30
|
|
|
}
|
|
|
|
|
2021-02-02 23:16:01 +10:30
|
|
|
/* We're failing because peer sent us an error/warning message */
|
2019-06-04 03:41:25 +09:30
|
|
|
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
2023-10-22 14:37:31 +10:30
|
|
|
bool disconnect,
|
|
|
|
const char *desc)
|
2018-02-19 11:36:15 +10:30
|
|
|
{
|
2018-08-02 16:19:55 +09:30
|
|
|
u8 *msg;
|
|
|
|
|
2023-10-22 14:37:31 +10:30
|
|
|
msg = towire_status_peer_error(NULL, disconnect, desc, false, NULL);
|
2021-02-02 23:16:01 +10:30
|
|
|
peer_billboard(true, "Received %s", desc);
|
2019-06-04 03:41:25 +09:30
|
|
|
peer_fatal_continue(take(msg), pps);
|
2018-02-19 11:36:15 +10:30
|
|
|
}
|
|
|
|
|
|
|
|
void peer_failed_connection_lost(void)
|
|
|
|
{
|
2019-06-04 03:41:25 +09:30
|
|
|
status_send_fatal(take(towire_status_peer_connection_lost(NULL)));
|
2017-02-24 16:22:55 +10:30
|
|
|
}
|