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

Function req_reply

hsmd/hsmd.c:253–278  ·  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

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