diff --git a/channeld/channel.c b/channeld/channel.c index 884c82ac5..abc81c653 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -247,7 +247,7 @@ static bool peer_write_pending(struct peer *peer) if (!msg) return false; - status_io(LOG_IO_OUT, msg); + status_peer_io(LOG_IO_OUT, msg); peer->peer_outmsg = cryptomsg_encrypt_msg(peer, &peer->cs, take(msg)); peer->peer_outoff = 0; return true; diff --git a/common/crypto_sync.c b/common/crypto_sync.c index 686b85338..5d1cdc374 100644 --- a/common/crypto_sync.c +++ b/common/crypto_sync.c @@ -18,7 +18,7 @@ bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES) u8 *enc; bool ret; - status_io(LOG_IO_OUT, msg); + status_peer_io(LOG_IO_OUT, msg); enc = cryptomsg_encrypt_msg(NULL, cs, msg); #if DEVELOPER @@ -74,7 +74,7 @@ u8 *sync_crypto_read(const tal_t *ctx, struct crypto_state *cs, int fd) if (!dec) status_trace("Failed body decrypt with rn=%"PRIu64, cs->rn-2); else - status_io(LOG_IO_IN, dec); + status_peer_io(LOG_IO_IN, dec); return dec; } diff --git a/common/cryptomsg.c b/common/cryptomsg.c index cb2669727..100f9eb12 100644 --- a/common/cryptomsg.c +++ b/common/cryptomsg.c @@ -137,7 +137,7 @@ static struct io_plan *peer_decrypt_body(struct io_conn *conn, if (!decrypted) return io_close(conn); - status_io(LOG_IO_IN, decrypted); + status_peer_io(LOG_IO_IN, decrypted); /* BOLT #1: * @@ -351,7 +351,7 @@ struct io_plan *peer_write_message(struct io_conn *conn, assert(!pcs->out); /* Important: this doesn't take msg! */ - status_io(LOG_IO_OUT, msg); + status_peer_io(LOG_IO_OUT, msg); pcs->out = cryptomsg_encrypt_msg(conn, &pcs->cs, msg); pcs->next_out = next; diff --git a/common/status.c b/common/status.c index e061ea102..66a268d9c 100644 --- a/common/status.c +++ b/common/status.c @@ -62,25 +62,34 @@ void status_send(const u8 *msg TAKES) } } -static void status_io_full(enum log_level iodir, const u8 *p) +static void status_io_full(enum log_level iodir, const char *who, const u8 *p) { - status_send(take(towire_status_io(NULL, iodir, p))); + status_send(take(towire_status_io(NULL, iodir, who, p))); } -static void status_io_short(enum log_level iodir, const u8 *p) +static void status_peer_io_short(enum log_level iodir, const u8 *p) { status_debug("%s %s", iodir == LOG_IO_OUT ? "peer_out" : "peer_in", wire_type_name(fromwire_peektype(p))); } -void status_io(enum log_level iodir, const u8 *p) +void status_peer_io(enum log_level iodir, const u8 *p) { if (logging_io) - status_io_full(iodir, p); + status_io_full(iodir, "", p); /* We get a huge amount of gossip; don't log it */ else if (!is_msg_for_gossipd(p)) - status_io_short(iodir, p); + status_peer_io_short(iodir, p); +} + +void status_io(enum log_level iodir, const char *who, + const void *data, size_t len) +{ + if (!logging_io) + return; + /* Horribly inefficient, but so is logging IO generally. */ + status_io_full(iodir, who, tal_dup_arr(tmpctx, u8, data, len, 0)); } void status_vfmt(enum log_level level, const char *fmt, va_list ap) diff --git a/common/status.h b/common/status.h index 6e9bbbe0b..855e1d3d8 100644 --- a/common/status.h +++ b/common/status.h @@ -25,7 +25,9 @@ void status_vfmt(enum log_level level, const char *fmt, va_list ap); /* Usually we only log the packet names, not contents. */ extern volatile bool logging_io; -void status_io(enum log_level iodir, const u8 *p); +void status_peer_io(enum log_level iodir, const u8 *p); +void status_io(enum log_level iodir, const char *who, + const void *data, size_t len); /* Helpers */ #define status_debug(...) \ diff --git a/common/status_wire.csv b/common/status_wire.csv index ddbad6902..5bd88e3f3 100644 --- a/common/status_wire.csv +++ b/common/status_wire.csv @@ -6,6 +6,7 @@ status_log,,entry,wirestring status_io,0xFFF1 status_io,,iodir,enum log_level +status_io,,who,wirestring status_io,,len,u16 status_io,,data,len*u8 diff --git a/lightningd/log_status.c b/lightningd/log_status.c index d050ac9f9..f579e8a10 100644 --- a/lightningd/log_status.c +++ b/lightningd/log_status.c @@ -3,7 +3,7 @@ bool log_status_msg(struct log *log, const u8 *msg) { - char *entry; + char *entry, *who; u8 *data; enum log_level level; @@ -12,9 +12,9 @@ bool log_status_msg(struct log *log, const u8 *msg) log_(log, level, "%s", entry); return true; } - } else if (fromwire_status_io(msg, msg, &level, &data)) { + } else if (fromwire_status_io(msg, msg, &level, &who, &data)) { if (level == LOG_IO_IN || level == LOG_IO_OUT) { - log_io(log, level, "", data, tal_len(data)); + log_io(log, level, who, data, tal_len(data)); return true; } } diff --git a/lightningd/test/run-cryptomsg.c b/lightningd/test/run-cryptomsg.c index 95ca3d8d8..9f355e27b 100644 --- a/lightningd/test/run-cryptomsg.c +++ b/lightningd/test/run-cryptomsg.c @@ -46,7 +46,7 @@ void status_fmt(enum log_level level UNUSED, const char *fmt, ...) va_end(ap); } -void status_io(enum log_level dir UNUSED, const u8 *msg UNUSED) +void status_peer_io(enum log_level dir UNUSED, const u8 *msg UNUSED) { }