2018-12-12 14:36:11 +01:00
|
|
|
#include "lightningd/notification.h"
|
|
|
|
#include <ccan/array_size/array_size.h>
|
|
|
|
|
|
|
|
const char *notification_topics[] = {
|
2018-12-13 13:58:40 +01:00
|
|
|
"connect",
|
|
|
|
"disconnect",
|
2018-12-12 14:36:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool notifications_have_topic(const char *topic)
|
|
|
|
{
|
2019-01-03 17:38:35 +01:00
|
|
|
for (size_t i=0; i<ARRAY_SIZE(notification_topics); i++)
|
2018-12-12 14:36:11 +01:00
|
|
|
if (streq(topic, notification_topics[i]))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-13 13:58:40 +01:00
|
|
|
|
2019-04-08 11:58:32 +02:00
|
|
|
void notify_connect(struct lightningd *ld, struct node_id *nodeid,
|
2018-12-13 13:58:40 +01:00
|
|
|
struct wireaddr_internal *addr)
|
|
|
|
{
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, notification_topics[0]);
|
2019-04-08 11:58:32 +02:00
|
|
|
json_add_node_id(n->stream, "id", nodeid);
|
2018-12-13 13:58:40 +01:00
|
|
|
json_add_address_internal(n->stream, "address", addr);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
|
|
|
|
2019-04-08 11:58:32 +02:00
|
|
|
void notify_disconnect(struct lightningd *ld, struct node_id *nodeid)
|
2018-12-13 13:58:40 +01:00
|
|
|
{
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, notification_topics[1]);
|
2019-04-08 11:58:32 +02:00
|
|
|
json_add_node_id(n->stream, "id", nodeid);
|
2018-12-13 13:58:40 +01:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|