diff --git a/doc/lightning-createonion.7 b/doc/lightning-createonion.7 index 90e3ebf4ffc4..41a0a9dce284 100644 --- a/doc/lightning-createonion.7 +++ b/doc/lightning-createonion.7 @@ -3,7 +3,7 @@ lightning-createonion - Low-level command to create a custom onion .SH SYNOPSIS -\fBcreateonion\fR \fIhops\fR \fIassocdata\fR [\fIsession_key\fR] +\fBcreateonion\fR \fIhops\fR \fIassocdata\fR [\fIsession_key\fR] [\fIonion_size\fR] .SH DESCRIPTION @@ -75,8 +75,8 @@ which the above \fIhops\fR parameter was generated: Notice that the payload in the \fIhops\fR parameter is the hex-encoded version of the parameters in the \fBgetroute\fR response\. .IP \[bu] -The payloads are shifted left by one, i\.e\., payload 0 in \fBcreateonion\fR -corresponds to payload 1 from \fBgetroute\fR\. +Except for the pubkey, the values are shifted left by one, i\.e\., the 1st +payload in \fBcreateonion\fR corresponds to the 2nd set of values from \fBgetroute\fR\. .IP \[bu] The final payload is a copy of the last payload sans \fBchannel\fR @@ -97,6 +97,11 @@ should only be used for testing or if a specific shared secret is important\. If not specified it will be securely generated internally, and the shared secrets will be returned\. + +The optional \fIonion_size\fR parameter specifies a size different from the default +payment onion (1300 bytes)\. May be used for custom protocols like trampoline +routing\. + .SH RETURN VALUE On success, an object containing the onion and the shared secrets will be @@ -132,4 +137,4 @@ Christian Decker \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:287d404b94d0e85eedbc6138b8e7a204723df86ad6d5f984ccfcd03e718ec514 +\" SHA256STAMP:d32334049025248f8b6088afed4e3322be75815ea6b976f79a007c619518f98a diff --git a/doc/lightning-createonion.7.md b/doc/lightning-createonion.7.md index 0c0128349378..630f327aa574 100644 --- a/doc/lightning-createonion.7.md +++ b/doc/lightning-createonion.7.md @@ -4,7 +4,7 @@ lightning-createonion -- Low-level command to create a custom onion SYNOPSIS -------- -**createonion** *hops* *assocdata* \[*session_key*\] +**createonion** *hops* *assocdata* \[*session_key*\] \[*onion_size*\] DESCRIPTION ----------- @@ -68,10 +68,10 @@ which the above *hops* parameter was generated: - Notice that the payload in the *hops* parameter is the hex-encoded version of the parameters in the `getroute` response. - - The payloads are shifted left by one, i.e., payload 0 in `createonion` - corresponds to payload 1 from `getroute`. + - Except for the pubkey, the values are shifted left by one, i.e., the 1st + payload in `createonion` corresponds to the 2nd set of values from `getroute`. - The final payload is a copy of the last payload sans `channel` - + These rules are directly derived from the onion construction. Please refer [BOLT 04][bolt04] for details and rationale. @@ -85,6 +85,10 @@ should only be used for testing or if a specific shared secret is important. If not specified it will be securely generated internally, and the shared secrets will be returned. +The optional *onion_size* parameter specifies a size different from the default +payment onion (1300 bytes). May be used for custom protocols like trampoline +routing. + RETURN VALUE ------------ @@ -122,4 +126,3 @@ RESOURCES Main web site: [bolt04]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md - diff --git a/lightningd/pay.c b/lightningd/pay.c index 6b73c07c53e4..a15a3c90490a 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1670,6 +1670,7 @@ static struct command_result *json_createonion(struct command *cmd, struct secret *session_key, *shared_secrets; struct sphinx_path *sp; u8 *assocdata, *serialized; + u32 *packet_size; struct onionpacket *packet; struct sphinx_hop *hops; @@ -1677,6 +1678,7 @@ static struct command_result *json_createonion(struct command *cmd, p_req("hops", param_hops_array, &hops), p_req("assocdata", param_bin_from_hex, &assocdata), p_opt("session_key", param_secret, &session_key), + p_opt_def("onion_size", param_number, &packet_size, ROUTING_INFO_SIZE), NULL)) { return command_param_failed(); } @@ -1689,12 +1691,12 @@ static struct command_result *json_createonion(struct command *cmd, for (size_t i=0; i ROUTING_INFO_SIZE) + if (sphinx_path_payloads_size(sp) > *packet_size) return command_fail( cmd, JSONRPC2_INVALID_PARAMS, "Payloads exceed maximum onion packet size."); - packet = create_onionpacket(cmd, sp, ROUTING_INFO_SIZE, &shared_secrets); + packet = create_onionpacket(cmd, sp, *packet_size, &shared_secrets); if (!packet) return command_fail(cmd, LIGHTNINGD, "Could not create onion packet");