Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subd version messages #4471

Merged
merged 5 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -3040,8 +3040,6 @@ static void init_channel(struct peer *peer)

assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK));

status_setup_sync(MASTER_FD);

msg = wire_sync_read(tmpctx, MASTER_FD);
if (!fromwire_channeld_init(peer, msg,
&chainparams,
Expand Down Expand Up @@ -3225,6 +3223,8 @@ int main(int argc, char *argv[])

subdaemon_setup(argc, argv);

status_setup_sync(MASTER_FD);

peer = tal(NULL, struct peer);
peer->expecting_pong = false;
timers_init(&peer->timers, time_mono());
Expand Down
7 changes: 7 additions & 0 deletions common/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <common/status.h>
#include <common/status_wiregen.h>
#include <common/utils.h>
#include <common/version.h>
#include <errno.h>
#include <signal.h>
#include <wire/peer_wire.h>
Expand Down Expand Up @@ -59,6 +60,9 @@ void status_setup_sync(int fd)
assert(!status_conn);
status_fd = fd;
setup_logging_sighandler();

/* Send version now. */
status_send(take(towire_status_version(NULL, version())));
}

static void destroy_daemon_conn(struct daemon_conn *dc UNUSED)
Expand All @@ -75,6 +79,9 @@ void status_setup_async(struct daemon_conn *master)
tal_add_destructor(master, destroy_daemon_conn);

setup_logging_sighandler();

/* Send version now. */
status_send(take(towire_status_version(NULL, version())));
}

void status_send(const u8 *msg TAKES)
Expand Down
3 changes: 3 additions & 0 deletions common/status_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ msgtype,status_peer_connection_lost,0xFFF3
msgtype,status_peer_billboard,0xFFF5
msgdata,status_peer_billboard,perm,bool,
msgdata,status_peer_billboard,happenings,wirestring,

msgtype,status_version,0xFFF6
msgdata,status_version,version,wirestring,
# Note: 0xFFFF is reserved for MSG_PASS_FD!
25 changes: 24 additions & 1 deletion common/status_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion common/status_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions lightningd/subd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <ccan/io/fdpass/fdpass.h>
#include <ccan/io/io.h>
Expand All @@ -12,6 +13,7 @@
#include <common/peer_status_wiregen.h>
#include <common/per_peer_state.h>
#include <common/status_wiregen.h>
#include <common/version.h>
#include <errno.h>
#include <fcntl.h>
#include <lightningd/lightningd.h>
Expand Down Expand Up @@ -402,6 +404,20 @@ static bool handle_set_billboard(struct subd *sd, const u8 *msg)
return true;
}

static bool handle_version(struct subd *sd, const u8 *msg)
{
char *ver;

if (!fromwire_status_version(msg, msg, &ver))
return false;

if (!streq(ver, version())) {
fatal("subdaemon %s version '%s' not '%s'",
sd->name, ver, version());
}
return true;
}

static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
{
int type = fromwire_peektype(sd->msg_in);
Expand Down Expand Up @@ -455,6 +471,10 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
if (!handle_set_billboard(sd, sd->msg_in))
goto malformed;
goto next;
case WIRE_STATUS_VERSION:
if (!handle_version(sd, sd->msg_in))
goto malformed;
goto next;
}

if (sd->channel) {
Expand Down
3 changes: 3 additions & 0 deletions lightningd/test/run-find_my_abspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ bool fromwire_status_peer_billboard(const tal_t *ctx UNNEEDED, const void *p UNN
/* Generated stub for fromwire_status_peer_error */
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct channel_id *channel UNNEEDED, wirestring **desc UNNEEDED, bool *warning UNNEEDED, struct per_peer_state **pps UNNEEDED, u8 **error_for_them UNNEEDED)
{ fprintf(stderr, "fromwire_status_peer_error called!\n"); abort(); }
/* Generated stub for fromwire_status_version */
bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, wirestring **version UNNEEDED)
{ fprintf(stderr, "fromwire_status_version called!\n"); abort(); }
/* Generated stub for gossip_init */
void gossip_init(struct lightningd *ld UNNEEDED, int connectd_fd UNNEEDED)
{ fprintf(stderr, "gossip_init called!\n"); abort(); }
Expand Down