diff --git a/channeld/channeld.c b/channeld/channeld.c index dd1939445..ab814c127 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2270,6 +2270,7 @@ static void peer_in(struct peer *peer, const u8 *msg) case WIRE_PONG: case WIRE_WARNING: case WIRE_ERROR: + case WIRE_ONION_MESSAGE: case WIRE_OBS_ONION_MESSAGE: abort(); } diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 71f6d5289..1af3977cc 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -380,7 +380,7 @@ static bool handle_local_channel_announcement(struct daemon *daemon, return true; } -/* Peer sends onion msg. */ +/* Peer sends obsolete onion msg. */ static u8 *handle_obs_onion_message(struct peer *peer, const u8 *msg) { enum onion_wire badreason; @@ -609,6 +609,13 @@ static u8 *handle_obs_onion_message(struct peer *peer, const u8 *msg) return NULL; } +/* Peer sends onion msg. */ +static u8 *handle_onion_message(struct peer *peer, const u8 *msg) +{ + /* FIXME */ + return NULL; +} + /* We send an obsolete onion msg. */ static struct io_plan *obs_onionmsg_req(struct io_conn *conn, struct daemon *daemon, const u8 *msg) @@ -641,6 +648,28 @@ static struct io_plan *obs_onionmsg_req(struct io_conn *conn, struct daemon *dae return daemon_conn_read_next(conn, daemon->master); } +static struct io_plan *onionmsg_req(struct io_conn *conn, struct daemon *daemon, + const u8 *msg) +{ + struct node_id id; + u8 *onionmsg; + struct pubkey blinding; + struct peer *peer; + + if (!fromwire_gossipd_send_onionmsg(msg, msg, &id, &onionmsg, &blinding)) + master_badmsg(WIRE_GOSSIPD_SEND_ONIONMSG, msg); + + /* Even though lightningd checks for valid ids, there's a race + * where it might vanish before we read this command. */ + peer = find_peer(daemon, &id); + if (peer) { + queue_peer_msg(peer, + take(towire_onion_message(NULL, + &blinding, onionmsg))); + } + return daemon_conn_read_next(conn, daemon->master); +} + /*~ This is where the per-peer daemons send us messages. It's either forwarded * gossip, or a request for information. We deliberately use non-overlapping * message types so we can distinguish them. */ @@ -683,6 +712,9 @@ static struct io_plan *peer_msg_in(struct io_conn *conn, case WIRE_OBS_ONION_MESSAGE: err = handle_obs_onion_message(peer, msg); goto handled_relay; + case WIRE_ONION_MESSAGE: + err = handle_onion_message(peer, msg); + goto handled_relay; /* These are non-gossip messages (!is_msg_for_gossipd()) */ case WIRE_WARNING: @@ -1509,6 +1541,10 @@ static struct io_plan *recv_req(struct io_conn *conn, case WIRE_GOSSIPD_SEND_OBS_ONIONMSG: return obs_onionmsg_req(conn, daemon, msg); + + case WIRE_GOSSIPD_SEND_ONIONMSG: + return onionmsg_req(conn, daemon, msg); + /* We send these, we don't receive them */ case WIRE_GOSSIPD_PING_REPLY: case WIRE_GOSSIPD_INIT_REPLY: @@ -1518,6 +1554,7 @@ static struct io_plan *recv_req(struct io_conn *conn, case WIRE_GOSSIPD_DEV_COMPACT_STORE_REPLY: case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_TO_US: case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_FORWARD: + case WIRE_GOSSIPD_GOT_ONIONMSG_TO_US: case WIRE_GOSSIPD_ADDGOSSIP_REPLY: break; } diff --git a/gossipd/gossipd_wire.csv b/gossipd/gossipd_wire.csv index c426f0341..636eac46a 100644 --- a/gossipd/gossipd_wire.csv +++ b/gossipd/gossipd_wire.csv @@ -103,6 +103,15 @@ msgdata,gossipd_got_obs_onionmsg_forward,next_blinding,?pubkey, msgdata,gossipd_got_obs_onionmsg_forward,next_onion_len,u16, msgdata,gossipd_got_obs_onionmsg_forward,next_onion,u8,next_onion_len +msgtype,gossipd_got_onionmsg_to_us,3145 +msgdata,gossipd_got_onionmsg_to_us,blinding_in,pubkey, +msgdata,gossipd_got_onionmsg_to_us,reply_blinding,?pubkey, +msgdata,gossipd_got_onionmsg_to_us,reply_first_node,?pubkey, +msgdata,gossipd_got_onionmsg_to_us,reply_path_len,u16, +msgdata,gossipd_got_onionmsg_to_us,reply_path,onionmsg_path,reply_path_len +msgdata,gossipd_got_onionmsg_to_us,rawmsg_len,u16, +msgdata,gossipd_got_onionmsg_to_us,rawmsg,u8,rawmsg_len + # Lightningd tells us to send a onion message. msgtype,gossipd_send_obs_onionmsg,3040 msgdata,gossipd_send_obs_onionmsg,id,node_id, @@ -110,6 +119,12 @@ msgdata,gossipd_send_obs_onionmsg,onion_len,u16, msgdata,gossipd_send_obs_onionmsg,onion,u8,onion_len msgdata,gossipd_send_obs_onionmsg,blinding,?pubkey, +msgtype,gossipd_send_onionmsg,3041 +msgdata,gossipd_send_onionmsg,id,node_id, +msgdata,gossipd_send_onionmsg,onion_len,u16, +msgdata,gossipd_send_onionmsg,onion,u8,onion_len +msgdata,gossipd_send_onionmsg,blinding,pubkey, + # Lightningd tells us to inject a gossip message (for addgossip RPC) msgtype,gossipd_addgossip,3044 msgdata,gossipd_addgossip,len,u16, diff --git a/gossipd/gossipd_wiregen.c b/gossipd/gossipd_wiregen.c index 78f00781b..e1e3271a0 100644 --- a/gossipd/gossipd_wiregen.c +++ b/gossipd/gossipd_wiregen.c @@ -40,7 +40,9 @@ const char *gossipd_wire_name(int e) case WIRE_GOSSIPD_NEW_BLOCKHEIGHT: return "WIRE_GOSSIPD_NEW_BLOCKHEIGHT"; case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_TO_US: return "WIRE_GOSSIPD_GOT_OBS_ONIONMSG_TO_US"; case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_FORWARD: return "WIRE_GOSSIPD_GOT_OBS_ONIONMSG_FORWARD"; + case WIRE_GOSSIPD_GOT_ONIONMSG_TO_US: return "WIRE_GOSSIPD_GOT_ONIONMSG_TO_US"; case WIRE_GOSSIPD_SEND_OBS_ONIONMSG: return "WIRE_GOSSIPD_SEND_OBS_ONIONMSG"; + case WIRE_GOSSIPD_SEND_ONIONMSG: return "WIRE_GOSSIPD_SEND_ONIONMSG"; case WIRE_GOSSIPD_ADDGOSSIP: return "WIRE_GOSSIPD_ADDGOSSIP"; case WIRE_GOSSIPD_ADDGOSSIP_REPLY: return "WIRE_GOSSIPD_ADDGOSSIP_REPLY"; case WIRE_GOSSIPD_NEW_LEASE_RATES: return "WIRE_GOSSIPD_NEW_LEASE_RATES"; @@ -73,7 +75,9 @@ bool gossipd_wire_is_defined(u16 type) case WIRE_GOSSIPD_NEW_BLOCKHEIGHT:; case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_TO_US:; case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_FORWARD:; + case WIRE_GOSSIPD_GOT_ONIONMSG_TO_US:; case WIRE_GOSSIPD_SEND_OBS_ONIONMSG:; + case WIRE_GOSSIPD_SEND_ONIONMSG:; case WIRE_GOSSIPD_ADDGOSSIP:; case WIRE_GOSSIPD_ADDGOSSIP_REPLY:; case WIRE_GOSSIPD_NEW_LEASE_RATES:; @@ -662,6 +666,70 @@ bool fromwire_gossipd_got_obs_onionmsg_forward(const tal_t *ctx, const void *p, return cursor != NULL; } +/* WIRE: GOSSIPD_GOT_ONIONMSG_TO_US */ +u8 *towire_gossipd_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in, const struct pubkey *reply_blinding, const struct pubkey *reply_first_node, const struct onionmsg_path **reply_path, const u8 *rawmsg) +{ + u16 reply_path_len = tal_count(reply_path); + u16 rawmsg_len = tal_count(rawmsg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_GOT_ONIONMSG_TO_US); + towire_pubkey(&p, blinding_in); + if (!reply_blinding) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, reply_blinding); + } + if (!reply_first_node) + towire_bool(&p, false); + else { + towire_bool(&p, true); + towire_pubkey(&p, reply_first_node); + } + towire_u16(&p, reply_path_len); + for (size_t i = 0; i < reply_path_len; i++) + towire_onionmsg_path(&p, reply_path[i]); + towire_u16(&p, rawmsg_len); + towire_u8_array(&p, rawmsg, rawmsg_len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey *blinding_in, struct pubkey **reply_blinding, struct pubkey **reply_first_node, struct onionmsg_path ***reply_path, u8 **rawmsg) +{ + u16 reply_path_len; + u16 rawmsg_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GOT_ONIONMSG_TO_US) + return false; + fromwire_pubkey(&cursor, &plen, blinding_in); + if (!fromwire_bool(&cursor, &plen)) + *reply_blinding = NULL; + else { + *reply_blinding = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *reply_blinding); + } + if (!fromwire_bool(&cursor, &plen)) + *reply_first_node = NULL; + else { + *reply_first_node = tal(ctx, struct pubkey); + fromwire_pubkey(&cursor, &plen, *reply_first_node); + } + reply_path_len = fromwire_u16(&cursor, &plen); + // 2nd case reply_path + *reply_path = reply_path_len ? tal_arr(ctx, struct onionmsg_path *, reply_path_len) : NULL; + for (size_t i = 0; i < reply_path_len; i++) + (*reply_path)[i] = fromwire_onionmsg_path(*reply_path, &cursor, &plen); + rawmsg_len = fromwire_u16(&cursor, &plen); + // 2nd case rawmsg + *rawmsg = rawmsg_len ? tal_arr(ctx, u8, rawmsg_len) : NULL; + fromwire_u8_array(&cursor, &plen, *rawmsg, rawmsg_len); + return cursor != NULL; +} + /* WIRE: GOSSIPD_SEND_OBS_ONIONMSG */ /* Lightningd tells us to send a onion message. */ u8 *towire_gossipd_send_obs_onionmsg(const tal_t *ctx, const struct node_id *id, const u8 *onion, const struct pubkey *blinding) @@ -705,6 +773,38 @@ bool fromwire_gossipd_send_obs_onionmsg(const tal_t *ctx, const void *p, struct return cursor != NULL; } +/* WIRE: GOSSIPD_SEND_ONIONMSG */ +u8 *towire_gossipd_send_onionmsg(const tal_t *ctx, const struct node_id *id, const u8 *onion, const struct pubkey *blinding) +{ + u16 onion_len = tal_count(onion); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_GOSSIPD_SEND_ONIONMSG); + towire_node_id(&p, id); + towire_u16(&p, onion_len); + towire_u8_array(&p, onion, onion_len); + towire_pubkey(&p, blinding); + + return memcheck(p, tal_count(p)); +} +bool fromwire_gossipd_send_onionmsg(const tal_t *ctx, const void *p, struct node_id *id, u8 **onion, struct pubkey *blinding) +{ + u16 onion_len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_SEND_ONIONMSG) + return false; + fromwire_node_id(&cursor, &plen, id); + onion_len = fromwire_u16(&cursor, &plen); + // 2nd case onion + *onion = onion_len ? tal_arr(ctx, u8, onion_len) : NULL; + fromwire_u8_array(&cursor, &plen, *onion, onion_len); + fromwire_pubkey(&cursor, &plen, blinding); + return cursor != NULL; +} + /* WIRE: GOSSIPD_ADDGOSSIP */ /* Lightningd tells us to inject a gossip message (for addgossip RPC) */ u8 *towire_gossipd_addgossip(const tal_t *ctx, const u8 *msg) @@ -777,4 +877,4 @@ bool fromwire_gossipd_new_lease_rates(const void *p, struct lease_rates *rates) fromwire_lease_rates(&cursor, &plen, rates); return cursor != NULL; } -// SHA256STAMP:d06e71483fdad04048e15d46b823420747d5f79efc97fa968752fa04b033d551 +// SHA256STAMP:aacb7a093fb63386eb9fa20a51d07c995ae363283a4b76d94ba3cd09ec298df2 diff --git a/gossipd/gossipd_wiregen.h b/gossipd/gossipd_wiregen.h index 1d8ae4a33..95e5476ee 100644 --- a/gossipd/gossipd_wiregen.h +++ b/gossipd/gossipd_wiregen.h @@ -49,8 +49,10 @@ enum gossipd_wire { /* Tell lightningd we got an obsolete onion message (for us */ WIRE_GOSSIPD_GOT_OBS_ONIONMSG_TO_US = 3142, WIRE_GOSSIPD_GOT_OBS_ONIONMSG_FORWARD = 3143, + WIRE_GOSSIPD_GOT_ONIONMSG_TO_US = 3145, /* Lightningd tells us to send a onion message. */ WIRE_GOSSIPD_SEND_OBS_ONIONMSG = 3040, + WIRE_GOSSIPD_SEND_ONIONMSG = 3041, /* Lightningd tells us to inject a gossip message (for addgossip RPC) */ WIRE_GOSSIPD_ADDGOSSIP = 3044, /* Empty string means no problem. */ @@ -166,11 +168,19 @@ bool fromwire_gossipd_got_obs_onionmsg_to_us(const tal_t *ctx, const void *p, st u8 *towire_gossipd_got_obs_onionmsg_forward(const tal_t *ctx, const struct short_channel_id *next_scid, const struct node_id *next_node_id, const struct pubkey *next_blinding, const u8 *next_onion); bool fromwire_gossipd_got_obs_onionmsg_forward(const tal_t *ctx, const void *p, struct short_channel_id **next_scid, struct node_id **next_node_id, struct pubkey **next_blinding, u8 **next_onion); +/* WIRE: GOSSIPD_GOT_ONIONMSG_TO_US */ +u8 *towire_gossipd_got_onionmsg_to_us(const tal_t *ctx, const struct pubkey *blinding_in, const struct pubkey *reply_blinding, const struct pubkey *reply_first_node, const struct onionmsg_path **reply_path, const u8 *rawmsg); +bool fromwire_gossipd_got_onionmsg_to_us(const tal_t *ctx, const void *p, struct pubkey *blinding_in, struct pubkey **reply_blinding, struct pubkey **reply_first_node, struct onionmsg_path ***reply_path, u8 **rawmsg); + /* WIRE: GOSSIPD_SEND_OBS_ONIONMSG */ /* Lightningd tells us to send a onion message. */ u8 *towire_gossipd_send_obs_onionmsg(const tal_t *ctx, const struct node_id *id, const u8 *onion, const struct pubkey *blinding); bool fromwire_gossipd_send_obs_onionmsg(const tal_t *ctx, const void *p, struct node_id *id, u8 **onion, struct pubkey **blinding); +/* WIRE: GOSSIPD_SEND_ONIONMSG */ +u8 *towire_gossipd_send_onionmsg(const tal_t *ctx, const struct node_id *id, const u8 *onion, const struct pubkey *blinding); +bool fromwire_gossipd_send_onionmsg(const tal_t *ctx, const void *p, struct node_id *id, u8 **onion, struct pubkey *blinding); + /* WIRE: GOSSIPD_ADDGOSSIP */ /* Lightningd tells us to inject a gossip message (for addgossip RPC) */ u8 *towire_gossipd_addgossip(const tal_t *ctx, const u8 *msg); @@ -188,4 +198,4 @@ bool fromwire_gossipd_new_lease_rates(const void *p, struct lease_rates *rates); #endif /* LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H */ -// SHA256STAMP:d06e71483fdad04048e15d46b823420747d5f79efc97fa968752fa04b033d551 +// SHA256STAMP:aacb7a093fb63386eb9fa20a51d07c995ae363283a4b76d94ba3cd09ec298df2 diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index b9ac3346d..4a530a832 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -126,6 +126,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIPD_DEV_SET_TIME: case WIRE_GOSSIPD_NEW_BLOCKHEIGHT: case WIRE_GOSSIPD_SEND_OBS_ONIONMSG: + case WIRE_GOSSIPD_SEND_ONIONMSG: case WIRE_GOSSIPD_ADDGOSSIP: /* This is a reply, so never gets through to here. */ case WIRE_GOSSIPD_INIT_REPLY: @@ -141,6 +142,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIPD_GOT_OBS_ONIONMSG_FORWARD: handle_obs_onionmsg_forward(gossip->ld, msg); break; + case WIRE_GOSSIPD_GOT_ONIONMSG_TO_US: + handle_onionmsg_to_us(gossip->ld, msg); + break; case WIRE_GOSSIPD_PING_REPLY: ping_reply(gossip, msg); break; diff --git a/lightningd/onion_message.c b/lightningd/onion_message.c index 8a5afbff9..c3f4e0a77 100644 --- a/lightningd/onion_message.c +++ b/lightningd/onion_message.c @@ -171,6 +171,12 @@ void handle_obs_onionmsg_forward(struct lightningd *ld, const u8 *msg) } } +void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg) +{ + /* FIXME! */ + return; +} + struct hop { struct pubkey id; struct short_channel_id *scid; diff --git a/lightningd/onion_message.h b/lightningd/onion_message.h index 722dc606c..02f93f8d2 100644 --- a/lightningd/onion_message.h +++ b/lightningd/onion_message.h @@ -8,4 +8,6 @@ struct lightningd; void handle_obs_onionmsg_to_us(struct lightningd *ld, const u8 *msg); void handle_obs_onionmsg_forward(struct lightningd *ld, const u8 *msg); +void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg); + #endif /* LIGHTNING_LIGHTNINGD_ONION_MESSAGE_H */ diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 0be919da0..7b8497d34 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -1283,6 +1283,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state) case WIRE_CHANNEL_REESTABLISH: case WIRE_ANNOUNCEMENT_SIGNATURES: case WIRE_GOSSIP_TIMESTAMP_FILTER: + case WIRE_ONION_MESSAGE: case WIRE_OBS_ONION_MESSAGE: case WIRE_ACCEPT_CHANNEL2: case WIRE_TX_ADD_INPUT: @@ -1631,6 +1632,7 @@ static bool run_tx_interactive(struct state *state, case WIRE_CHANNEL_REESTABLISH: case WIRE_ANNOUNCEMENT_SIGNATURES: case WIRE_GOSSIP_TIMESTAMP_FILTER: + case WIRE_ONION_MESSAGE: case WIRE_OBS_ONION_MESSAGE: case WIRE_TX_SIGNATURES: case WIRE_OPEN_CHANNEL2: @@ -3689,6 +3691,7 @@ static u8 *handle_peer_in(struct state *state) case WIRE_CHANNEL_REESTABLISH: case WIRE_ANNOUNCEMENT_SIGNATURES: case WIRE_GOSSIP_TIMESTAMP_FILTER: + case WIRE_ONION_MESSAGE: case WIRE_OBS_ONION_MESSAGE: case WIRE_ACCEPT_CHANNEL2: case WIRE_TX_ADD_INPUT: diff --git a/wire/extracted_onion_02_newonion.patch b/wire/extracted_onion_02_newonion.patch new file mode 100644 index 000000000..6a36d3516 --- /dev/null +++ b/wire/extracted_onion_02_newonion.patch @@ -0,0 +1,30 @@ +--- onion_wire.csv 2021-08-25 12:41:02.872253965 +0930 ++++ onion_wire.csv.raw 2021-08-25 13:52:00.748767887 +0930 +@@ -8,6 +8,10 @@ tlvdata,tlv_payload,short_channel_id,short_channel_id,short_channel_id, + tlvtype,tlv_payload,payment_data,8 + tlvdata,tlv_payload,payment_data,payment_secret,byte,32 + tlvdata,tlv_payload,payment_data,total_msat,tu64, ++tlvtype,onionmsg_payload,reply_path,2 ++tlvdata,onionmsg_payload,reply_path,first_node_id,point, ++tlvdata,onionmsg_payload,reply_path,blinding,point, ++tlvdata,onionmsg_payload,reply_path,path,onionmsg_path,... + tlvtype,onionmsg_payload,obs_next_node_id,4 + tlvdata,onionmsg_payload,obs_next_node_id,node_id,point, + tlvtype,onionmsg_payload,obs_next_short_channel_id,6 +@@ -29,10 +29,16 @@ tlvtype,onionmsg_payload,invoice,66 + tlvdata,onionmsg_payload,invoice,invoice,byte,... + tlvtype,onionmsg_payload,invoice_error,68 + tlvdata,onionmsg_payload,invoice_error,invoice_error,byte,... ++tlvtype,encmsg_tlvs,padding,1 ++tlvdata,encmsg_tlvs,padding,pad,byte,... + tlvtype,encmsg_tlvs,next_node_id,4 + tlvdata,encmsg_tlvs,next_node_id,node_id,point, + tlvtype,encmsg_tlvs,obs_next_short_channel_id,6 + tlvdata,encmsg_tlvs,obs_next_short_channel_id,short_channel_id,short_channel_id, ++tlvtype,encmsg_tlvs,next_blinding,12 ++tlvdata,encmsg_tlvs,next_blinding,blinding,point, ++tlvtype,encmsg_tlvs,self_id,14 ++tlvdata,encmsg_tlvs,self_id,data,byte,... + subtype,onionmsg_path + subtypedata,onionmsg_path,node_id,point, + subtypedata,onionmsg_path,enclen,u16, diff --git a/wire/extracted_onion_exp_enctlv.patch b/wire/extracted_onion_exp_enctlv.patch index 8fa482161..ea55b7704 100644 --- a/wire/extracted_onion_exp_enctlv.patch +++ b/wire/extracted_onion_exp_enctlv.patch @@ -8,7 +8,6 @@ +tlvdata,tlv_payload,enctlv,enctlv,byte,... +tlvtype,tlv_payload,blinding_seed,12 +tlvdata,tlv_payload,blinding_seed,blinding_seed,pubkey, - tlvtype,onionmsg_payload,obs_next_node_id,4 - tlvdata,onionmsg_payload,obs_next_node_id,node_id,point, - tlvtype,onionmsg_payload,obs_next_short_channel_id,6 - + tlvtype,onionmsg_payload,reply_path,2 + tlvdata,onionmsg_payload,reply_path,first_node_id,point, + tlvdata,onionmsg_payload,reply_path,blinding,point, diff --git a/wire/extracted_peer_05_newonion.patch b/wire/extracted_peer_05_newonion.patch new file mode 100644 index 000000000..97c1629e5 --- /dev/null +++ b/wire/extracted_peer_05_newonion.patch @@ -0,0 +1,10 @@ +--- peer_wire.csv 2021-08-25 12:41:02.876254003 +0930 ++++ peer_wire.csv.raw 2021-08-25 13:42:31.991693809 +0930 +@@ -320,3 +210,7 @@ + msgdata,obs_onion_message,obs_onion_message_tlvs,obs_onion_message_tlvs, + tlvtype,obs_onion_message_tlvs,blinding,2 + tlvdata,obs_onion_message_tlvs,blinding,blinding,point, ++msgtype,onion_message,387,option_onion_messages ++msgdata,onion_message,blinding,point, ++msgdata,onion_message,len,u16, ++msgdata,onion_message,onionmsg,byte,len diff --git a/wire/onion_printgen.c b/wire/onion_printgen.c index f75376225..9d844fa31 100644 --- a/wire/onion_printgen.c +++ b/wire/onion_printgen.c @@ -207,6 +207,43 @@ static const struct tlv_print_record_type print_tlvs_tlv_payload[] = { { 8, printwire_tlv_tlv_payload_payment_data }, }; +static void printwire_tlv_onionmsg_payload_reply_path(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "reply_path"); + + printf("first_node_id="); + struct pubkey first_node_id; + fromwire_pubkey(cursor, plen, &first_node_id); + + printwire_pubkey(tal_fmt(NULL, "%s.first_node_id", fieldname), &first_node_id); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("blinding="); + struct pubkey blinding; + fromwire_pubkey(cursor, plen, &blinding); + + printwire_pubkey(tal_fmt(NULL, "%s.blinding", fieldname), &blinding); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("path="); + printf("["); + for (size_t i = 0; i < *plen; i++) { + printf("{\n"); + printwire_onionmsg_path(tal_fmt(NULL, "%s.path", fieldname), cursor, plen); + printf("}\n"); + } + printf("]"); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} static void printwire_tlv_onionmsg_payload_obs_next_node_id(const char *fieldname, const u8 **cursor, size_t *plen) { printf("(msg_name=%s)\n", "obs_next_node_id"); @@ -334,6 +371,7 @@ static void printwire_tlv_onionmsg_payload_invoice_error(const char *fieldname, } static const struct tlv_print_record_type print_tlvs_onionmsg_payload[] = { + { 2, printwire_tlv_onionmsg_payload_reply_path }, { 4, printwire_tlv_onionmsg_payload_obs_next_node_id }, { 6, printwire_tlv_onionmsg_payload_obs_next_short_channel_id }, { 8, printwire_tlv_onionmsg_payload_obs_reply_path }, @@ -344,6 +382,19 @@ static const struct tlv_print_record_type print_tlvs_onionmsg_payload[] = { { 68, printwire_tlv_onionmsg_payload_invoice_error }, }; +static void printwire_tlv_encmsg_tlvs_padding(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "padding"); + + printf("pad="); + printwire_u8_array(tal_fmt(NULL, "%s.pad", fieldname), cursor, plen, *plen); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} static void printwire_tlv_encmsg_tlvs_next_node_id(const char *fieldname, const u8 **cursor, size_t *plen) { printf("(msg_name=%s)\n", "next_node_id"); @@ -373,11 +424,42 @@ static void printwire_tlv_encmsg_tlvs_obs_next_short_channel_id(const char *fiel return; } +} +static void printwire_tlv_encmsg_tlvs_next_blinding(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "next_blinding"); + + printf("blinding="); + struct pubkey blinding; + fromwire_pubkey(cursor, plen, &blinding); + + printwire_pubkey(tal_fmt(NULL, "%s.blinding", fieldname), &blinding); + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + +} +static void printwire_tlv_encmsg_tlvs_self_id(const char *fieldname, const u8 **cursor, size_t *plen) +{ + printf("(msg_name=%s)\n", "self_id"); + + printf("data="); + printwire_u8_array(tal_fmt(NULL, "%s.data", fieldname), cursor, plen, *plen); + + if (!*cursor) { + printf("**TRUNCATED**\n"); + return; + } + } static const struct tlv_print_record_type print_tlvs_encmsg_tlvs[] = { + { 1, printwire_tlv_encmsg_tlvs_padding }, { 4, printwire_tlv_encmsg_tlvs_next_node_id }, { 6, printwire_tlv_encmsg_tlvs_obs_next_short_channel_id }, + { 12, printwire_tlv_encmsg_tlvs_next_blinding }, + { 14, printwire_tlv_encmsg_tlvs_self_id }, }; void printwire_invalid_realm(const char *fieldname, const u8 *cursor) { @@ -859,4 +941,4 @@ void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_encmsg_tlvs, ARRAY_SIZE(print_tlvs_encmsg_tlvs)); } } -// SHA256STAMP:6564b6a17750dfd460f88f9c484964a5fbfdfd77242c1b5c9986e4d69e00d387 +// SHA256STAMP:dc74e1b66f37a96bed7d2ab3f5b83fdf7cbe4ee7775ebda3ee43812e75f260ba diff --git a/wire/onion_printgen.h b/wire/onion_printgen.h index 6d10fbe33..2f9b3ef05 100644 --- a/wire/onion_printgen.h +++ b/wire/onion_printgen.h @@ -58,4 +58,4 @@ void printwire_mpp_timeout(const char *fieldname, const u8 *cursor); void printwire_onionmsg_path(const char *fieldname, const u8 **cursor, size_t *plen); #endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */ -// SHA256STAMP:6564b6a17750dfd460f88f9c484964a5fbfdfd77242c1b5c9986e4d69e00d387 +// SHA256STAMP:dc74e1b66f37a96bed7d2ab3f5b83fdf7cbe4ee7775ebda3ee43812e75f260ba diff --git a/wire/onion_wire.csv b/wire/onion_wire.csv index 74847bc84..e60849a87 100644 --- a/wire/onion_wire.csv +++ b/wire/onion_wire.csv @@ -8,6 +8,10 @@ tlvdata,tlv_payload,short_channel_id,short_channel_id,short_channel_id, tlvtype,tlv_payload,payment_data,8 tlvdata,tlv_payload,payment_data,payment_secret,byte,32 tlvdata,tlv_payload,payment_data,total_msat,tu64, +tlvtype,onionmsg_payload,reply_path,2 +tlvdata,onionmsg_payload,reply_path,first_node_id,point, +tlvdata,onionmsg_payload,reply_path,blinding,point, +tlvdata,onionmsg_payload,reply_path,path,onionmsg_path,... tlvtype,onionmsg_payload,obs_next_node_id,4 tlvdata,onionmsg_payload,obs_next_node_id,node_id,point, tlvtype,onionmsg_payload,obs_next_short_channel_id,6 @@ -25,10 +29,16 @@ tlvtype,onionmsg_payload,invoice,66 tlvdata,onionmsg_payload,invoice,invoice,byte,... tlvtype,onionmsg_payload,invoice_error,68 tlvdata,onionmsg_payload,invoice_error,invoice_error,byte,... +tlvtype,encmsg_tlvs,padding,1 +tlvdata,encmsg_tlvs,padding,pad,byte,... tlvtype,encmsg_tlvs,next_node_id,4 tlvdata,encmsg_tlvs,next_node_id,node_id,point, tlvtype,encmsg_tlvs,obs_next_short_channel_id,6 tlvdata,encmsg_tlvs,obs_next_short_channel_id,short_channel_id,short_channel_id, +tlvtype,encmsg_tlvs,next_blinding,12 +tlvdata,encmsg_tlvs,next_blinding,blinding,point, +tlvtype,encmsg_tlvs,self_id,14 +tlvdata,encmsg_tlvs,self_id,data,byte,... subtype,onionmsg_path subtypedata,onionmsg_path,node_id,point, subtypedata,onionmsg_path,enclen,u16, diff --git a/wire/onion_wiregen.c b/wire/onion_wiregen.c index a336bd869..577df14aa 100644 --- a/wire/onion_wiregen.c +++ b/wire/onion_wiregen.c @@ -244,6 +244,40 @@ struct tlv_onionmsg_payload *tlv_onionmsg_payload_new(const tal_t *ctx) return inst; } +/* ONIONMSG_PAYLOAD MSG: reply_path */ +static u8 *towire_tlv_onionmsg_payload_reply_path(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_onionmsg_payload *r = vrecord; + u8 *ptr; + + if (!r->reply_path) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_pubkey(&ptr, &r->reply_path->first_node_id); + + towire_pubkey(&ptr, &r->reply_path->blinding); + + for (size_t i = 0; i < tal_count(r->reply_path->path); i++) + towire_onionmsg_path(&ptr, r->reply_path->path[i]); + return ptr; +} +static void fromwire_tlv_onionmsg_payload_reply_path(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_onionmsg_payload *r = vrecord; + + r->reply_path = tal(r, struct tlv_onionmsg_payload_reply_path); + fromwire_pubkey(cursor, plen, &r->reply_path->first_node_id); + fromwire_pubkey(cursor, plen, &r->reply_path->blinding); + r->reply_path->path = *plen ? tal_arr(r->reply_path, struct onionmsg_path *, 0) : NULL; + for (size_t i = 0; *plen != 0; i++) { + struct onionmsg_path * tmp; + tmp = fromwire_onionmsg_path(r->reply_path, cursor, plen); + tal_arr_expand(&r->reply_path->path, tmp); + } +} /* ONIONMSG_PAYLOAD MSG: obs_next_node_id */ static u8 *towire_tlv_onionmsg_payload_obs_next_node_id(const tal_t *ctx, const void *vrecord) { @@ -434,6 +468,7 @@ fromwire_u8_array(cursor, plen, r->invoice_error, *plen); } static const struct tlv_record_type tlvs_onionmsg_payload[] = { + { 2, towire_tlv_onionmsg_payload_reply_path, fromwire_tlv_onionmsg_payload_reply_path }, { 4, towire_tlv_onionmsg_payload_obs_next_node_id, fromwire_tlv_onionmsg_payload_obs_next_node_id }, { 6, towire_tlv_onionmsg_payload_obs_next_short_channel_id, fromwire_tlv_onionmsg_payload_obs_next_short_channel_id }, { 8, towire_tlv_onionmsg_payload_obs_reply_path, fromwire_tlv_onionmsg_payload_obs_reply_path }, @@ -446,13 +481,13 @@ static const struct tlv_record_type tlvs_onionmsg_payload[] = { void towire_onionmsg_payload(u8 **pptr, const struct tlv_onionmsg_payload *record) { - towire_tlv(pptr, tlvs_onionmsg_payload, 8, record); + towire_tlv(pptr, tlvs_onionmsg_payload, 9, record); } bool fromwire_onionmsg_payload(const u8 **cursor, size_t *max, struct tlv_onionmsg_payload *record) { - return fromwire_tlv(cursor, max, tlvs_onionmsg_payload, 8, record, &record->fields); + return fromwire_tlv(cursor, max, tlvs_onionmsg_payload, 9, record, &record->fields); } bool onionmsg_payload_is_valid(const struct tlv_onionmsg_payload *record, size_t *err_index) @@ -471,6 +506,28 @@ struct tlv_encmsg_tlvs *tlv_encmsg_tlvs_new(const tal_t *ctx) return inst; } +/* ENCMSG_TLVS MSG: padding */ +static u8 *towire_tlv_encmsg_tlvs_padding(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_encmsg_tlvs *r = vrecord; + u8 *ptr; + + if (!r->padding) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u8_array(&ptr, r->padding, tal_count(r->padding)); + return ptr; +} +static void fromwire_tlv_encmsg_tlvs_padding(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_encmsg_tlvs *r = vrecord; + + r->padding = tal_arr(r, u8, *plen); +fromwire_u8_array(cursor, plen, r->padding, *plen); +} /* ENCMSG_TLVS MSG: next_node_id */ static u8 *towire_tlv_encmsg_tlvs_next_node_id(const tal_t *ctx, const void *vrecord) { @@ -517,21 +574,69 @@ static void fromwire_tlv_encmsg_tlvs_obs_next_short_channel_id(const u8 **cursor fromwire_short_channel_id(cursor, plen, &*r->obs_next_short_channel_id); } +/* ENCMSG_TLVS MSG: next_blinding */ +static u8 *towire_tlv_encmsg_tlvs_next_blinding(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_encmsg_tlvs *r = vrecord; + u8 *ptr; + + if (!r->next_blinding) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_pubkey(&ptr, r->next_blinding); + return ptr; +} +static void fromwire_tlv_encmsg_tlvs_next_blinding(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_encmsg_tlvs *r = vrecord; + + r->next_blinding = tal(r, struct pubkey); + +fromwire_pubkey(cursor, plen, &*r->next_blinding); +} +/* ENCMSG_TLVS MSG: self_id */ +static u8 *towire_tlv_encmsg_tlvs_self_id(const tal_t *ctx, const void *vrecord) +{ + const struct tlv_encmsg_tlvs *r = vrecord; + u8 *ptr; + + if (!r->self_id) + return NULL; + + + ptr = tal_arr(ctx, u8, 0); + + towire_u8_array(&ptr, r->self_id, tal_count(r->self_id)); + return ptr; +} +static void fromwire_tlv_encmsg_tlvs_self_id(const u8 **cursor, size_t *plen, void *vrecord) +{ + struct tlv_encmsg_tlvs *r = vrecord; + + r->self_id = tal_arr(r, u8, *plen); +fromwire_u8_array(cursor, plen, r->self_id, *plen); +} static const struct tlv_record_type tlvs_encmsg_tlvs[] = { + { 1, towire_tlv_encmsg_tlvs_padding, fromwire_tlv_encmsg_tlvs_padding }, { 4, towire_tlv_encmsg_tlvs_next_node_id, fromwire_tlv_encmsg_tlvs_next_node_id }, { 6, towire_tlv_encmsg_tlvs_obs_next_short_channel_id, fromwire_tlv_encmsg_tlvs_obs_next_short_channel_id }, + { 12, towire_tlv_encmsg_tlvs_next_blinding, fromwire_tlv_encmsg_tlvs_next_blinding }, + { 14, towire_tlv_encmsg_tlvs_self_id, fromwire_tlv_encmsg_tlvs_self_id }, }; void towire_encmsg_tlvs(u8 **pptr, const struct tlv_encmsg_tlvs *record) { - towire_tlv(pptr, tlvs_encmsg_tlvs, 2, record); + towire_tlv(pptr, tlvs_encmsg_tlvs, 5, record); } bool fromwire_encmsg_tlvs(const u8 **cursor, size_t *max, struct tlv_encmsg_tlvs *record) { - return fromwire_tlv(cursor, max, tlvs_encmsg_tlvs, 2, record, &record->fields); + return fromwire_tlv(cursor, max, tlvs_encmsg_tlvs, 5, record, &record->fields); } bool encmsg_tlvs_is_valid(const struct tlv_encmsg_tlvs *record, size_t *err_index) @@ -1026,4 +1131,4 @@ bool fromwire_mpp_timeout(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:6564b6a17750dfd460f88f9c484964a5fbfdfd77242c1b5c9986e4d69e00d387 +// SHA256STAMP:dc74e1b66f37a96bed7d2ab3f5b83fdf7cbe4ee7775ebda3ee43812e75f260ba diff --git a/wire/onion_wiregen.h b/wire/onion_wiregen.h index f6273a3b8..20c2d7d81 100644 --- a/wire/onion_wiregen.h +++ b/wire/onion_wiregen.h @@ -59,6 +59,11 @@ struct tlv_tlv_payload_payment_data { struct secret payment_secret; u64 total_msat; }; +struct tlv_onionmsg_payload_reply_path { + struct pubkey first_node_id; + struct pubkey blinding; + struct onionmsg_path **path; +}; struct tlv_onionmsg_payload_obs_reply_path { struct pubkey blinding; struct onionmsg_path **path; @@ -80,6 +85,7 @@ struct tlv_onionmsg_payload { /* TODO The following explicit fields could just point into the * tlv_field entries above to save on memory. */ + struct tlv_onionmsg_payload_reply_path *reply_path; struct pubkey *obs_next_node_id; struct short_channel_id *obs_next_short_channel_id; struct tlv_onionmsg_payload_obs_reply_path *obs_reply_path; @@ -95,8 +101,11 @@ struct tlv_encmsg_tlvs { /* TODO The following explicit fields could just point into the * tlv_field entries above to save on memory. */ + u8 *padding; struct pubkey *next_node_id; struct short_channel_id *obs_next_short_channel_id; + struct pubkey *next_blinding; + u8 *self_id; }; struct tlv_tlv_payload *tlv_tlv_payload_new(const tal_t *ctx); @@ -317,4 +326,4 @@ bool fromwire_mpp_timeout(const void *p); #endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */ -// SHA256STAMP:6564b6a17750dfd460f88f9c484964a5fbfdfd77242c1b5c9986e4d69e00d387 +// SHA256STAMP:dc74e1b66f37a96bed7d2ab3f5b83fdf7cbe4ee7775ebda3ee43812e75f260ba diff --git a/wire/peer_printgen.c b/wire/peer_printgen.c index 63f38bfb8..f7a3c3d31 100644 --- a/wire/peer_printgen.c +++ b/wire/peer_printgen.c @@ -176,6 +176,10 @@ void printpeer_wire_message(const u8 *msg) printf("WIRE_OBS_ONION_MESSAGE:\n"); printwire_obs_onion_message("obs_onion_message", msg); return; + case WIRE_ONION_MESSAGE: + printf("WIRE_ONION_MESSAGE:\n"); + printwire_onion_message("onion_message", msg); + return; } printf("UNKNOWN: %s\\n", tal_hex(msg, msg)); @@ -3090,6 +3094,41 @@ void printwire_obs_onion_message(const char *fieldname, const u8 *cursor) printwire_tlvs(tal_fmt(NULL, "%s.obs_onion_message_tlvs", fieldname), &cursor, &plen, print_tlvs_obs_onion_message_tlvs, ARRAY_SIZE(print_tlvs_obs_onion_message_tlvs)); + if (plen != 0) + printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); +} +void printwire_onion_message(const char *fieldname, const u8 *cursor) +{ + + size_t plen = tal_count(cursor); + if (fromwire_u16(&cursor, &plen) != WIRE_ONION_MESSAGE) { + printf("WRONG TYPE?!\n"); + return; + } + + printf("blinding="); + struct pubkey blinding; + fromwire_pubkey(&cursor, &plen, &blinding); + + printwire_pubkey(tal_fmt(NULL, "%s.blinding", fieldname), &blinding); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + u16 len = fromwire_u16(&cursor, &plen); + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + printf("onionmsg="); + printwire_u8_array(tal_fmt(NULL, "%s.onionmsg", fieldname), &cursor, &plen, len); + + if (!cursor) { + printf("**TRUNCATED**\n"); + return; + } + + if (plen != 0) printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen)); } @@ -3139,4 +3178,4 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_obs_onion_message_tlvs, ARRAY_SIZE(print_tlvs_obs_onion_message_tlvs)); } } -// SHA256STAMP:6d70cc661b9bfd206dc82540e4a53f9c2ef6301355710d1e444acdeaf29c53ef +// SHA256STAMP:6c0b9a8708efecb98f258c55fb8cc46909b5cf1ea1204cf18cc7b422f3496d41 diff --git a/wire/peer_printgen.h b/wire/peer_printgen.h index 570e7dd40..7e4c03fe6 100644 --- a/wire/peer_printgen.h +++ b/wire/peer_printgen.h @@ -92,6 +92,8 @@ void printwire_gossip_timestamp_filter(const char *fieldname, const u8 *cursor); void printwire_obs_onion_message(const char *fieldname, const u8 *cursor); +void printwire_onion_message(const char *fieldname, const u8 *cursor); + void printwire_witness_element(const char *fieldname, const u8 **cursor, size_t *plen); void printwire_lease_rates(const char *fieldname, const u8 **cursor, size_t *plen); @@ -99,4 +101,4 @@ void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen); void printwire_witness_stack(const char *fieldname, const u8 **cursor, size_t *plen); #endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */ -// SHA256STAMP:6d70cc661b9bfd206dc82540e4a53f9c2ef6301355710d1e444acdeaf29c53ef +// SHA256STAMP:6c0b9a8708efecb98f258c55fb8cc46909b5cf1ea1204cf18cc7b422f3496d41 diff --git a/wire/peer_wire.c b/wire/peer_wire.c index 0a8c16846..38c6f48eb 100644 --- a/wire/peer_wire.c +++ b/wire/peer_wire.c @@ -33,6 +33,7 @@ static bool unknown_type(enum peer_wire t) case WIRE_QUERY_CHANNEL_RANGE: case WIRE_REPLY_CHANNEL_RANGE: case WIRE_GOSSIP_TIMESTAMP_FILTER: + case WIRE_ONION_MESSAGE: case WIRE_OBS_ONION_MESSAGE: case WIRE_TX_ADD_INPUT: case WIRE_TX_REMOVE_INPUT: @@ -64,6 +65,7 @@ bool is_msg_for_gossipd(const u8 *cursor) case WIRE_REPLY_CHANNEL_RANGE: case WIRE_PING: case WIRE_PONG: + case WIRE_ONION_MESSAGE: case WIRE_OBS_ONION_MESSAGE: return true; case WIRE_WARNING: diff --git a/wire/peer_wire.csv b/wire/peer_wire.csv index 1d74c9477..85cf20b4d 100644 --- a/wire/peer_wire.csv +++ b/wire/peer_wire.csv @@ -334,3 +334,7 @@ msgdata,obs_onion_message,onionmsg,byte,len msgdata,obs_onion_message,obs_onion_message_tlvs,obs_onion_message_tlvs, tlvtype,obs_onion_message_tlvs,blinding,2 tlvdata,obs_onion_message_tlvs,blinding,blinding,point, +msgtype,onion_message,387,option_onion_messages +msgdata,onion_message,blinding,point, +msgdata,onion_message,len,u16, +msgdata,onion_message,onionmsg,byte,len diff --git a/wire/peer_wiregen.c b/wire/peer_wiregen.c index 43e3ff768..dc7f90a6c 100644 --- a/wire/peer_wiregen.c +++ b/wire/peer_wiregen.c @@ -61,6 +61,7 @@ const char *peer_wire_name(int e) case WIRE_REPLY_CHANNEL_RANGE: return "WIRE_REPLY_CHANNEL_RANGE"; case WIRE_GOSSIP_TIMESTAMP_FILTER: return "WIRE_GOSSIP_TIMESTAMP_FILTER"; case WIRE_OBS_ONION_MESSAGE: return "WIRE_OBS_ONION_MESSAGE"; + case WIRE_ONION_MESSAGE: return "WIRE_ONION_MESSAGE"; } snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e); @@ -111,6 +112,7 @@ bool peer_wire_is_defined(u16 type) case WIRE_REPLY_CHANNEL_RANGE:; case WIRE_GOSSIP_TIMESTAMP_FILTER:; case WIRE_OBS_ONION_MESSAGE:; + case WIRE_ONION_MESSAGE:; return true; } return false; @@ -2549,6 +2551,36 @@ bool fromwire_obs_onion_message(const tal_t *ctx, const void *p, u8 **onionmsg, return cursor != NULL; } +/* WIRE: ONION_MESSAGE */ +u8 *towire_onion_message(const tal_t *ctx, const struct pubkey *blinding, const u8 *onionmsg) +{ + u16 len = tal_count(onionmsg); + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_ONION_MESSAGE); + towire_pubkey(&p, blinding); + towire_u16(&p, len); + towire_u8_array(&p, onionmsg, len); + + return memcheck(p, tal_count(p)); +} +bool fromwire_onion_message(const tal_t *ctx, const void *p, struct pubkey *blinding, u8 **onionmsg) +{ + u16 len; + + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_ONION_MESSAGE) + return false; + fromwire_pubkey(&cursor, &plen, blinding); + len = fromwire_u16(&cursor, &plen); + // 2nd case onionmsg + *onionmsg = len ? tal_arr(ctx, u8, len) : NULL; + fromwire_u8_array(&cursor, &plen, *onionmsg, len); + return cursor != NULL; +} + /* WIRE: CHANNEL_UPDATE_OPTION_CHANNEL_HTLC_MAX */ u8 *towire_channel_update_option_channel_htlc_max(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths, struct amount_msat htlc_maximum_msat) { @@ -2589,4 +2621,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec *htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:6d70cc661b9bfd206dc82540e4a53f9c2ef6301355710d1e444acdeaf29c53ef +// SHA256STAMP:6c0b9a8708efecb98f258c55fb8cc46909b5cf1ea1204cf18cc7b422f3496d41 diff --git a/wire/peer_wiregen.h b/wire/peer_wiregen.h index 4861c3083..7245e55f7 100644 --- a/wire/peer_wiregen.h +++ b/wire/peer_wiregen.h @@ -58,6 +58,7 @@ enum peer_wire { WIRE_REPLY_CHANNEL_RANGE = 264, WIRE_GOSSIP_TIMESTAMP_FILTER = 265, WIRE_OBS_ONION_MESSAGE = 385, + WIRE_ONION_MESSAGE = 387, }; const char *peer_wire_name(int e); @@ -975,10 +976,14 @@ bool fromwire_gossip_timestamp_filter(const void *p, struct bitcoin_blkid *chain u8 *towire_obs_onion_message(const tal_t *ctx, const u8 *onionmsg, const struct tlv_obs_onion_message_tlvs *obs_onion_message_tlvs); bool fromwire_obs_onion_message(const tal_t *ctx, const void *p, u8 **onionmsg, struct tlv_obs_onion_message_tlvs *obs_onion_message_tlvs); +/* WIRE: ONION_MESSAGE */ +u8 *towire_onion_message(const tal_t *ctx, const struct pubkey *blinding, const u8 *onionmsg); +bool fromwire_onion_message(const tal_t *ctx, const void *p, struct pubkey *blinding, u8 **onionmsg); + /* WIRE: CHANNEL_UPDATE_OPTION_CHANNEL_HTLC_MAX */ u8 *towire_channel_update_option_channel_htlc_max(const tal_t *ctx, const secp256k1_ecdsa_signature *signature, const struct bitcoin_blkid *chain_hash, const struct short_channel_id *short_channel_id, u32 timestamp, u8 message_flags, u8 channel_flags, u16 cltv_expiry_delta, struct amount_msat htlc_minimum_msat, u32 fee_base_msat, u32 fee_proportional_millionths, struct amount_msat htlc_maximum_msat); bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ecdsa_signature *signature, struct bitcoin_blkid *chain_hash, struct short_channel_id *short_channel_id, u32 *timestamp, u8 *message_flags, u8 *channel_flags, u16 *cltv_expiry_delta, struct amount_msat *htlc_minimum_msat, u32 *fee_base_msat, u32 *fee_proportional_millionths, struct amount_msat *htlc_maximum_msat); #endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */ -// SHA256STAMP:6d70cc661b9bfd206dc82540e4a53f9c2ef6301355710d1e444acdeaf29c53ef +// SHA256STAMP:6c0b9a8708efecb98f258c55fb8cc46909b5cf1ea1204cf18cc7b422f3496d41