diff --git a/channeld/channeld.c b/channeld/channeld.c index 30ae01f84..6506ae0db 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -2911,6 +2912,21 @@ static void req_in(struct peer *peer, const u8 *msg) case WIRE_CHANNEL_SEND_ERROR_REPLY: break; } + + /* Now handle common messages. */ + switch ((enum common_wire_type)t) { +#if DEVELOPER + case WIRE_CUSTOMMSG_OUT: + /* TODO(cdecker) Add handling of custom messages. */ + return; +#else + case WIRE_CUSTOMMSG_OUT: +#endif + /* We send these. */ + case WIRE_CUSTOMMSG_IN: + break; + } + master_badmsg(-1, msg); } diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index f59d56795..9256151bf 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -23,6 +23,7 @@ #include #include #include +#include #include static void update_feerates(struct lightningd *ld, struct channel *channel) @@ -319,6 +320,19 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) break; } + switch ((enum common_wire_type)t) { +#if DEVELOPER + case WIRE_CUSTOMMSG_IN: + /* TODO(cdecker) Add handling of custom messages. */ + break; +#else + case WIRE_CUSTOMMSG_IN: +#endif + /* We send these. */ + case WIRE_CUSTOMMSG_OUT: + break; + } + return 0; } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 614293484..27919a75a 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -922,6 +923,20 @@ static unsigned int openingd_msg(struct subd *openingd, case WIRE_OPENING_DEV_MEMLEAK_REPLY: break; } + + switch ((enum common_wire_type)t) { +#if DEVELOPER + case WIRE_CUSTOMMSG_IN: + /* TODO(cdecker) Add handling of custom messages. */ + return 0; +#else + case WIRE_CUSTOMMSG_IN: +#endif + /* We send these. */ + case WIRE_CUSTOMMSG_OUT: + break; + } + log_broken(openingd->log, "Unexpected msg %s: %s", opening_wire_type_name(t), tal_hex(tmpctx, msg)); tal_free(openingd); diff --git a/openingd/openingd.c b/openingd/openingd.c index 3b9e5258e..380d56a22 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -1413,6 +1414,20 @@ static u8 *handle_master_in(struct state *state) break; } + /* Now handle common messages. */ + switch ((enum common_wire_type)t) { +#if DEVELOPER + case WIRE_CUSTOMMSG_OUT: + /* TODO(cdecker) Add handling of custom messages. */ + return NULL; +#else + case WIRE_CUSTOMMSG_OUT: +#endif + /* We send these. */ + case WIRE_CUSTOMMSG_IN: + break; + } + status_failed(STATUS_FAIL_MASTER_IO, "Unknown msg %s", tal_hex(tmpctx, msg)); } diff --git a/wire/Makefile b/wire/Makefile index 8a0efb011..92bec190b 100644 --- a/wire/Makefile +++ b/wire/Makefile @@ -10,8 +10,8 @@ WIRE_HEADERS_NOGEN := wire/onion_defs.h \ wire/wire.h \ wire/wire_sync.h \ wire/wire_io.h -WIRE_GEN_HEADERS := wire/gen_peer_wire.h wire/gen_onion_wire.h -WIRE_GEN_SRC := wire/gen_peer_wire.c +WIRE_GEN_HEADERS := wire/gen_peer_wire.h wire/gen_onion_wire.h wire/gen_common_wire.h +WIRE_GEN_SRC := wire/gen_peer_wire.c wire/gen_common_wire.c WIRE_GEN_ONION_SRC := wire/gen_onion_wire.c WIRE_SRC := wire/wire_sync.c \ wire/wire_io.c \ @@ -85,6 +85,13 @@ wire/gen_onion_wire.h: wire/gen_onion_wire_csv $(WIRE_BOLT_DEPS) wire/Makefile wire/gen_onion_wire.c: wire/gen_onion_wire_csv $(WIRE_BOLT_DEPS) wire/Makefile $(BOLT_GEN) -s --expose-tlv-type=tlv_payload --page impl ${@:.c=.h} onion_type < $< > $@ +# Some messages that are common among all daemons +wire/gen_common_wire.h: wire/common_wire_csv $(WIRE_BOLT_DEPS) wire/Makefile + $(BOLT_GEN) -s --page header $@ common_wire_type < $< > $@ + +wire/gen_common_wire.c: wire/common_wire_csv $(WIRE_BOLT_DEPS) wire/Makefile + $(BOLT_GEN) -s --page impl ${@:.c=.h} common_wire_type < $< > $@ + check-source: $(WIRE_SRC:%=check-src-include-order/%) $(WIRE_HEADERS_NOGEN:%=check-hdr-include-order/%) check-source-bolt: $(WIRE_SRC:%=bolt-check/%) $(WIRE_HEADERS_NOGEN:%=bolt-check/%) diff --git a/wire/common_wire_csv b/wire/common_wire_csv new file mode 100644 index 000000000..7e607c806 --- /dev/null +++ b/wire/common_wire_csv @@ -0,0 +1,10 @@ +# A custom message that we got from a peer and don't know how to handle, so we +# forward it to the master for further handling. +msgtype,custommsg_in,1030 +msgdata,custommsg_in,msg_len,u16, +msgdata,custommsg_in,msg,u8,msg_len + +# A custom message that the master tells us to send to the peer. +msgtype,custommsg_out,1031 +msgdata,custommsg_out,msg_len,u16, +msgdata,custommsg_out,msg,u8,msg_len