getinfo: new RPC command

Useful for getting ID, what port (if not set in config file).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-09-13 03:37:07 +09:30
parent c648897695
commit 221a96cdeb
4 changed files with 30 additions and 5 deletions

View File

@ -255,6 +255,28 @@ static const struct json_command dev_restart_command = {
"Simple restart test for developers"
};
static void json_getinfo(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
struct json_result *response = new_json_result(cmd);
json_object_start(response, NULL);
json_add_pubkey(response, cmd->dstate->secpctx, "id", &cmd->dstate->id);
/* FIXME: Keep netaddrs and list them all. */
if (cmd->dstate->portnum)
json_add_num(response, "port", cmd->dstate->portnum);
json_add_bool(response, "testnet", cmd->dstate->config.testnet);
json_object_end(response);
command_success(cmd, response);
}
static const struct json_command getinfo_command = {
"getinfo",
json_getinfo,
"Get general information about this node",
"Returns {id}, {port}, {testnet}, etc."
};
static const struct json_command *cmdlist[] = {
&help_command,
&stop_command,

View File

@ -254,6 +254,7 @@ static struct lightningd_state *lightningd_state(void)
list_head_init(&dstate->peers);
list_head_init(&dstate->pay_commands);
dstate->portnum = 0;
timers_init(&dstate->timers, controlled_time());
txwatch_hash_init(&dstate->txwatches);
txowatch_hash_init(&dstate->txowatches);

View File

@ -72,6 +72,9 @@ struct lightningd_state {
char *config_dir;
char *rpc_filename;
/* Port we're listening on */
u16 portnum;
/* Configuration settings. */
struct config config;

View File

@ -2745,7 +2745,6 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum)
struct sockaddr_in6 addr6;
socklen_t len;
int fd1, fd2;
u16 listen_port;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
@ -2771,10 +2770,10 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum)
close_noerr(fd1);
} else {
addr.sin_port = in6.sin6_port;
listen_port = ntohs(addr.sin_port);
dstate->portnum = ntohs(addr.sin_port);
log_info(dstate->base_log,
"Creating IPv6 listener on port %u",
listen_port);
dstate->portnum);
io_new_listener(dstate, fd1, peer_connected_in, dstate);
}
}
@ -2790,10 +2789,10 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum)
strerror(errno));
close_noerr(fd2);
} else {
listen_port = ntohs(addr.sin_port);
dstate->portnum = ntohs(addr.sin_port);
log_info(dstate->base_log,
"Creating IPv4 listener on port %u",
listen_port);
dstate->portnum);
io_new_listener(dstate, fd2, peer_connected_in, dstate);
}
}