From 8015ceadfdc1d6d156da0c9d3c0e149f523f7684 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 4 Nov 2016 11:17:03 +1030 Subject: [PATCH] log: add netaddr Also avoids allocating netaddr_name which otherwise lasts as long as connection does. Signed-off-by: Rusty Russell --- daemon/lightning-cli.c | 7 +++++++ daemon/log.c | 2 ++ daemon/log.h | 1 + daemon/peer.c | 4 +--- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/daemon/lightning-cli.c b/daemon/lightning-cli.c index 8e482b7f4..a9f58f97d 100644 --- a/daemon/lightning-cli.c +++ b/daemon/lightning-cli.c @@ -45,6 +45,13 @@ struct timeabs controlled_time(void) return time_now(); } +struct netaddr; +char *netaddr_name(const tal_t *ctx, const struct netaddr *a); +char *netaddr_name(const tal_t *ctx, const struct netaddr *a) +{ + return NULL; +} + int main(int argc, char *argv[]) { int fd, i, off; diff --git a/daemon/log.c b/daemon/log.c index 64aa0a478..6d8159500 100644 --- a/daemon/log.c +++ b/daemon/log.c @@ -349,6 +349,8 @@ static char *to_string_(const tal_t *ctx, &u.cstate->side[LOCAL]), to_string(ctx, lr, struct channel_oneside, &u.cstate->side[REMOTE])); + } else if (streq(structname, "struct netaddr")) { + s = netaddr_name(ctx, u.netaddr); } return s; diff --git a/daemon/log.h b/daemon/log.h index 9d54c2092..f1eb78593 100644 --- a/daemon/log.h +++ b/daemon/log.h @@ -90,6 +90,7 @@ union loggable_structs { const struct rval *rval; const struct channel_state *cstate; const struct channel_oneside *channel_oneside; + const struct netaddr *netaddr; const char *charp_; }; diff --git a/daemon/peer.c b/daemon/peer.c index ba1dd1d04..f70005d64 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -2668,7 +2668,6 @@ static struct io_plan *peer_connected_out(struct io_conn *conn, struct json_connecting *connect) { struct log *l; - const char *name; struct netaddr addr; l = new_log(conn, dstate->log_record, "OUT-%s:%s:", @@ -2678,9 +2677,8 @@ static struct io_plan *peer_connected_out(struct io_conn *conn, log_unusual(l, "Failed to get netaddr: %s", strerror(errno)); return io_close(conn); } - name = netaddr_name(conn, &addr); - log_debug(l, "Connected out to %s", name); + log_debug_struct(l, "Connected out to %s", struct netaddr, &addr); return peer_crypto_setup(conn, dstate, NULL, l, crypto_on_out, connect); }