Browse Source

peer: Add custommsg hook and wire it into channeld and openingd

travis-debug
Christian Decker 5 years ago
parent
commit
ccec64d63c
  1. 2
      lightningd/channel_control.c
  2. 2
      lightningd/opening_control.c
  3. 39
      lightningd/peer_control.c
  4. 2
      lightningd/peer_control.h
  5. 3
      wallet/test/run-wallet.c

2
lightningd/channel_control.c

@ -323,7 +323,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
switch ((enum common_wire_type)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_IN:
/* TODO(cdecker) Add handling of custom messages. */
handle_custommsg_in(sd->ld, sd->node_id, msg);
break;
#else
case WIRE_CUSTOMMSG_IN:

2
lightningd/opening_control.c

@ -926,7 +926,7 @@ static unsigned int openingd_msg(struct subd *openingd,
switch ((enum common_wire_type)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_IN:
/* TODO(cdecker) Add handling of custom messages. */
handle_custommsg_in(openingd->ld, openingd->node_id, msg);
return 0;
#else
case WIRE_CUSTOMMSG_IN:

39
lightningd/peer_control.c

@ -2375,6 +2375,45 @@ void peer_dev_memleak(struct command *cmd)
peer_memleak_req_next(cmd, NULL);
}
struct custommsg_payload {
struct node_id peer_id;
const u8 *msg;
};
static void custommsg_callback(struct custommsg_payload *payload,
const char *buffer, const jsmntok_t *toks)
{
tal_free(payload);
}
static void custommsg_payload_serialize(struct custommsg_payload *payload,
struct json_stream *stream)
{
json_add_hex_talarr(stream, "message", payload->msg);
json_add_node_id(stream, "peer_id", &payload->peer_id);
}
REGISTER_PLUGIN_HOOK(custommsg, custommsg_callback, struct custommsg_payload *,
custommsg_payload_serialize, struct custommsg_payload *);
void handle_custommsg_in(struct lightningd *ld, const struct node_id *peer_id,
const u8 *msg)
{
struct custommsg_payload *p = tal(NULL, struct custommsg_payload);
u8 *custommsg;
if (!fromwire_custommsg_in(NULL, msg, &custommsg)) {
log_broken(ld->log, "Malformed custommsg from peer %s: %s",
type_to_string(tmpctx, struct node_id, peer_id),
tal_hex(tmpctx, msg));
return;
}
p->peer_id = *peer_id;
p->msg = tal_steal(p, custommsg);
plugin_hook_call_custommsg(ld, p, p);
}
static struct command_result *json_sendcustommsg(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,

2
lightningd/peer_control.h

@ -93,6 +93,8 @@ struct htlc_in_map *load_channels_from_wallet(struct lightningd *ld);
#if DEVELOPER
void peer_dev_memleak(struct command *cmd);
void handle_custommsg_in(struct lightningd *ld, const struct node_id *peer_id,
const u8 *msg);
#endif /* DEVELOPER */
/* Triggered at each new block. */

3
wallet/test/run-wallet.c

@ -111,6 +111,9 @@ bool fromwire_channel_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p
/* Generated stub for fromwire_connect_peer_connected */
bool fromwire_connect_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct per_peer_state **pps UNNEEDED, u8 **features UNNEEDED)
{ fprintf(stderr, "fromwire_connect_peer_connected called!\n"); abort(); }
/* Generated stub for fromwire_custommsg_in */
bool fromwire_custommsg_in(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **msg UNNEEDED)
{ fprintf(stderr, "fromwire_custommsg_in called!\n"); abort(); }
/* Generated stub for fromwire_gossip_get_channel_peer_reply */
bool fromwire_gossip_get_channel_peer_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id **peer_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_get_channel_peer_reply called!\n"); abort(); }

Loading…
Cancel
Save