2017-07-04 10:17:02 +09:30
|
|
|
#include <ccan/io/io.h>
|
2017-02-24 16:22:55 +10:30
|
|
|
#include <ccan/tal/str/str.h>
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/crypto_sync.h>
|
|
|
|
#include <common/peer_failed.h>
|
|
|
|
#include <common/status.h>
|
2018-01-10 15:16:54 +10:30
|
|
|
#include <common/wire_error.h>
|
2017-02-24 16:22:55 +10:30
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <wire/gen_peer_wire.h>
|
|
|
|
|
|
|
|
/* We only support one channel per peer anyway */
|
|
|
|
void peer_failed(int peer_fd, struct crypto_state *cs,
|
|
|
|
const struct channel_id *channel_id,
|
2017-09-12 14:25:52 +09:30
|
|
|
const char *fmt, ...)
|
2017-02-24 16:22:55 +10:30
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
const char *errmsg;
|
|
|
|
struct channel_id all_channels;
|
|
|
|
u8 *msg;
|
|
|
|
|
|
|
|
/* BOLT #1:
|
|
|
|
*
|
2017-06-06 09:18:10 +09:30
|
|
|
* The channel is referred to by `channel_id` unless `channel_id` is
|
2017-03-02 22:51:49 +10:30
|
|
|
* zero (ie. all bytes zero), in which case it refers to all channels.
|
2017-02-24 16:22:55 +10:30
|
|
|
*/
|
|
|
|
if (!channel_id) {
|
2017-03-02 22:51:49 +10:30
|
|
|
memset(&all_channels, 0, sizeof(all_channels));
|
2017-02-24 16:22:55 +10:30
|
|
|
channel_id = &all_channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
errmsg = tal_vfmt(NULL, fmt, ap);
|
|
|
|
va_end(ap);
|
2018-01-10 15:16:54 +10:30
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
msg = towire_errorfmtv(errmsg, channel_id, fmt, ap);
|
|
|
|
va_end(ap);
|
2017-02-24 16:22:55 +10:30
|
|
|
|
|
|
|
/* This is only best-effort; don't block. */
|
2017-07-04 10:17:02 +09:30
|
|
|
io_fd_block(peer_fd, false);
|
2017-06-27 12:25:06 +09:30
|
|
|
sync_crypto_write(cs, peer_fd, take(msg));
|
2017-02-24 16:22:55 +10:30
|
|
|
|
2017-09-12 14:25:52 +09:30
|
|
|
status_failed(STATUS_FAIL_PEER_BAD, "%s", errmsg);
|
2017-02-24 16:22:55 +10:30
|
|
|
}
|