mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
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:
@@ -255,6 +255,28 @@ static const struct json_command dev_restart_command = {
|
|||||||
"Simple restart test for developers"
|
"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[] = {
|
static const struct json_command *cmdlist[] = {
|
||||||
&help_command,
|
&help_command,
|
||||||
&stop_command,
|
&stop_command,
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ static struct lightningd_state *lightningd_state(void)
|
|||||||
|
|
||||||
list_head_init(&dstate->peers);
|
list_head_init(&dstate->peers);
|
||||||
list_head_init(&dstate->pay_commands);
|
list_head_init(&dstate->pay_commands);
|
||||||
|
dstate->portnum = 0;
|
||||||
timers_init(&dstate->timers, controlled_time());
|
timers_init(&dstate->timers, controlled_time());
|
||||||
txwatch_hash_init(&dstate->txwatches);
|
txwatch_hash_init(&dstate->txwatches);
|
||||||
txowatch_hash_init(&dstate->txowatches);
|
txowatch_hash_init(&dstate->txowatches);
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ struct lightningd_state {
|
|||||||
char *config_dir;
|
char *config_dir;
|
||||||
char *rpc_filename;
|
char *rpc_filename;
|
||||||
|
|
||||||
|
/* Port we're listening on */
|
||||||
|
u16 portnum;
|
||||||
|
|
||||||
/* Configuration settings. */
|
/* Configuration settings. */
|
||||||
struct config config;
|
struct config config;
|
||||||
|
|
||||||
|
|||||||
@@ -2745,7 +2745,6 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum)
|
|||||||
struct sockaddr_in6 addr6;
|
struct sockaddr_in6 addr6;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
int fd1, fd2;
|
int fd1, fd2;
|
||||||
u16 listen_port;
|
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
@@ -2771,10 +2770,10 @@ void setup_listeners(struct lightningd_state *dstate, unsigned int portnum)
|
|||||||
close_noerr(fd1);
|
close_noerr(fd1);
|
||||||
} else {
|
} else {
|
||||||
addr.sin_port = in6.sin6_port;
|
addr.sin_port = in6.sin6_port;
|
||||||
listen_port = ntohs(addr.sin_port);
|
dstate->portnum = ntohs(addr.sin_port);
|
||||||
log_info(dstate->base_log,
|
log_info(dstate->base_log,
|
||||||
"Creating IPv6 listener on port %u",
|
"Creating IPv6 listener on port %u",
|
||||||
listen_port);
|
dstate->portnum);
|
||||||
io_new_listener(dstate, fd1, peer_connected_in, dstate);
|
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));
|
strerror(errno));
|
||||||
close_noerr(fd2);
|
close_noerr(fd2);
|
||||||
} else {
|
} else {
|
||||||
listen_port = ntohs(addr.sin_port);
|
dstate->portnum = ntohs(addr.sin_port);
|
||||||
log_info(dstate->base_log,
|
log_info(dstate->base_log,
|
||||||
"Creating IPv4 listener on port %u",
|
"Creating IPv4 listener on port %u",
|
||||||
listen_port);
|
dstate->portnum);
|
||||||
io_new_listener(dstate, fd2, peer_connected_in, dstate);
|
io_new_listener(dstate, fd2, peer_connected_in, dstate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user