Browse Source

plugin: Add connect and disconnect notifications

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pr-2218
Christian Decker 6 years ago
parent
commit
26f17e87a3
  1. 22
      lightningd/notification.c
  2. 5
      lightningd/notification.h
  3. 2
      lightningd/opening_control.c
  4. 4
      lightningd/peer_control.c
  5. 7
      lightningd/test/run-invoice-select-inchan.c
  6. 7
      wallet/test/run-wallet.c

22
lightningd/notification.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));
}

5
lightningd/notification.h

@ -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 */

2
lightningd/opening_control.c

@ -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,

4
lightningd/peer_control.c

@ -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;

7
lightningd/test/run-invoice-select-inchan.c

@ -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(); }

7
wallet/test/run-wallet.c

@ -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…
Cancel
Save