Browse Source

plugins: do I/O logging.

I was trying to trace a problem with a plugin, and needed this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
htlc_accepted_hook
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
8f9c48254b
  1. 5
      lightningd/json_stream.c
  2. 5
      lightningd/json_stream.h
  3. 11
      lightningd/plugin.c
  4. 6
      lightningd/plugin.h
  5. 4
      lightningd/plugin_hook.c

5
lightningd/json_stream.c

@ -65,7 +65,9 @@ struct json_stream *new_json_stream(const tal_t *ctx,
return js;
}
struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *original)
struct json_stream *json_stream_dup(const tal_t *ctx,
struct json_stream *original,
struct log *log)
{
size_t num_elems = membuf_num_elems(&original->outbuf);
char *elems = membuf_elems(&original->outbuf);
@ -83,6 +85,7 @@ struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *origin
membuf_added(&js->outbuf, num_elems);
}
}
js->log = log;
return js;
}

5
lightningd/json_stream.h

@ -36,8 +36,11 @@ struct json_stream *new_json_stream(const tal_t *ctx, struct command *writer,
*
* @ctx: tal context for allocation.
* @original: the stream to duplicate.
* @log: log for new stream.
*/
struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *original);
struct json_stream *json_stream_dup(const tal_t *ctx,
struct json_stream *original,
struct log *log);
/**
* json_stream_close - finished writing to a JSON stream.

11
lightningd/plugin.c

@ -374,6 +374,10 @@ static struct io_plan *plugin_read_json(struct io_conn *conn UNUSED,
struct plugin *plugin)
{
bool success;
log_io(plugin->log, LOG_IO_IN, "",
plugin->buffer + plugin->used, plugin->len_read);
plugin->used += plugin->len_read;
if (plugin->used == tal_count(plugin->buffer))
tal_resize(&plugin->buffer, plugin->used * 2);
@ -1051,7 +1055,7 @@ void plugins_notify(struct plugins *plugins,
struct plugin *p;
list_for_each(&plugins->plugins, p, list) {
if (plugin_subscriptions_contains(p, n->method))
plugin_send(p, json_stream_dup(p, n->stream));
plugin_send(p, json_stream_dup(p, n->stream, p->log));
}
if (taken(n))
tal_free(n);
@ -1086,3 +1090,8 @@ void *plugin_exclusive_loop(struct plugin *plugin)
return ret;
}
struct log *plugin_get_log(struct plugin *plugin)
{
return plugin->log;
}

6
lightningd/plugin.h

@ -119,4 +119,10 @@ void plugin_request_send(struct plugin *plugin,
*/
char *plugin_opt_set(const char *arg, struct plugin_opt *popt);
/**
* Needed for I/O logging for plugin messages.
*/
struct log *plugin_get_log(struct plugin *plugin);
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */

4
lightningd/plugin_hook.c

@ -74,8 +74,8 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
* currently have a list to store these. We might want
* to eventually to inspect in-flight requests. */
ph_req = notleak(tal(hook->plugin, struct plugin_hook_request));
/* FIXME: do IO logging for these! */
req = jsonrpc_request_start(NULL, hook->name, NULL,
req = jsonrpc_request_start(NULL, hook->name,
plugin_get_log(hook->plugin),
plugin_hook_callback, ph_req);
ph_req->hook = hook;
ph_req->cb_arg = cb_arg;

Loading…
Cancel
Save