2017-02-24 06:52:55 +01:00
|
|
|
#include <ccan/tal/str/str.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>
|
|
|
|
|
|
|
|
/* We only support one channel per peer anyway */
|
2018-02-19 02:06:14 +01:00
|
|
|
void peer_failed_(int peer_fd, int gossip_fd,
|
|
|
|
struct crypto_state *cs, u64 gossip_index,
|
|
|
|
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;
|
2017-02-24 06:52:55 +01:00
|
|
|
u8 *msg;
|
|
|
|
|
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-02-19 02:06:15 +01:00
|
|
|
msg = towire_status_peer_error(NULL, channel_id,
|
2018-02-19 02:06:15 +01:00
|
|
|
desc, cs, gossip_index,
|
|
|
|
towire_errorfmt(desc, channel_id,
|
|
|
|
"%s", desc));
|
2018-02-23 06:53:47 +01:00
|
|
|
peer_billboard(true, desc);
|
2018-02-19 02:06:15 +01:00
|
|
|
tal_free(desc);
|
2018-02-19 02:06:15 +01:00
|
|
|
status_send_fatal(take(msg), peer_fd, gossip_fd);
|
2018-02-19 02:06:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We're failing because peer sent us an error message */
|
|
|
|
void peer_failed_received_errmsg(int peer_fd, int gossip_fd,
|
|
|
|
struct crypto_state *cs, u64 gossip_index,
|
|
|
|
const char *desc,
|
|
|
|
const struct channel_id *channel_id)
|
|
|
|
{
|
|
|
|
u8 *msg = towire_status_peer_error(NULL, channel_id,
|
|
|
|
desc, cs, gossip_index, NULL);
|
2018-02-23 06:53:47 +01:00
|
|
|
peer_billboard(true, "Received error from peer: %s", desc);
|
2018-02-19 02:06:15 +01:00
|
|
|
status_send_fatal(take(msg), peer_fd, gossip_fd);
|
2018-02-19 02:06:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void peer_failed_connection_lost(void)
|
|
|
|
{
|
2018-02-19 02:06:15 +01:00
|
|
|
status_send_fatal(take(towire_status_peer_connection_lost(NULL)),
|
|
|
|
-1, -1);
|
2017-02-24 06:52:55 +01:00
|
|
|
}
|