Skip to content

Commit

Permalink
status: make status_io a more generic mechanism.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed May 10, 2018
1 parent 5a0bc83 commit e93682e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion channeld/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions common/crypto_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions common/cryptomsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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;

Expand Down
21 changes: 15 additions & 6 deletions common/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(...) \
Expand Down
1 change: 1 addition & 0 deletions common/status_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lightningd/log_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lightningd/test/run-cryptomsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down

0 comments on commit e93682e

Please sign in to comment.