Browse Source

common: allow subdaemons to specify the node_id in status messages.

This is ignored in subdaemons which are per-peer, but very useful for
multi-peer daemons like connectd and gossipd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
parent
commit
00cb5adfe6
  1. 4
      channeld/test/run-commit_tx.c
  2. 4
      channeld/test/run-full_channel.c
  3. 4
      common/crypto_sync.c
  4. 38
      common/status.c
  5. 39
      common/status.h
  6. 2
      common/status_wire.csv
  7. 2
      common/subdaemon.c
  8. 4
      common/test/run-cryptomsg.c
  9. 4
      connectd/peer_exchange_initmsg.c
  10. 4
      connectd/test/run-initiator-success.c
  11. 4
      connectd/test/run-responder-success.c
  12. 10
      connectd/tor.c
  13. 6
      connectd/tor_autoservice.c
  14. 8
      devtools/gossipwith.c
  15. 4
      devtools/mkclose.c
  16. 4
      devtools/mkcommit.c
  17. 4
      devtools/mkfunding.c
  18. 4
      gossipd/test/run-bench-find_route.c
  19. 4
      gossipd/test/run-crc32_of_update.c
  20. 5
      gossipd/test/run-extended-info.c
  21. 2
      gossipd/test/run-find_route-specific.c
  22. 4
      gossipd/test/run-find_route.c
  23. 4
      gossipd/test/run-next_block_range.c
  24. 4
      gossipd/test/run-overlong.c
  25. 4
      gossipd/test/run-txout_failure.c
  26. 12
      lightningd/log_status.c
  27. 4
      onchaind/test/run-grind_feerate-bug.c
  28. 4
      onchaind/test/run-grind_feerate.c

4
channeld/test/run-commit_tx.c

@ -27,7 +27,9 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

4
channeld/test/run-full_channel.c

@ -32,7 +32,9 @@ void status_failed(enum status_failreason code UNNEEDED,
{ fprintf(stderr, "status_failed called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

4
common/crypto_sync.c

@ -22,7 +22,7 @@ void sync_crypto_write(struct per_peer_state *pps, const void *msg TAKES)
#endif
u8 *enc;
status_peer_io(LOG_IO_OUT, msg);
status_peer_io(LOG_IO_OUT, NULL, msg);
enc = cryptomsg_encrypt_msg(NULL, &pps->cs, msg);
#if DEVELOPER
@ -124,7 +124,7 @@ u8 *sync_crypto_read(const tal_t *ctx, struct per_peer_state *pps)
if (!dec)
peer_failed_connection_lost();
else
status_peer_io(LOG_IO_IN, dec);
status_peer_io(LOG_IO_IN, NULL, dec);
return dec;
}

38
common/status.c

@ -93,39 +93,49 @@ void status_send(const u8 *msg TAKES)
}
}
static void status_io_full(enum log_level iodir, const char *who, const u8 *p)
static void status_io_full(enum log_level iodir,
const struct node_id *peer,
const char *who, const u8 *p)
{
status_send(take(towire_status_io(NULL, iodir, who, p)));
status_send(take(towire_status_io(NULL, iodir, peer, who, p)));
}
static void status_peer_io_short(enum log_level iodir, const u8 *p)
static void status_peer_io_short(enum log_level iodir,
const struct node_id *peer,
const u8 *p)
{
status_debug("%s %s",
status_peer_debug(peer, "%s %s",
iodir == LOG_IO_OUT ? "peer_out" : "peer_in",
wire_type_name(fromwire_peektype(p)));
}
void status_peer_io(enum log_level iodir, const u8 *p)
void status_peer_io(enum log_level iodir,
const struct node_id *peer,
const u8 *p)
{
report_logging_io("SIGUSR1");
if (logging_io)
status_io_full(iodir, "", p);
status_io_full(iodir, NULL, "", p);
/* We get a huge amount of gossip; don't log it */
else if (!is_msg_for_gossipd(p))
status_peer_io_short(iodir, p);
status_peer_io_short(iodir, peer, p);
}
void status_io(enum log_level iodir, const char *who,
void status_io(enum log_level iodir,
const struct node_id *peer,
const char *who,
const void *data, size_t len)
{
report_logging_io("SIGUSR1");
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));
status_io_full(iodir, peer, who, tal_dup_arr(tmpctx, u8, data, len, 0));
}
void status_vfmt(enum log_level level, const char *fmt, va_list ap)
void status_vfmt(enum log_level level,
const struct node_id *peer,
const char *fmt, va_list ap)
{
char *str;
@ -146,16 +156,18 @@ void status_vfmt(enum log_level level, const char *fmt, va_list ap)
}
}
str = tal_vfmt(NULL, fmt, ap);
status_send(take(towire_status_log(NULL, level, str)));
status_send(take(towire_status_log(NULL, level, peer, str)));
tal_free(str);
}
void status_fmt(enum log_level level, const char *fmt, ...)
void status_fmt(enum log_level level,
const struct node_id *peer,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
status_vfmt(level, fmt, ap);
status_vfmt(level, peer, fmt, ap);
va_end(ap);
}

39
common/status.h

@ -11,6 +11,7 @@
struct channel_id;
struct daemon_conn;
struct node_id;
struct per_peer_state;
/* Simple status reporting API. */
@ -18,27 +19,47 @@ void status_setup_sync(int fd);
void status_setup_async(struct daemon_conn *master);
/* Send a printf-style debugging trace. */
void status_fmt(enum log_level level, const char *fmt, ...)
PRINTF_FMT(2,3);
void status_fmt(enum log_level level,
const struct node_id *peer,
const char *fmt, ...)
PRINTF_FMT(3,4);
/* vprintf-style */
void status_vfmt(enum log_level level, const char *fmt, va_list ap);
void status_vfmt(enum log_level level,
const struct node_id *peer,
const char *fmt, va_list ap);
/* Usually we only log the packet names, not contents. */
extern volatile bool logging_io;
void status_peer_io(enum log_level iodir, const u8 *p);
void status_io(enum log_level iodir, const char *who,
/* This logs a debug summary if IO logging not enabled. */
void status_peer_io(enum log_level iodir,
const struct node_id *peer,
const u8 *p);
void status_io(enum log_level iodir,
const struct node_id *peer,
const char *who,
const void *data, size_t len);
/* Helpers */
#define status_debug(...) \
status_fmt(LOG_DBG, __VA_ARGS__)
status_fmt(LOG_DBG, NULL, __VA_ARGS__)
#define status_info(...) \
status_fmt(LOG_INFORM, __VA_ARGS__)
status_fmt(LOG_INFORM, NULL, __VA_ARGS__)
#define status_unusual(...) \
status_fmt(LOG_UNUSUAL, __VA_ARGS__)
status_fmt(LOG_UNUSUAL, NULL, __VA_ARGS__)
#define status_broken( ...) \
status_fmt(LOG_BROKEN, __VA_ARGS__)
status_fmt(LOG_BROKEN, NULL, __VA_ARGS__)
/* For daemons which handle multiple peers */
#define status_peer_debug(peer, ...) \
status_fmt(LOG_DBG, (peer), __VA_ARGS__)
#define status_peer_info(peer, ...) \
status_fmt(LOG_INFORM, (peer), __VA_ARGS__)
#define status_peer_unusual(peer, ...) \
status_fmt(LOG_UNUSUAL, (peer), __VA_ARGS__)
#define status_peer_broken(peer, ...) \
status_fmt(LOG_BROKEN, (peer), __VA_ARGS__)
/* Send a failure status code with printf-style msg, and exit. */
void status_failed(enum status_failreason code,

2
common/status_wire.csv

@ -3,10 +3,12 @@
msgtype,status_log,0xFFF0
msgdata,status_log,level,enum log_level,
msgdata,status_log,peer,?node_id,
msgdata,status_log,entry,wirestring,
msgtype,status_io,0xFFF1
msgdata,status_io,iodir,enum log_level,
msgdata,status_io,peer,?node_id,
msgdata,status_io,who,wirestring,
msgdata,status_io,len,u16,
msgdata,status_io,data,u8,len

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

2
common/subdaemon.c

@ -16,7 +16,7 @@ static void status_backtrace_print(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
status_vfmt(LOG_BROKEN, fmt, ap);
status_vfmt(LOG_BROKEN, NULL, fmt, ap);
va_end(ap);
}

4
common/test/run-cryptomsg.c

@ -32,7 +32,9 @@ const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id UNUSED,
const char *fmt, ...)
{
va_list ap;

4
connectd/peer_exchange_initmsg.c

@ -39,7 +39,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
if (!msg)
return io_close(conn);
status_peer_io(LOG_IO_IN, msg);
status_peer_io(LOG_IO_IN, &peer->id, msg);
/* BOLT #1:
*
@ -168,7 +168,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
/* Features so nice, we send it twice! */
get_offered_features(tmpctx),
get_offered_features(tmpctx));
status_peer_io(LOG_IO_OUT, peer->msg);
status_peer_io(LOG_IO_OUT, &peer->id, peer->msg);
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));
next = read_init;

4
connectd/test/run-initiator-success.c

@ -54,7 +54,9 @@ static struct io_plan *test_read(struct io_conn *conn,
struct handshake *h);
#define SUPERVERBOSE status_debug
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

4
connectd/test/run-responder-success.c

@ -54,7 +54,9 @@ static struct io_plan *test_read(struct io_conn *conn,
struct handshake *h);
#define SUPERVERBOSE status_debug
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

10
connectd/tor.c

@ -44,7 +44,7 @@ struct connecting_socks {
static struct io_plan *connect_finish2(struct io_conn *conn,
struct connecting_socks *connect)
{
status_io(LOG_IO_IN, "proxy",
status_io(LOG_IO_IN, NULL, "proxy",
connect->buffer + SIZE_OF_RESPONSE + SIZE_OF_IPV4_RESPONSE,
SIZE_OF_IPV6_RESPONSE - SIZE_OF_IPV4_RESPONSE);
status_debug("Now try LN connect out for host %s", connect->host);
@ -54,7 +54,7 @@ static struct io_plan *connect_finish2(struct io_conn *conn,
static struct io_plan *connect_finish(struct io_conn *conn,
struct connecting_socks *connect)
{
status_io(LOG_IO_IN, "proxy",
status_io(LOG_IO_IN, NULL, "proxy",
connect->buffer, SIZE_OF_IPV4_RESPONSE + SIZE_OF_RESPONSE);
if ( connect->buffer[1] == '\0') {
@ -100,7 +100,7 @@ static struct io_plan *io_tor_connect_after_resp_to_connect(struct io_conn
connecting_socks
*connect)
{
status_io(LOG_IO_IN, "proxy", connect->buffer, 2);
status_io(LOG_IO_IN, NULL, "proxy", connect->buffer, 2);
if (connect->buffer[1] == SOCKS_ERROR) {
status_debug("Connected out for %s error", connect->host);
@ -118,7 +118,7 @@ static struct io_plan *io_tor_connect_after_resp_to_connect(struct io_conn
memcpy(connect->buffer + SOCK_REQ_V5_LEN + strlen(connect->host),
&(connect->port), sizeof connect->port);
status_io(LOG_IO_OUT, "proxy", connect->buffer,
status_io(LOG_IO_OUT, NULL, "proxy", connect->buffer,
SOCK_REQ_V5_HEADER_LEN + connect->hlen);
return io_write(conn, connect->buffer,
SOCK_REQ_V5_HEADER_LEN + connect->hlen,
@ -141,7 +141,7 @@ static struct io_plan *io_tor_connect_do_req(struct io_conn *conn,
connect->buffer[1] = 1;
connect->buffer[2] = SOCKS_NOAUTH;
status_io(LOG_IO_OUT, "proxy", connect->buffer, SOCK_REQ_METH_LEN);
status_io(LOG_IO_OUT, NULL, "proxy", connect->buffer, SOCK_REQ_METH_LEN);
return io_write(conn, connect->buffer, SOCK_REQ_METH_LEN,
&io_tor_connect_after_req_to_connect, connect);
}

6
connectd/tor_autoservice.c

@ -34,12 +34,12 @@ static void *buf_resize(struct membuf *mb, void *buf, size_t len)
static void tor_send_cmd(struct rbuf *rbuf, const char *cmd)
{
status_io(LOG_IO_OUT, "torcontrol", cmd, strlen(cmd));
status_io(LOG_IO_OUT, NULL, "torcontrol", cmd, strlen(cmd));
if (!write_all(rbuf->fd, cmd, strlen(cmd)))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Writing '%s' to Tor socket", cmd);
status_io(LOG_IO_OUT, "torcontrol", "\r\n", 2);
status_io(LOG_IO_OUT, NULL, "torcontrol", "\r\n", 2);
if (!write_all(rbuf->fd, "\r\n", 2))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Writing CRLF to Tor socket");
@ -50,7 +50,7 @@ static char *tor_response_line(struct rbuf *rbuf)
char *line;
while ((line = rbuf_read_str(rbuf, '\n')) != NULL) {
status_io(LOG_IO_IN, "torcontrol", line, strlen(line));
status_io(LOG_IO_IN, NULL, "torcontrol", line, strlen(line));
/* Weird response */
if (!strstarts(line, "250"))

8
devtools/gossipwith.c

@ -49,11 +49,15 @@ static bool initial_sync = false;
static unsigned long max_messages = -1UL;
/* Empty stubs to make us compile */
void status_peer_io(enum log_level iodir, const u8 *p)
void status_peer_io(enum log_level iodir,
const struct node_id *node_id,
const u8 *p)
{
}
void status_fmt(enum log_level level, const char *fmt, ...)
void status_fmt(enum log_level level,
const struct node_id *node_id,
const char *fmt, ...)
{
}

4
devtools/mkclose.c

@ -23,7 +23,9 @@
static bool verbose = false;
void status_fmt(enum log_level level, const char *fmt, ...)
void status_fmt(enum log_level level,
const struct node_id *node_id,
const char *fmt, ...)
{
if (verbose) {
va_list ap;

4
devtools/mkcommit.c

@ -28,7 +28,9 @@
static bool verbose = false;
void status_fmt(enum log_level level, const char *fmt, ...)
void status_fmt(enum log_level level,
const struct node_id *node_id,
const char *fmt, ...)
{
if (verbose) {
va_list ap;

4
devtools/mkfunding.c

@ -21,7 +21,9 @@
#include <common/utxo.h>
#include <stdio.h>
void status_fmt(enum log_level level, const char *fmt, ...)
void status_fmt(enum log_level level,
const struct node_id *node_id,
const char *fmt, ...)
{
}

4
gossipd/test/run-bench-find_route.c

@ -15,7 +15,9 @@
#include "../routing.c"
#include "../gossip_store.c"
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

4
gossipd/test/run-crc32_of_update.c

@ -87,7 +87,9 @@ void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for towire_errorfmt */

5
gossipd/test/run-extended-info.c

@ -68,8 +68,9 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *node_id UNNEEDED,
const char *fmt UNNEEDED, ...)
{
}

2
gossipd/test/run-find_route-specific.c

@ -8,7 +8,7 @@
#include <common/status.h>
#include <stdio.h>
#define status_fmt(level, fmt, ...) \
#define status_fmt(level, node_id, fmt, ...) \
do { printf((fmt) ,##__VA_ARGS__); printf("\n"); } while(0)
#include "../routing.c"

4
gossipd/test/run-find_route.c

@ -2,7 +2,9 @@
#include "../gossip_store.c"
#include <stdio.h>
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

4
gossipd/test/run-next_block_range.c

@ -40,7 +40,9 @@ void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for would_ratelimit_cupdate */

4
gossipd/test/run-overlong.c

@ -2,7 +2,9 @@
#include "../gossip_store.c"
#include <stdio.h>
void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void status_fmt(enum log_level level UNUSED,
const struct node_id *node_id,
const char *fmt, ...)
{
va_list ap;

4
gossipd/test/run-txout_failure.c

@ -64,7 +64,9 @@ char *sanitize_error(const tal_t *ctx UNNEEDED, const u8 *errmsg UNNEEDED,
struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "sanitize_error called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for towire_errorfmt */

12
lightningd/log_status.c

@ -7,18 +7,26 @@ bool log_status_msg(struct log *log,
{
char *entry, *who;
u8 *data;
struct node_id *suggested_node_id;
enum log_level level;
bool call_notifier;
if (fromwire_status_log(msg, msg, &level, &entry)) {
if (fromwire_status_log(msg, msg, &level, &suggested_node_id, &entry)) {
/* If there's not already a node_id (global subdirs), they can
* set it */
if (!node_id)
node_id = suggested_node_id;
if (level != LOG_IO_IN && level != LOG_IO_OUT) {
call_notifier = (level == LOG_BROKEN ||
level == LOG_UNUSUAL)? true : false;
log_(log, level, node_id, call_notifier, "%s", entry);
return true;
}
} else if (fromwire_status_io(msg, msg, &level, &who, &data)) {
} else if (fromwire_status_io(msg, msg, &level, &suggested_node_id,
&who, &data)) {
if (level == LOG_IO_IN || level == LOG_IO_OUT) {
if (!node_id)
node_id = suggested_node_id;
log_io(log, level, node_id, who, data, tal_count(data));
return true;
}

4
onchaind/test/run-grind_feerate-bug.c

@ -189,7 +189,9 @@ bool fromwire_hsm_sign_tx_reply(const void *p UNNEEDED, struct bitcoin_signature
return true;
}
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *node_id,
const char *fmt UNNEEDED, ...)
{
}

4
onchaind/test/run-grind_feerate.c

@ -118,7 +118,9 @@ void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_fmt called!\n"); abort(); }
/* Generated stub for status_setup_sync */

Loading…
Cancel
Save