mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
plugin: Add connect and disconnect notifications
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
5813567856
commit
26f17e87a3
6 changed files with 47 additions and 0 deletions
|
@ -2,6 +2,8 @@
|
|||
#include <ccan/array_size/array_size.h>
|
||||
|
||||
const char *notification_topics[] = {
|
||||
"connect",
|
||||
"disconnect",
|
||||
};
|
||||
|
||||
bool notifications_have_topic(const char *topic)
|
||||
|
@ -11,3 +13,23 @@ bool notifications_have_topic(const char *topic)
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@
|
|||
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
|
||||
#include "config.h"
|
||||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/plugin.h>
|
||||
|
||||
bool notifications_have_topic(const char *topic);
|
||||
|
||||
void notify_connect(struct lightningd *ld, struct pubkey *nodeid,
|
||||
struct wireaddr_internal *addr);
|
||||
void notify_disconnect(struct lightningd *ld, struct pubkey *nodeid);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/log.h>
|
||||
#include <lightningd/notification.h>
|
||||
#include <lightningd/opening_control.h>
|
||||
#include <lightningd/peer_control.h>
|
||||
#include <lightningd/subd.h>
|
||||
|
@ -85,6 +86,7 @@ static void uncommitted_channel_disconnect(struct uncommitted_channel *uc,
|
|||
subd_send_msg(uc->peer->ld->connectd, msg);
|
||||
if (uc->fc)
|
||||
was_pending(command_fail(uc->fc->cmd, LIGHTNINGD, "%s", desc));
|
||||
notify_disconnect(uc->peer->ld, &uc->peer->id);
|
||||
}
|
||||
|
||||
void kill_uncommitted_channel(struct uncommitted_channel *uc,
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/log.h>
|
||||
#include <lightningd/memdump.h>
|
||||
#include <lightningd/notification.h>
|
||||
#include <lightningd/onchain_control.h>
|
||||
#include <lightningd/opening_control.h>
|
||||
#include <lightningd/options.h>
|
||||
|
@ -381,6 +382,7 @@ void channel_errmsg(struct channel *channel,
|
|||
|
||||
/* Make sure channel_fail_permanent doesn't tell connectd we died! */
|
||||
channel->connected = false;
|
||||
notify_disconnect(channel->peer->ld, &channel->peer->id);
|
||||
|
||||
/* BOLT #1:
|
||||
*
|
||||
|
@ -504,6 +506,8 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
|
|||
abort();
|
||||
}
|
||||
|
||||
notify_connect(ld, &id, &addr);
|
||||
|
||||
/* No err, all good. */
|
||||
error = NULL;
|
||||
|
||||
|
|
|
@ -240,6 +240,13 @@ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
|
|||
struct timerel expire UNNEEDED,
|
||||
void (*cb)(void *) UNNEEDED, void *arg UNNEEDED)
|
||||
{ fprintf(stderr, "new_reltimer_ called!\n"); abort(); }
|
||||
/* Generated stub for notify_connect */
|
||||
void notify_connect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED,
|
||||
struct wireaddr_internal *addr UNNEEDED)
|
||||
{ fprintf(stderr, "notify_connect called!\n"); abort(); }
|
||||
/* Generated stub for notify_disconnect */
|
||||
void notify_disconnect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED)
|
||||
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for null_response */
|
||||
struct json_stream *null_response(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "null_response called!\n"); abort(); }
|
||||
|
|
|
@ -292,6 +292,13 @@ void log_add(struct log *log UNNEEDED, const char *fmt UNNEEDED, ...)
|
|||
void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED, const char *comment UNNEEDED,
|
||||
const void *data UNNEEDED, size_t len UNNEEDED)
|
||||
{ fprintf(stderr, "log_io called!\n"); abort(); }
|
||||
/* Generated stub for notify_connect */
|
||||
void notify_connect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED,
|
||||
struct wireaddr_internal *addr UNNEEDED)
|
||||
{ fprintf(stderr, "notify_connect called!\n"); abort(); }
|
||||
/* Generated stub for notify_disconnect */
|
||||
void notify_disconnect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED)
|
||||
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for null_response */
|
||||
struct json_stream *null_response(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "null_response called!\n"); abort(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue