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

Function write_to_peer

connectd/multiplex.c:942–986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

940}
941
942static struct io_plan *write_to_peer(struct io_conn *peer_conn,
943 struct peer *peer)
944{
945 const u8 *msg;
946 assert(peer->to_peer == peer_conn);
947
948 /* Free last sent one (if any) */
949 peer->sent_to_peer = tal_free(peer->sent_to_peer);
950
951 /* Pop tail of send queue */
952 msg = msg_dequeue(peer->peer_outq);
953
954 /* Still nothing to send? */
955 if (!msg) {
956 /* Draining? We're done when subds are done. */
957 if (peer->draining && tal_count(peer->subds) == 0)
958 return io_sock_shutdown(peer_conn);
959
960 /* If they want us to send gossip, do so now. */
961 if (!peer->draining)
962 msg = maybe_from_gossip_store(NULL, peer);
963 if (!msg) {
964 /* Tell them to read again, */
965 io_wake(&peer->subds);
966
967 /* Wait for them to wake us */
968 return msg_queue_wait(peer_conn, peer->peer_outq,
969 write_to_peer, peer);
970 }
971 }
972
973 /* dev_disconnect can disable writes */
974#if DEVELOPER
975 if (peer->dev_writes_enabled) {
976 if (*peer->dev_writes_enabled == 0) {
977 tal_free(msg);
978 /* Continue, to drain queue */
979 return write_to_peer(peer_conn, peer);
980 }
981 (*peer->dev_writes_enabled)--;
982 }
983#endif
984
985 return encrypt_and_send(peer, take(msg), write_to_peer);
986}
987
988static struct io_plan *read_from_subd(struct io_conn *subd_conn,
989 struct subd *subd);

Callers 1

multiplex_peer_setupFunction · 0.85

Calls 6

tal_freeFunction · 0.85
msg_dequeueFunction · 0.85
io_sock_shutdownFunction · 0.85
maybe_from_gossip_storeFunction · 0.85
io_wakeFunction · 0.85
encrypt_and_sendFunction · 0.85

Tested by

no test coverage detected