mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
status: new message for subdaemons to tell us their versions.
For this patch we simply abort if it's wrong. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a8fde9f11f
commit
b36e9fe473
@ -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
common/status_wiregen.c
generated
25
common/status_wiregen.c
generated
@ -25,6 +25,7 @@ const char *status_wire_name(int e)
|
||||
case WIRE_STATUS_FAIL: return "WIRE_STATUS_FAIL";
|
||||
case WIRE_STATUS_PEER_CONNECTION_LOST: return "WIRE_STATUS_PEER_CONNECTION_LOST";
|
||||
case WIRE_STATUS_PEER_BILLBOARD: return "WIRE_STATUS_PEER_BILLBOARD";
|
||||
case WIRE_STATUS_VERSION: return "WIRE_STATUS_VERSION";
|
||||
}
|
||||
|
||||
snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e);
|
||||
@ -39,6 +40,7 @@ bool status_wire_is_defined(u16 type)
|
||||
case WIRE_STATUS_FAIL:;
|
||||
case WIRE_STATUS_PEER_CONNECTION_LOST:;
|
||||
case WIRE_STATUS_PEER_BILLBOARD:;
|
||||
case WIRE_STATUS_VERSION:;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -191,4 +193,25 @@ bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm,
|
||||
*happenings = fromwire_wirestring(ctx, &cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
// SHA256STAMP:67770c6a9a4205f10a455ea925afc2be4f853642b1e7ed70e3867221c64b7abc
|
||||
|
||||
/* WIRE: STATUS_VERSION */
|
||||
u8 *towire_status_version(const tal_t *ctx, const wirestring *version)
|
||||
{
|
||||
u8 *p = tal_arr(ctx, u8, 0);
|
||||
|
||||
towire_u16(&p, WIRE_STATUS_VERSION);
|
||||
towire_wirestring(&p, version);
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_status_version(const tal_t *ctx, const void *p, wirestring **version)
|
||||
{
|
||||
const u8 *cursor = p;
|
||||
size_t plen = tal_count(p);
|
||||
|
||||
if (fromwire_u16(&cursor, &plen) != WIRE_STATUS_VERSION)
|
||||
return false;
|
||||
*version = fromwire_wirestring(ctx, &cursor, &plen);
|
||||
return cursor != NULL;
|
||||
}
|
||||
// SHA256STAMP:8e1ba9cbc812c8aad76c5049fcecefea2d706a100423c93d3c3be0afcbee851e
|
||||
|
7
common/status_wiregen.h
generated
7
common/status_wiregen.h
generated
@ -17,6 +17,7 @@ enum status_wire {
|
||||
WIRE_STATUS_FAIL = 0xFFF2,
|
||||
WIRE_STATUS_PEER_CONNECTION_LOST = 0xFFF3,
|
||||
WIRE_STATUS_PEER_BILLBOARD = 0xFFF5,
|
||||
WIRE_STATUS_VERSION = 0xFFF6,
|
||||
};
|
||||
|
||||
const char *status_wire_name(int e);
|
||||
@ -51,6 +52,10 @@ bool fromwire_status_peer_connection_lost(const void *p);
|
||||
u8 *towire_status_peer_billboard(const tal_t *ctx, bool perm, const wirestring *happenings);
|
||||
bool fromwire_status_peer_billboard(const tal_t *ctx, const void *p, bool *perm, wirestring **happenings);
|
||||
|
||||
/* WIRE: STATUS_VERSION */
|
||||
u8 *towire_status_version(const tal_t *ctx, const wirestring *version);
|
||||
bool fromwire_status_version(const tal_t *ctx, const void *p, wirestring **version);
|
||||
|
||||
|
||||
#endif /* LIGHTNING_COMMON_STATUS_WIREGEN_H */
|
||||
// SHA256STAMP:67770c6a9a4205f10a455ea925afc2be4f853642b1e7ed70e3867221c64b7abc
|
||||
// SHA256STAMP:8e1ba9cbc812c8aad76c5049fcecefea2d706a100423c93d3c3be0afcbee851e
|
||||
|
@ -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>
|
||||
@ -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>
|
||||
@ -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);
|
||||
@ -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) {
|
||||
|
@ -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(); }
|
||||
|
Loading…
Reference in New Issue
Block a user