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

Function encrypt_and_send

connectd/multiplex.c:411–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409}
410
411static struct io_plan *encrypt_and_send(struct peer *peer,
412 const u8 *msg TAKES,
413 struct io_plan *(*next)
414 (struct io_conn *peer_conn,
415 struct peer *peer))
416{
417 int type = fromwire_peektype(msg);
418
419#if DEVELOPER
420 switch (dev_disconnect(&peer->id, type)) {
421 case DEV_DISCONNECT_BEFORE:
422 if (taken(msg))
423 tal_free(msg);
424 return io_close(peer->to_peer);
425 case DEV_DISCONNECT_AFTER:
426 /* Disallow reads from now on */
427 peer->dev_read_enabled = false;
428 next = (void *)io_close_cb;
429 break;
430 case DEV_DISCONNECT_BLACKHOLE:
431 /* Disable both reads and writes from now on */
432 peer->dev_read_enabled = false;
433 peer->dev_writes_enabled = talz(peer, u32);
434 break;
435 case DEV_DISCONNECT_NORMAL:
436 break;
437 case DEV_DISCONNECT_DISABLE_AFTER:
438 peer->dev_read_enabled = false;
439 peer->dev_writes_enabled = tal(peer, u32);
440 *peer->dev_writes_enabled = 1;
441 break;
442 }
443#endif
444 set_urgent_flag(peer, is_urgent(type));
445
446 /* BOLT #1:
447 *
448 * A sending node:
449 *...
450 * - MAY close the connection after sending.
451 */
452 if (type == WIRE_ERROR || type == WIRE_WARNING) {
453 /* Might already be draining... */
454 if (!peer->draining)
455 drain_peer(peer);
456
457 /* Close as soon as we've sent this. */
458 next = io_sock_shutdown_cb;
459 }
460
461 /* We free this and the encrypted version in next write_to_peer */
462 peer->sent_to_peer = cryptomsg_encrypt_msg(peer, &peer->cs, msg);
463 return io_write(peer->to_peer,
464 peer->sent_to_peer,
465 tal_bytelen(peer->sent_to_peer),
466 next, peer);
467}
468

Callers 1

write_to_peerFunction · 0.85

Calls 10

takenFunction · 0.85
tal_freeFunction · 0.85
io_closeFunction · 0.85
set_urgent_flagFunction · 0.85
is_urgentFunction · 0.85
drain_peerFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
tal_bytelenFunction · 0.85
fromwire_peektypeFunction · 0.50
dev_disconnectFunction · 0.50

Tested by

no test coverage detected