core-lightning/lightningd/notification.c
Christian Decker 71934f983a notifications: Fix iteration over notification topics
Turns out that checking boundaries is important...

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-17 05:42:49 +00:00

36 lines
990 B
C

#include "lightningd/notification.h"
#include <ccan/array_size/array_size.h>
const char *notification_topics[] = {
"connect",
"disconnect",
};
bool notifications_have_topic(const char *topic)
{
for (size_t i=0; i<ARRAY_SIZE(notification_topics); i++)
if (streq(topic, notification_topics[i]))
return true;
return false;
}
void notify_connect(struct lightningd *ld, struct pubkey *nodeid,
struct wireaddr_internal *addr)
{
struct jsonrpc_notification *n =
jsonrpc_notification_start(NULL, notification_topics[0]);
json_add_pubkey(n->stream, "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 pubkey *nodeid)
{
struct jsonrpc_notification *n =
jsonrpc_notification_start(NULL, notification_topics[1]);
json_add_pubkey(n->stream, "id", nodeid);
jsonrpc_notification_end(n);
plugins_notify(ld->plugins, take(n));
}