jsonrpc: only allow a single command at a time.

There's a DoS if we keep reading commands and don't insist the client
read the responses.

My initial implementation simply removed the io_duplex, but that
doesn't work if we want to inject notifications in the stream (as we
will eventually want to do), so we operate it as duplex but have each
side wake the other when it's done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-10-19 11:47:48 +10:30
parent 8238fe6acf
commit ce0bd7abd3
2 changed files with 55 additions and 76 deletions

View File

@@ -22,8 +22,6 @@ enum command_mode {
/* Context for a command (from JSON, but might outlive the connection!)
* You can allocate off this for temporary objects. */
struct command {
/* Off jcon->commands */
struct list_node list;
/* The global state */
struct lightningd *ld;
/* The 'id' which we need to include in the response. */
@@ -60,10 +58,10 @@ struct json_connection {
/* We've been told to stop. */
bool stop;
/* Current commands. */
struct list_head commands;
/* Current command. */
struct command *command;
struct list_head output;
/* Current command's output. */
const char *outbuf;
struct io_lock *lock;
};