Browse Source
plugin: Add connect and disconnect notifications
Signed-off-by: Christian Decker <decker.christian@gmail.com>
plugin-7
Christian Decker
6 years ago
No known key found for this signature in database
GPG Key ID: 1416D83DC4F0E86D
6 changed files with
47 additions and
0 deletions
-
lightningd/notification.c
-
lightningd/notification.h
-
lightningd/opening_control.c
-
lightningd/peer_control.c
-
lightningd/test/run-invoice-select-inchan.c
-
wallet/test/run-wallet.c
|
|
@ -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(); } |
|
|
|