#include "lightningd/notification.h" #include #include const char *notification_topics[] = { "connect", "disconnect", "warning" }; bool notifications_have_topic(const char *topic) { for (size_t i=0; istream, "id", nodeid); json_add_address_internal(n->stream, "address", addr); jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); } void notify_disconnect(struct lightningd *ld, struct node_id *nodeid) { struct jsonrpc_notification *n = jsonrpc_notification_start(NULL, notification_topics[1]); json_add_node_id(n->stream, "id", nodeid); jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); } /*'warning' is based on LOG_UNUSUAL/LOG_BROKEN level log *(in plugin module, they're 'warn'/'error' level). */ void notify_warning(struct lightningd *ld, struct log_entry *l) { struct jsonrpc_notification *n = jsonrpc_notification_start(NULL, notification_topics[2]); json_object_start(n->stream, "warning"); /* Choose "BROKEN"/"UNUSUAL" to keep consistent with the habit * of plugin. But this may confuses the users who want to 'getlog' * with the level indicated by notifications. It is the duty of a * plugin to eliminate this misunderstanding. */ json_add_string(n->stream, "level", l->level == LOG_BROKEN ? "error" : "warn"); /* unsuaul/broken event is rare, plugin pay more attentions on * the absolute time, like when channels failed. */ json_add_time(n->stream, "time", l->time.ts); json_add_string(n->stream, "source", l->prefix); json_add_string(n->stream, "log", l->log); json_object_end(n->stream); /* .warning */ jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); }