diff --git a/Makefile b/Makefile index c7b4d1229..4ba037b31 100644 --- a/Makefile +++ b/Makefile @@ -165,7 +165,8 @@ CORE_HEADERS := close_tx.h \ utils.h \ version.h -GEN_HEADERS := gen_state_names.h \ +GEN_HEADERS := gen_pkt_names.h \ + gen_state_names.h \ gen_version.h \ lightning.pb-c.h @@ -265,6 +266,10 @@ ccan/ccan/cdump/tools/cdump-enumstr: ccan/ccan/cdump/tools/cdump-enumstr.o $(CDU gen_state_names.h: state_types.h ccan/ccan/cdump/tools/cdump-enumstr ccan/ccan/cdump/tools/cdump-enumstr state_types.h > $@ +# lightning.pb-c.h doesn't create a named enum, just a typedef. Hack it. +gen_pkt_names.h: lightning.pb-c.h ccan/ccan/cdump/tools/cdump-enumstr + (echo 'enum PktCase {'; grep '^ PKT__' lightning.pb-c.h; echo '};') | ccan/ccan/cdump/tools/cdump-enumstr - | sed 's/enum PktCase/Pkt__PktCase/' > $@ + # We build a static libsecpk1, since we need ecdh # (and it's not API stable yet!). libsecp256k1.a: secp256k1/libsecp256k1.la @@ -327,7 +332,7 @@ distclean: clean maintainter-clean: distclean @echo 'This command is intended for maintainers to use; it' @echo 'deletes files that may need special tools to rebuild.' - $(RM) lightning.pb-c.c lightning.pb-c.h ccan/config.h gen_version.h + $(RM) lightning.pb-c.c lightning.pb-c.h ccan/config.h $(GEN_HEADERS) $(RM) doc/deployable-lightning.pdf clean: daemon-clean diff --git a/daemon/cryptopkt.c b/daemon/cryptopkt.c index 9efa6ce97..3093707a8 100644 --- a/daemon/cryptopkt.c +++ b/daemon/cryptopkt.c @@ -272,7 +272,7 @@ static struct io_plan *decrypt_body(struct io_conn *conn, struct peer *peer) log_debug(peer->log, "Received packet LEN=%u, type=%s", le32_to_cpu(iod->hdr_in.length), peer->inpkt->pkt_case == PKT__PKT_AUTH ? "PKT_AUTH" - : input_name(peer->inpkt->pkt_case)); + : pkt_name(peer->inpkt->pkt_case)); return iod->cb(conn, peer); } diff --git a/daemon/packets.c b/daemon/packets.c index 82b73cd8e..494b49190 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -425,7 +425,7 @@ void queue_pkt_close_signature(struct peer *peer) Pkt *pkt_err_unexpected(struct peer *peer, const Pkt *pkt) { - return pkt_err(peer, "Unexpected packet %s", state_name(pkt->pkt_case)); + return pkt_err(peer, "Unexpected packet %s", pkt_name(pkt->pkt_case)); } /* Process various packets: return an error packet on failure. */ diff --git a/daemon/peer.c b/daemon/peer.c index c127ba4b8..88192bbc6 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -170,7 +170,7 @@ static void state_single(struct peer *peer, if (tal_count(peer->outpkt) > old_outpkts) { Pkt *outpkt = peer->outpkt[old_outpkts].pkt; - log_add(peer->log, " (out %s)", input_name(outpkt->pkt_case)); + log_add(peer->log, " (out %s)", pkt_name(outpkt->pkt_case)); } if (broadcast) broadcast_tx(peer, broadcast); diff --git a/names.c b/names.c index f4926692c..f94976eb6 100644 --- a/names.c +++ b/names.c @@ -1,6 +1,7 @@ #include "names.h" /* Indented for 'check-source' because it has to be included after names.h */ #include "gen_state_names.h" + #include "gen_pkt_names.h" const char *state_name(enum state s) { @@ -41,3 +42,13 @@ const char *peercond_name(enum state_peercond peercond) return enum_state_peercond_names[i].name; return "unknown"; } + +const char *pkt_name(Pkt__PktCase pkt) +{ + size_t i; + + for (i = 0; enum_PktCase_names[i].name; i++) + if (enum_PktCase_names[i].v == pkt) + return enum_PktCase_names[i].name; + return "unknown"; +} diff --git a/names.h b/names.h index b102ef4ca..e586cd774 100644 --- a/names.h +++ b/names.h @@ -1,10 +1,12 @@ #ifndef LIGHTNING_NAMES_H #define LIGHTNING_NAMES_H #include "config.h" +#include "lightning.pb-c.h" #include "state_types.h" const char *state_name(enum state s); const char *input_name(enum state_input in); const char *cstatus_name(enum command_status cstatus); const char *peercond_name(enum state_peercond peercond); +const char *pkt_name(Pkt__PktCase pkt); #endif /* LIGHTNING_NAMES_H */