Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
e93682e3bf
  1. 2
      channeld/channel.c
  2. 4
      common/crypto_sync.c
  3. 4
      common/cryptomsg.c
  4. 21
      common/status.c
  5. 4
      common/status.h
  6. 1
      common/status_wire.csv
  7. 6
      lightningd/log_status.c
  8. 2
      lightningd/test/run-cryptomsg.c

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

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

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

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

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

1
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

Can't render this file because it has a wrong number of fields in line 3.

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

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

Loading…
Cancel
Save