getpeers: new command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
d8959b3117
commit
08ccb4b6f0
|
@ -361,7 +361,6 @@ static struct io_plan *check_proof(struct io_conn *conn, struct peer *peer)
|
|||
struct sha256_double sha;
|
||||
struct signature sig;
|
||||
struct io_plan *(*cb)(struct io_conn *, struct peer *);
|
||||
struct pubkey id;
|
||||
Authenticate *auth;
|
||||
|
||||
auth = pkt_unwrap(peer, PKT__PKT_AUTH);
|
||||
|
@ -373,7 +372,7 @@ static struct io_plan *check_proof(struct io_conn *conn, struct peer *peer)
|
|||
return io_close(conn);
|
||||
}
|
||||
|
||||
if (!proto_to_pubkey(peer->state->secpctx, auth->node_id, &id)) {
|
||||
if (!proto_to_pubkey(peer->state->secpctx, auth->node_id, &peer->id)) {
|
||||
log_unusual(peer->log, "Invalid auth id");
|
||||
return io_close(conn);
|
||||
}
|
||||
|
@ -382,7 +381,7 @@ static struct io_plan *check_proof(struct io_conn *conn, struct peer *peer)
|
|||
sha256_double(&sha,
|
||||
neg->our_sessionpubkey, sizeof(neg->our_sessionpubkey));
|
||||
|
||||
if (!check_signed_hash(peer->state->secpctx, &sha, &sig, &id)) {
|
||||
if (!check_signed_hash(peer->state->secpctx, &sha, &sig, &peer->id)) {
|
||||
log_unusual(peer->log, "Bad auth signature");
|
||||
return io_close(conn);
|
||||
}
|
||||
|
|
|
@ -196,6 +196,7 @@ static const struct json_command *cmdlist[] = {
|
|||
&stop_command,
|
||||
&getlog_command,
|
||||
&connect_command,
|
||||
&getpeers_command,
|
||||
/* Developer/debugging options. */
|
||||
&echo_command,
|
||||
};
|
||||
|
|
|
@ -57,5 +57,6 @@ void setup_jsonrpc(struct lightningd_state *state, const char *rpc_filename);
|
|||
|
||||
/* Commands (from other files) */
|
||||
extern const struct json_command connect_command;
|
||||
extern const struct json_command getpeers_command;
|
||||
|
||||
#endif /* LIGHTNING_DAEMON_JSONRPC_H */
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "log.h"
|
||||
#include "peer.h"
|
||||
#include <ccan/io/io.h>
|
||||
#include <ccan/list/list.h>
|
||||
#include <ccan/noerr/noerr.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
|
@ -30,7 +31,9 @@ static struct io_plan *peer_test_check(struct io_conn *conn, struct peer *peer)
|
|||
|| strcmp(peer->inpkt->error->problem, "hello") != 0)
|
||||
fatal("Bad packet '%.6s'", peer->inpkt->error->problem);
|
||||
log_info(peer->log, "Successful hello!");
|
||||
return io_close(conn);
|
||||
|
||||
/* Sleep forever... */
|
||||
return io_wait(conn, peer, io_close_cb, NULL);
|
||||
}
|
||||
|
||||
static struct io_plan *peer_test_read(struct io_conn *conn, struct peer *peer)
|
||||
|
@ -245,3 +248,31 @@ const struct json_command connect_command = {
|
|||
"Connect to a {host} at {port}",
|
||||
"Returns an empty result on success"
|
||||
};
|
||||
|
||||
/* FIXME: Somehow we should show running DNS lookups! */
|
||||
/* FIXME: Show status of peers! */
|
||||
static void json_getpeers(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct peer *p;
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "peers");
|
||||
list_for_each(&cmd->state->peers, p, list) {
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "name", log_prefix(p->log));
|
||||
json_add_hex(response, "id", p->id.der, pubkey_derlen(&p->id));
|
||||
json_object_end(response);
|
||||
}
|
||||
json_array_end(response);
|
||||
json_object_end(response);
|
||||
command_success(cmd, response);
|
||||
}
|
||||
|
||||
const struct json_command getpeers_command = {
|
||||
"getpeers",
|
||||
json_getpeers,
|
||||
"List the current peers",
|
||||
"Returns a 'peers' array"
|
||||
};
|
||||
|
|
|
@ -15,6 +15,9 @@ struct peer {
|
|||
/* The other end's address. */
|
||||
struct netaddr addr;
|
||||
|
||||
/* Their ID. */
|
||||
struct pubkey id;
|
||||
|
||||
/* Current received packet. */
|
||||
Pkt *inpkt;
|
||||
|
||||
|
|
Loading…
Reference in New Issue