From 14505594b52bbd1b4ddd85f65dc80669ffd39555 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 10 Mar 2017 21:26:58 +1030 Subject: [PATCH] lightningd/channel: convert to subd. Signed-off-by: Rusty Russell --- lightningd/channel/Makefile | 17 ++++------- lightningd/channel/channel.c | 8 ++--- lightningd/channel/channel_status_wire.csv | 14 --------- ...nnel_control_wire.csv => channel_wire.csv} | 15 ++++++++++ lightningd/peer_control.c | 29 ++++++++++--------- 5 files changed, 39 insertions(+), 44 deletions(-) delete mode 100644 lightningd/channel/channel_status_wire.csv rename lightningd/channel/{channel_control_wire.csv => channel_wire.csv} (71%) diff --git a/lightningd/channel/Makefile b/lightningd/channel/Makefile index 6b63bfae2..eee989061 100644 --- a/lightningd/channel/Makefile +++ b/lightningd/channel/Makefile @@ -10,8 +10,7 @@ lightningd/channel-all: lightningd/lightningd_channel # lightningd/channel needs these: LIGHTNINGD_CHANNEL_HEADERS_GEN := \ - lightningd/channel/gen_channel_control_wire.h \ - lightningd/channel/gen_channel_status_wire.h + lightningd/channel/gen_channel_wire.h LIGHTNINGD_CHANNEL_HEADERS_NOGEN := @@ -36,17 +35,11 @@ LIGHTNINGD_HEADERS_NOGEN += $(LIGHTNINGD_CHANNEL_HEADERS_NOGEN) $(LIGHTNINGD_CHANNEL_OBJS): $(LIGHTNINGD_HEADERS) -lightningd/channel/gen_channel_control_wire.h: $(WIRE_GEN) lightningd/channel/channel_control_wire.csv - $(WIRE_GEN) --header $@ channel_control_wire_type < lightningd/channel/channel_control_wire.csv > $@ +lightningd/channel/gen_channel_wire.h: $(WIRE_GEN) lightningd/channel/channel_wire.csv + $(WIRE_GEN) --header $@ channel_wire_type < lightningd/channel/channel_wire.csv > $@ -lightningd/channel/gen_channel_control_wire.c: $(WIRE_GEN) lightningd/channel/channel_control_wire.csv - $(WIRE_GEN) ${@:.c=.h} channel_control_wire_type < lightningd/channel/channel_control_wire.csv > $@ - -lightningd/channel/gen_channel_status_wire.h: $(WIRE_GEN) lightningd/channel/channel_status_wire.csv - $(WIRE_GEN) --header $@ channel_status_wire_type < lightningd/channel/channel_status_wire.csv > $@ - -lightningd/channel/gen_channel_status_wire.c: $(WIRE_GEN) lightningd/channel/channel_status_wire.csv - $(WIRE_GEN) ${@:.c=.h} channel_status_wire_type < lightningd/channel/channel_status_wire.csv > $@ +lightningd/channel/gen_channel_wire.c: $(WIRE_GEN) lightningd/channel/channel_wire.csv + $(WIRE_GEN) ${@:.c=.h} channel_wire_type < lightningd/channel/channel_wire.csv > $@ LIGHTNINGD_CHANNEL_OBJS := $(LIGHTNINGD_CHANNEL_SRC:.c=.o) $(LIGHTNINGD_CHANNEL_GEN_SRC:.c=.o) diff --git a/lightningd/channel/channel.c b/lightningd/channel/channel.c index 4d5c32127..43dc4180f 100644 --- a/lightningd/channel/channel.c +++ b/lightningd/channel/channel.c @@ -8,8 +8,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -28,8 +27,7 @@ #include #include -/* Stdout == status, stdin == requests, 3 == peer */ -#define STATUS_FD STDOUT_FILENO +/* stdin == requests, 3 == peer */ #define REQ_FD STDIN_FILENO #define PEER_FD 3 @@ -176,7 +174,7 @@ int main(int argc, char *argv[]) signal(SIGCHLD, SIG_IGN); secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN); - status_setup(STATUS_FD); + status_setup(REQ_FD); peer->peer_out = tal_arr(peer, const u8 *, 0); init_peer_crypto_state(peer, &peer->pcs); peer->funding_locked[LOCAL] = peer->funding_locked[REMOTE] = false; diff --git a/lightningd/channel/channel_status_wire.csv b/lightningd/channel/channel_status_wire.csv deleted file mode 100644 index 8e40269a0..000000000 --- a/lightningd/channel/channel_status_wire.csv +++ /dev/null @@ -1,14 +0,0 @@ -# Shouldn't happen -channel_bad_command,0x8000 -# Also shouldn't happen -channel_hsm_failed,0x8001 - -# These are due to peer. -channel_peer_write_failed,0x8010 -channel_peer_read_failed,0x8011 -channel_peer_bad_message,0x8012 - -# Received funding_locked -channel_received_funding_locked,1 -# Received and sent fundin_locked -channel_normal_operation,2 diff --git a/lightningd/channel/channel_control_wire.csv b/lightningd/channel/channel_wire.csv similarity index 71% rename from lightningd/channel/channel_control_wire.csv rename to lightningd/channel/channel_wire.csv index ee738f88b..24c985d6d 100644 --- a/lightningd/channel/channel_control_wire.csv +++ b/lightningd/channel/channel_wire.csv @@ -1,3 +1,18 @@ +# Shouldn't happen +channel_bad_command,0x8000 +# Also shouldn't happen +channel_hsm_failed,0x8001 + +# These are due to peer. +channel_peer_write_failed,0x8010 +channel_peer_read_failed,0x8011 +channel_peer_bad_message,0x8012 + +# Received funding_locked +channel_received_funding_locked,1000 +# Received and sent funding_locked +channel_normal_operation,1001 + #include #include diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 65488a1bb..1d680b90d 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -16,8 +16,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -550,8 +549,9 @@ static enum watch_result funding_depth_cb(struct peer *peer, } peer_set_condition(peer, "Funding tx reached depth %u", depth); - subdaemon_req(peer->owner, take(towire_channel_funding_locked(peer)), - -1, NULL, NULL, NULL); + /* FIXME: subdaemon */ + subd_send_msg((struct subd *)peer->owner, + take(towire_channel_funding_locked(peer))); return DELETE_WATCH; } @@ -598,11 +598,11 @@ static bool opening_got_hsm_funding_sig(struct subd *hsm, const u8 *resp, return true; } -static enum subdaemon_status update_channel_status(struct subdaemon *sd, - const u8 *msg, - int unused) +static enum subd_msg_ret update_channel_status(struct subd *sd, + const u8 *msg, + int unused) { - enum channel_status_wire_type t = fromwire_peektype(msg); + enum channel_wire_type t = fromwire_peektype(msg); switch (t) { case WIRE_CHANNEL_RECEIVED_FUNDING_LOCKED: @@ -617,10 +617,13 @@ static enum subdaemon_status update_channel_status(struct subdaemon *sd, case WIRE_CHANNEL_PEER_WRITE_FAILED: case WIRE_CHANNEL_PEER_READ_FAILED: case WIRE_CHANNEL_PEER_BAD_MESSAGE: + /* And we never get these from channeld. */ + case WIRE_CHANNEL_INIT: + case WIRE_CHANNEL_FUNDING_LOCKED: break; } - return STATUS_COMPLETE; + return SUBD_COMPLETE; } /* opening is done, start lightningd_channel for peer. */ @@ -635,10 +638,9 @@ static void peer_start_channeld(struct peer *peer, bool am_funder, u8 *msg; /* Normal channel daemon. */ - peer->owner = new_subdaemon(peer->ld, peer->ld, + peer->owner = (struct subdaemon *)new_subd(peer->ld, peer->ld, "lightningd_channel", peer, - channel_status_wire_type_name, - channel_control_wire_type_name, + channel_wire_type_name, update_channel_status, NULL, peer->fd, -1); if (!peer->owner) { @@ -671,7 +673,8 @@ static void peer_start_channeld(struct peer *peer, bool am_funder, peer->seed); /* We don't expect a response: we are triggered by funding_depth_cb. */ - subdaemon_req(peer->owner, take(msg), -1, NULL, NULL, NULL); + /* FIXME: subdaemon */ + subd_send_msg((struct subd *)peer->owner, take(msg)); } static bool opening_release_tx(struct subd *opening, const u8 *resp,