| 140 | } |
| 141 | |
| 142 | struct command_result * |
| 143 | inject_onionmessage_(struct command *cmd, |
| 144 | const struct onion_message *omsg, |
| 145 | struct command_result *(*cb)(struct command *command, |
| 146 | const char *method, |
| 147 | const char *buf, |
| 148 | const jsmntok_t *result, |
| 149 | void *arg), |
| 150 | struct command_result *(*errcb)(struct command *command, |
| 151 | const char *method, |
| 152 | const char *buf, |
| 153 | const jsmntok_t *result, |
| 154 | void *arg), |
| 155 | void *arg) |
| 156 | { |
| 157 | struct out_req *req; |
| 158 | struct sphinx_path *sphinx_path; |
| 159 | struct onionpacket *op; |
| 160 | struct secret *path_secrets; |
| 161 | size_t onion_size; |
| 162 | |
| 163 | /* Create an onion which encodes this. */ |
| 164 | sphinx_path = sphinx_path_new(tmpctx, NULL, 0); |
| 165 | for (size_t i = 0; i < tal_count(omsg->hops); i++) |
| 166 | sphinx_add_hop(sphinx_path, |
| 167 | &omsg->hops[i]->pubkey, omsg->hops[i]->raw_payload); |
| 168 | |
| 169 | /* BOLT #4: |
| 170 | * - SHOULD set `onion_message_packet` `len` to 1366 or 32834. |
| 171 | */ |
| 172 | if (sphinx_path_payloads_size(sphinx_path) <= ROUTING_INFO_SIZE) |
| 173 | onion_size = ROUTING_INFO_SIZE; |
| 174 | else |
| 175 | onion_size = 32768; /* VERSION_SIZE + HMAC_SIZE + PUBKEY_SIZE == 66 */ |
| 176 | |
| 177 | op = create_onionpacket(tmpctx, sphinx_path, onion_size, &path_secrets); |
| 178 | if (!op) { |
| 179 | /* errcb expects a JSON message. */ |
| 180 | const char *err; |
| 181 | jsmntok_t *toks; |
| 182 | |
| 183 | err = tal_fmt(tmpctx, "{\"code\":%d,\"message\":\"Creating onion failed (tlvs too long?)\"}", |
| 184 | JSONRPC2_INVALID_PARAMS); |
| 185 | toks = json_parse_simple(tmpctx, err, strlen(err)); |
| 186 | assert(toks); |
| 187 | /* Not really an error from injectpaymentonion, but near enough */ |
| 188 | return errcb(cmd, "injectpaymentonion", err, toks, arg); |
| 189 | } |
| 190 | |
| 191 | req = jsonrpc_request_start(cmd, "injectonionmessage", cb, errcb, arg); |
| 192 | json_add_pubkey(req->js, "path_key", &omsg->first_path_key); |
| 193 | json_add_hex_talarr(req->js, "message", serialize_onionpacket(tmpctx, op)); |
| 194 | return send_outreq(req); |
| 195 | } |
| 196 | |
| 197 | /* Holds the details while we wait for establish_onion_path to connect */ |
| 198 | struct onion_reply { |
nothing calls this directly
no test coverage detected