Skip to content

Commit

Permalink
fixup! json: Only start parsing once we're sure we have a message
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyrussell committed Sep 1, 2020
1 parent 9751c86 commit c58a4e9
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,22 +492,17 @@ static struct io_plan *plugin_read_json(struct io_conn *conn,
{
bool success;
bool have_full;
int offset = plugin->used >= 1 ? 1 : 0;

log_io(plugin->log, LOG_IO_IN, NULL, "",
plugin->buffer + plugin->used, plugin->len_read);

/* Peek into the buffer increment we just read (including a tiny
* overlap if we're not at the start) to see if we have a '}'
* separator. If not we can skip the JSON attempt.
*
* Our JSON parser is pretty good at incremental parsing, but
/* Our JSON parser is pretty good at incremental parsing, but
* `getrawblock` gives a giant 2MB token, which forces it to re-parse
* every time until we have all of it. However, we can't complete a
* JSON object without a '}', so we do a cheaper check here.
*/
have_full = memmem(plugin->buffer + plugin->used - offset,
plugin->len_read + offset, "}", 1);
*/
have_full = memchr(plugin->buffer + plugin->used, '}',
plugin->len_read);

plugin->used += plugin->len_read;
if (plugin->used == tal_count(plugin->buffer))
Expand Down

0 comments on commit c58a4e9

Please sign in to comment.