status: make status_io a more generic mechanism.

Currently it's always for messages to peer: make that status_peer_io and
add a new status_io for other IO.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-05-10 08:48:24 +09:30
parent 5a0bc83b20
commit e93682e3bf
8 changed files with 28 additions and 16 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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)

View File

@@ -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(...) \

View File

@@ -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
1 #include <common/status_wire.h>
6 status_io,,iodir,enum log_level
7 status_io,,len,u16 status_io,,who,wirestring
8 status_io,,data,len*u8 status_io,,len,u16
9 status_io,,data,len*u8
10 status_fail,0xFFF2
11 status_fail,,failreason,enum status_failreason
12 status_fail,,desc,wirestring

View File

@@ -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;
}
}

View File

@@ -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)
{
}