Browse Source

[rpc] Add peer stats to getinfo rpc

trytravis
Conor Scott 6 years ago
committed by Rusty Russell
parent
commit
3f420dc408
  1. 28
      lightningd/peer_control.c

28
lightningd/peer_control.c

@ -1073,6 +1073,11 @@ static void json_getinfo(struct command *cmd,
const char *buffer UNUSED, const jsmntok_t *params UNUSED) const char *buffer UNUSED, const jsmntok_t *params UNUSED)
{ {
struct json_stream *response; struct json_stream *response;
struct peer *peer;
struct channel *channel;
unsigned int pending_channels = 0, active_channels = 0,
inactive_channels = 0, num_peers = 0;
if (!param(cmd, buffer, params, NULL)) if (!param(cmd, buffer, params, NULL))
return; return;
@ -1082,6 +1087,29 @@ static void json_getinfo(struct command *cmd,
json_add_string(response, "alias", (const char *)cmd->ld->alias); json_add_string(response, "alias", (const char *)cmd->ld->alias);
json_add_hex_talarr(response, "color", cmd->ld->rgb); json_add_hex_talarr(response, "color", cmd->ld->rgb);
/* Add some peer and channel stats */
list_for_each(&cmd->ld->peers, peer, list) {
num_peers++;
/* Count towards pending? */
if (peer->uncommitted_channel) {
pending_channels++;
}
list_for_each(&peer->channels, channel, list) {
if (channel->state == CHANNELD_AWAITING_LOCKIN) {
pending_channels++;
} else if (channel_active(channel)) {
active_channels++;
} else {
inactive_channels++;
}
}
}
json_add_num(response, "num_peers", num_peers);
json_add_num(response, "num_pending_channels", pending_channels);
json_add_num(response, "num_active_channels", active_channels);
json_add_num(response, "num_inactive_channels", inactive_channels);
/* Add network info */ /* Add network info */
if (cmd->ld->listen) { if (cmd->ld->listen) {
/* These are the addresses we're announcing */ /* These are the addresses we're announcing */

Loading…
Cancel
Save