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

Function process_batch_elements

connectd/multiplex.c:376–431  ·  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

374/* Process and eat protocol_batch_element messages, encrypt each element message
375 * and return the encrypted messages as one long byte array. */
376static 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,

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