mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 09:04:22 +01:00
jsonrpc: Added 'getnodes' to list known nodes.
getnodes returns an object containing a single array of 'nodes'. Each element contains the node's ID, its hostname and its port. If unknown (because we haven't seen a node announcement yet) then the port is 0 and the hostname is null.
This commit is contained in:
@@ -285,6 +285,7 @@ static const struct json_command *cmdlist[] = {
|
|||||||
&getlog_command,
|
&getlog_command,
|
||||||
&connect_command,
|
&connect_command,
|
||||||
&getpeers_command,
|
&getpeers_command,
|
||||||
|
&getnodes_command,
|
||||||
&gethtlcs_command,
|
&gethtlcs_command,
|
||||||
&close_command,
|
&close_command,
|
||||||
&newaddr_command,
|
&newaddr_command,
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ extern const struct json_command newaddr_command;
|
|||||||
extern const struct json_command connect_command;
|
extern const struct json_command connect_command;
|
||||||
extern const struct json_command close_command;
|
extern const struct json_command close_command;
|
||||||
extern const struct json_command getpeers_command;
|
extern const struct json_command getpeers_command;
|
||||||
|
extern const struct json_command getnodes_command;
|
||||||
|
|
||||||
/* Invoice management. */
|
/* Invoice management. */
|
||||||
extern const struct json_command invoice_command;
|
extern const struct json_command invoice_command;
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ struct node *new_node(struct lightningd_state *dstate,
|
|||||||
n->id = *id;
|
n->id = *id;
|
||||||
n->in = tal_arr(n, struct node_connection *, 0);
|
n->in = tal_arr(n, struct node_connection *, 0);
|
||||||
n->out = tal_arr(n, struct node_connection *, 0);
|
n->out = tal_arr(n, struct node_connection *, 0);
|
||||||
|
n->port = 0;
|
||||||
node_map_add(dstate->nodes, n);
|
node_map_add(dstate->nodes, n);
|
||||||
tal_add_destructor(n, destroy_node);
|
tal_add_destructor(n, destroy_node);
|
||||||
|
|
||||||
@@ -511,4 +512,40 @@ const struct json_command dev_routefail_command = {
|
|||||||
"Returns an empty result on success"
|
"Returns an empty result on success"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void json_getnodes(struct command *cmd,
|
||||||
|
const char *buffer, const jsmntok_t *params)
|
||||||
|
{
|
||||||
|
struct json_result *response = new_json_result(cmd);
|
||||||
|
struct node *n;
|
||||||
|
struct node_map_iter i;
|
||||||
|
|
||||||
|
n = node_map_first(cmd->dstate->nodes, &i);
|
||||||
|
|
||||||
|
json_object_start(response, NULL);
|
||||||
|
json_array_start(response, "nodes");
|
||||||
|
|
||||||
|
while (n != NULL) {
|
||||||
|
json_object_start(response, NULL);
|
||||||
|
json_add_pubkey(response, cmd->dstate->secpctx,
|
||||||
|
"nodeid", &n->id);
|
||||||
|
json_add_num(response, "port", n->port);
|
||||||
|
if (!n->port)
|
||||||
|
json_add_null(response, "hostname");
|
||||||
|
else
|
||||||
|
json_add_string(response, "hostname", n->hostname);
|
||||||
|
|
||||||
|
json_object_end(response);
|
||||||
|
n = node_map_next(cmd->dstate->nodes, &i);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_array_end(response);
|
||||||
|
json_object_end(response);
|
||||||
|
command_success(cmd, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct json_command getnodes_command = {
|
||||||
|
"getnodes",
|
||||||
|
json_getnodes,
|
||||||
|
"List all known nodes in the network.",
|
||||||
|
"Returns a 'nodes' array"
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user