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

Function req_reply

hsmd/hsmd.c:264–289  ·  view source on GitHub ↗

This is the common pattern for the tail of each handler in this file. */

Source from the content-addressed store, hash-verified

262
263/* This is the common pattern for the tail of each handler in this file. */
264static struct io_plan *req_reply(struct io_conn *conn,
265 struct client *c,
266 const u8 *msg_out TAKES)
267{
268 /*~ Write this out, then read the next one. This works perfectly for
269 * a simple request/response system like this.
270 *
271 * Internally, the ccan/io subsystem gathers all the file descriptors,
272 * figures out which want to write and read, asks the OS which ones
273 * are available, and for those file descriptors, tries to do the
274 * reads/writes we've asked it. It handles retry in the case where a
275 * read or write is done partially.
276 *
277 * Since the OS does buffering internally (on my system, over 100k
278 * worth) writes will normally succeed immediately. However, if the
279 * client is slow or malicious, and doesn't read from the socket as
280 * fast as we're writing, eventually the socket buffer will fill up;
281 * we don't care, because ccan/io will wait until there's room to
282 * write this reply before it will read again. The client just hurts
283 * themselves, and there's no Denial of Service on us.
284 *
285 * If we were to queue outgoing messages ourselves, we *would* have to
286 * consider such scenarios; this is why our daemons generally avoid
287 * buffering from untrusted parties. */
288 return io_write_wire(conn, msg_out, client_read_next, c);
289}
290
291/* Send an init reply failure message to lightningd and then call status_failed */
292static void hsmd_send_init_reply_failure(enum hsm_secret_error error_code, enum status_failreason reason, const char *error_msg, ...)

Callers 4

init_hsmFunction · 0.85
handle_memleakFunction · 0.85
handle_clientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected