Process and eat protocol_batch_element messages, encrypt each element message * and return the encrypted messages as one long byte array. */
| 374 | /* Process and eat protocol_batch_element messages, encrypt each element message |
| 375 | * and return the encrypted messages as one long byte array. */ |
| 376 | static u8 *process_batch_elements(const tal_t *ctx, struct peer *peer, const u8 *msg TAKES) |
| 377 | { |
| 378 | u8 *ret = tal_arr(ctx, u8, 0); |
| 379 | const u8 *cursor = msg; |
| 380 | size_t plen = tal_count(msg); |
| 381 | |
| 382 | status_debug("Processing batch elements of %zu bytes. %s", plen, |
| 383 | tal_hex(tmpctx, msg)); |
| 384 | |
| 385 | do { |
| 386 | u8 *element_bytes; |
| 387 | u16 element_size; |
| 388 | struct channel_id channel_id; |
| 389 | u8 *enc_msg; |
| 390 | |
| 391 | if (fromwire_u16(&cursor, &plen) != WIRE_PROTOCOL_BATCH_ELEMENT) { |
| 392 | status_broken("process_batch_elements on msg that is" |
| 393 | " not WIRE_PROTOCOL_BATCH_ELEMENT. %s", |
| 394 | tal_hexstr(tmpctx, cursor, plen)); |
| 395 | return tal_free(ret); |
| 396 | } |
| 397 | |
| 398 | fromwire_channel_id(&cursor, &plen, &channel_id); |
| 399 | |
| 400 | element_size = fromwire_u16(&cursor, &plen); |
| 401 | if (!element_size) { |
| 402 | status_broken("process_batch_elements cannot have zero" |
| 403 | " length elements. %s", |
| 404 | tal_hexstr(tmpctx, cursor, plen)); |
| 405 | return tal_free(ret); |
| 406 | } |
| 407 | |
| 408 | element_bytes = fromwire_tal_arrn(NULL, &cursor, &plen, |
| 409 | element_size); |
| 410 | if (!element_bytes) { |
| 411 | status_broken("process_batch_elements fromwire_tal_arrn" |
| 412 | " %s", |
| 413 | tal_hexstr(tmpctx, cursor, plen)); |
| 414 | return tal_free(ret); |
| 415 | } |
| 416 | |
| 417 | status_debug("Processing batch extracted item %s. %s", |
| 418 | peer_wire_name(fromwire_peektype(element_bytes)), |
| 419 | tal_hex(tmpctx, element_bytes)); |
| 420 | |
| 421 | enc_msg = cryptomsg_encrypt_msg(tmpctx, &peer->cs, |
| 422 | take(element_bytes)); |
| 423 | |
| 424 | tal_arr_append(&ret, enc_msg); |
| 425 | |
| 426 | } while(plen); |
| 427 | |
| 428 | tal_free_if_taken(msg); |
| 429 | |
| 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | /* --dev-disconnect can do magic things: if this returns non-NULL, |
no test coverage detected