core-lightning/lightningd/peer_failed.c
Rusty Russell 7419fde9a0 Update to new spec: differentiate channel_id and short_channel_id.
The spec 4af8e1841151f0c6e8151979d6c89d11839b2f65 uses a 32-byte 'channel-id'
field, not to be confused with the 8-byte short ID used by gossip.  Rename
appropriately, and update to the new handshake protocol.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30

41 lines
1.0 KiB
C

#include <ccan/tal/str/str.h>
#include <fcntl.h>
#include <lightningd/crypto_sync.h>
#include <lightningd/peer_failed.h>
#include <status.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,
u16 error_code, const char *fmt, ...)
{
va_list ap;
const char *errmsg;
struct channel_id all_channels;
u8 *msg;
/* BOLT #1:
*
* The channel is referred to by `channel-id` unless `channel-id` is
* zero (ie. all bytes zero), in which case it refers to all channels.
*/
if (!channel_id) {
memset(&all_channels, 0, sizeof(all_channels));
channel_id = &all_channels;
}
va_start(ap, fmt);
errmsg = tal_vfmt(NULL, fmt, ap);
va_end(ap);
msg = towire_error(errmsg, channel_id, (const u8 *)errmsg);
/* This is only best-effort; don't block. */
fcntl(peer_fd, F_SETFL, fcntl(peer_fd, F_GETFL) | O_NONBLOCK);
sync_crypto_write(cs, peer_fd, msg);
status_failed(error_code, "%s", errmsg);
}