2021-02-01 13:28:50 +10:30
|
|
|
#include "config.h"
|
2019-12-04 23:02:54 +01:00
|
|
|
#include <assert.h>
|
2021-05-09 02:39:41 +05:30
|
|
|
#include <bitcoin/chainparams.h>
|
2018-02-19 11:36:15 +10:30
|
|
|
#include <common/peer_failed.h>
|
2022-01-08 23:53:29 +10:30
|
|
|
#include <common/peer_io.h>
|
2019-06-04 03:41:25 +09:30
|
|
|
#include <common/per_peer_state.h>
|
2021-10-07 23:23:18 +10:30
|
|
|
#include <common/ping.h>
|
2018-01-31 13:23:35 +10:30
|
|
|
#include <common/read_peer_msg.h>
|
|
|
|
#include <common/status.h>
|
|
|
|
#include <common/wire_error.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <wire/peer_wire.h>
|
|
|
|
#include <wire/wire_sync.h>
|
|
|
|
|
2023-09-12 13:53:14 +09:30
|
|
|
const char *is_peer_warning(const tal_t *ctx, const u8 *msg)
|
2018-08-02 16:19:55 +09:30
|
|
|
{
|
2023-09-12 13:53:14 +09:30
|
|
|
if (fromwire_peektype(msg) != WIRE_WARNING)
|
|
|
|
return NULL;
|
|
|
|
/* connectd demuxes, so we only see it if channel_id is ours. */
|
|
|
|
return sanitize_error(ctx, msg, NULL);
|
2018-08-02 16:19:55 +09:30
|
|
|
}
|
|
|
|
|
2023-09-12 13:53:14 +09:30
|
|
|
const char *is_peer_error(const tal_t *ctx, const u8 *msg)
|
2018-08-02 16:19:55 +09:30
|
|
|
{
|
2023-09-12 13:53:14 +09:30
|
|
|
if (fromwire_peektype(msg) != WIRE_ERROR)
|
|
|
|
return NULL;
|
|
|
|
/* connectd demuxes, so we only see it if channel_id is ours. */
|
|
|
|
return sanitize_error(ctx, msg, NULL);
|
|
|
|
}
|
2021-02-02 23:17:01 +10:30
|
|
|
|
2023-09-12 13:53:14 +09:30
|
|
|
bool handle_peer_error_or_warning(struct per_peer_state *pps,
|
|
|
|
const u8 *msg TAKES)
|
|
|
|
{
|
|
|
|
const char *err;
|
|
|
|
|
|
|
|
err = is_peer_error(tmpctx, msg);
|
|
|
|
if (err)
|
|
|
|
peer_failed_received_errmsg(pps, err, false);
|
|
|
|
|
|
|
|
/* Simply log incoming warnings */
|
|
|
|
err = is_peer_warning(tmpctx, msg);
|
|
|
|
if (err) {
|
|
|
|
if (taken(msg))
|
|
|
|
tal_free(msg);
|
|
|
|
status_info("Received %s", err);
|
|
|
|
return true;
|
2018-08-02 16:19:55 +09:30
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|