2019-06-03 20:11:25 +02:00
|
|
|
#include <ccan/breakpoint/breakpoint.h>
|
2017-02-24 06:52:55 +01:00
|
|
|
#include <ccan/tal/str/str.h>
|
2018-08-09 02:25:29 +02:00
|
|
|
#include <common/crypto_sync.h>
|
2018-02-19 02:06:15 +01:00
|
|
|
#include <common/gen_peer_status_wire.h>
|
|
|
|
#include <common/gen_status_wire.h>
|
2018-02-23 06:53:47 +01:00
|
|
|
#include <common/peer_billboard.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/peer_failed.h>
|
|
|
|
#include <common/status.h>
|
2018-01-10 05:46:54 +01:00
|
|
|
#include <common/wire_error.h>
|
2017-02-24 06:52:55 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2019-06-03 20:11:25 +02:00
|
|
|
/* Fatal error here, return peer control to lightningd */
|
|
|
|
static void NORETURN
|
|
|
|
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);
|
|
|
|
status_send_fd(pps->gossip_fd);
|
|
|
|
status_send_fd(pps->gossip_store_fd);
|
|
|
|
exit(0x80 | (reason & 0xFF));
|
|
|
|
}
|
|
|
|
|
2017-02-24 06:52:55 +01:00
|
|
|
/* We only support one channel per peer anyway */
|
2019-06-03 20:11:25 +02:00
|
|
|
void peer_failed(struct per_peer_state *pps,
|
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *fmt, ...)
|
2017-02-24 06:52:55 +01:00
|
|
|
{
|
|
|
|
va_list ap;
|
2018-02-08 02:25:12 +01:00
|
|
|
const char *desc;
|
2018-08-09 02:25:29 +02:00
|
|
|
u8 *msg, *err;
|
2017-02-24 06:52:55 +01:00
|
|
|
|
2018-02-08 02:25:12 +01:00
|
|
|
va_start(ap, fmt);
|
|
|
|
desc = tal_vfmt(NULL, fmt, ap);
|
2017-02-24 06:52:55 +01:00
|
|
|
va_end(ap);
|
2018-01-10 05:46:54 +01:00
|
|
|
|
2018-08-09 02:25:29 +02:00
|
|
|
/* Tell peer the error. */
|
|
|
|
err = towire_errorfmt(desc, channel_id, "%s", desc);
|
2019-06-03 20:11:25 +02:00
|
|
|
sync_crypto_write(pps, err);
|
2018-08-09 02:25:29 +02:00
|
|
|
|
|
|
|
/* Tell master the error so it can re-xmit. */
|
2018-02-19 02:06:15 +01:00
|
|
|
msg = towire_status_peer_error(NULL, channel_id,
|
2019-07-26 04:11:19 +02:00
|
|
|
desc, false, pps,
|
2018-08-09 02:25:29 +02:00
|
|
|
err);
|
2018-02-23 06:53:47 +01:00
|
|
|
peer_billboard(true, desc);
|
2018-02-19 02:06:15 +01:00
|
|
|
tal_free(desc);
|
2019-06-03 20:11:25 +02:00
|
|
|
peer_fatal_continue(take(msg), pps);
|
2018-02-19 02:06:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We're failing because peer sent us an error message */
|
2019-06-03 20:11:25 +02:00
|
|
|
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
2018-02-19 02:06:15 +01:00
|
|
|
const char *desc,
|
|
|
|
const struct channel_id *channel_id)
|
|
|
|
{
|
2018-08-02 08:49:55 +02:00
|
|
|
static const struct channel_id all_channels;
|
|
|
|
u8 *msg;
|
2019-07-26 04:11:29 +02:00
|
|
|
bool sync_error;
|
|
|
|
|
|
|
|
/* <+roasbeef> rusty: sync error can just be a timing thing
|
|
|
|
* <+roasbeef> andn doesn't always mean that we can't continue forwrd,
|
|
|
|
* or y'all sent the wrong info
|
|
|
|
*/
|
|
|
|
/* So while LND is sitting in the corner eating paint, back off. */
|
|
|
|
sync_error = strstr(desc, "sync error");
|
|
|
|
if (sync_error)
|
|
|
|
status_unusual("Peer said '%s' so we'll come back later",
|
|
|
|
desc);
|
2018-08-02 08:49:55 +02:00
|
|
|
|
|
|
|
if (!channel_id)
|
|
|
|
channel_id = &all_channels;
|
2019-07-26 04:11:29 +02:00
|
|
|
msg = towire_status_peer_error(NULL, channel_id, desc, sync_error, pps,
|
|
|
|
NULL);
|
2018-02-23 06:53:47 +01:00
|
|
|
peer_billboard(true, "Received error from peer: %s", desc);
|
2019-06-03 20:11:25 +02:00
|
|
|
peer_fatal_continue(take(msg), pps);
|
2018-02-19 02:06:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void peer_failed_connection_lost(void)
|
|
|
|
{
|
2019-06-03 20:11:25 +02:00
|
|
|
status_send_fatal(take(towire_status_peer_connection_lost(NULL)));
|
2017-02-24 06:52:55 +01:00
|
|
|
}
|