MCPcopy Create free account
hub / github.com/ElementsProject/lightning / process_batch_elements

Function process_batch_elements

connectd/multiplex.c:379–434  ·  view source on GitHub ↗

Process and eat protocol_batch_element messages, encrypt each element message * and return the encrypted messages as one long byte array. */

Source from the content-addressed store, hash-verified

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

Callers 1

encrypt_appendFunction · 0.85

Calls 9

tal_hexFunction · 0.85
tal_hexstrFunction · 0.85
tal_freeFunction · 0.85
fromwire_peektypeFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
tal_free_if_takenFunction · 0.85
fromwire_u16Function · 0.50
fromwire_channel_idFunction · 0.50
fromwire_tal_arrnFunction · 0.50

Tested by

no test coverage detected