Browse Source

wire: Add common messages that are independent of daemons

These messages may be exchanged between the master and any daemon. For now
these are just the daemons that a peer may be attached to at any time since
the first example of this is the custommsg infrastructure.
travis-debug
Christian Decker 5 years ago
parent
commit
a8fa55d275
  1. 16
      channeld/channeld.c
  2. 14
      lightningd/channel_control.c
  3. 15
      lightningd/opening_control.c
  4. 15
      openingd/openingd.c
  5. 11
      wire/Makefile
  6. 10
      wire/common_wire_csv

16
channeld/channeld.c

@ -55,6 +55,7 @@
#include <inttypes.h>
#include <secp256k1.h>
#include <stdio.h>
#include <wire/gen_common_wire.h>
#include <wire/gen_onion_wire.h>
#include <wire/peer_wire.h>
#include <wire/wire.h>
@ -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);
}

14
lightningd/channel_control.c

@ -23,6 +23,7 @@
#include <lightningd/log.h>
#include <lightningd/peer_control.h>
#include <lightningd/subd.h>
#include <wire/gen_common_wire.h>
#include <wire/wire_sync.h>
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;
}

15
lightningd/opening_control.c

@ -33,6 +33,7 @@
#include <lightningd/plugin_hook.h>
#include <lightningd/subd.h>
#include <openingd/gen_opening_wire.h>
#include <wire/gen_common_wire.h>
#include <wire/wire.h>
#include <wire/wire_sync.h>
@ -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);

15
openingd/openingd.c

@ -47,6 +47,7 @@
#include <secp256k1.h>
#include <stdio.h>
#include <wally_bip32.h>
#include <wire/gen_common_wire.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wire.h>
#include <wire/wire.h>
@ -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));
}

11
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/%)

10
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
Loading…
Cancel
Save