mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
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>
This commit is contained in:
committed by
Christian Decker
parent
48df6c8566
commit
8f9c48254b
@@ -65,7 +65,9 @@ struct json_stream *new_json_stream(const tal_t *ctx,
|
|||||||
return js;
|
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);
|
size_t num_elems = membuf_num_elems(&original->outbuf);
|
||||||
char *elems = membuf_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);
|
membuf_added(&js->outbuf, num_elems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
js->log = log;
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ struct json_stream *new_json_stream(const tal_t *ctx, struct command *writer,
|
|||||||
*
|
*
|
||||||
* @ctx: tal context for allocation.
|
* @ctx: tal context for allocation.
|
||||||
* @original: the stream to duplicate.
|
* @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.
|
* json_stream_close - finished writing to a JSON stream.
|
||||||
|
|||||||
@@ -374,6 +374,10 @@ static struct io_plan *plugin_read_json(struct io_conn *conn UNUSED,
|
|||||||
struct plugin *plugin)
|
struct plugin *plugin)
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
|
log_io(plugin->log, LOG_IO_IN, "",
|
||||||
|
plugin->buffer + plugin->used, plugin->len_read);
|
||||||
|
|
||||||
plugin->used += plugin->len_read;
|
plugin->used += plugin->len_read;
|
||||||
if (plugin->used == tal_count(plugin->buffer))
|
if (plugin->used == tal_count(plugin->buffer))
|
||||||
tal_resize(&plugin->buffer, plugin->used * 2);
|
tal_resize(&plugin->buffer, plugin->used * 2);
|
||||||
@@ -1051,7 +1055,7 @@ void plugins_notify(struct plugins *plugins,
|
|||||||
struct plugin *p;
|
struct plugin *p;
|
||||||
list_for_each(&plugins->plugins, p, list) {
|
list_for_each(&plugins->plugins, p, list) {
|
||||||
if (plugin_subscriptions_contains(p, n->method))
|
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))
|
if (taken(n))
|
||||||
tal_free(n);
|
tal_free(n);
|
||||||
@@ -1086,3 +1090,8 @@ void *plugin_exclusive_loop(struct plugin *plugin)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct log *plugin_get_log(struct plugin *plugin)
|
||||||
|
{
|
||||||
|
return plugin->log;
|
||||||
|
}
|
||||||
|
|||||||
@@ -119,4 +119,10 @@ void plugin_request_send(struct plugin *plugin,
|
|||||||
*/
|
*/
|
||||||
char *plugin_opt_set(const char *arg, struct plugin_opt *popt);
|
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 */
|
#endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */
|
||||||
|
|||||||
@@ -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
|
* currently have a list to store these. We might want
|
||||||
* to eventually to inspect in-flight requests. */
|
* to eventually to inspect in-flight requests. */
|
||||||
ph_req = notleak(tal(hook->plugin, struct plugin_hook_request));
|
ph_req = notleak(tal(hook->plugin, struct plugin_hook_request));
|
||||||
/* FIXME: do IO logging for these! */
|
req = jsonrpc_request_start(NULL, hook->name,
|
||||||
req = jsonrpc_request_start(NULL, hook->name, NULL,
|
plugin_get_log(hook->plugin),
|
||||||
plugin_hook_callback, ph_req);
|
plugin_hook_callback, ph_req);
|
||||||
ph_req->hook = hook;
|
ph_req->hook = hook;
|
||||||
ph_req->cb_arg = cb_arg;
|
ph_req->cb_arg = cb_arg;
|
||||||
|
|||||||
Reference in New Issue
Block a user