Browse Source

daemon: expose find_peer(), rename other to find_peer_json().

This is the more normal case; find by ID.  The low-level json commands are
really just for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
27da8f77b5
  1. 36
      daemon/peer.c
  2. 2
      daemon/peer.h

36
daemon/peer.c

@ -50,23 +50,29 @@ struct json_connecting {
struct anchor_input *input;
};
static struct peer *find_peer(struct lightningd_state *dstate,
struct peer *find_peer(struct lightningd_state *dstate, const struct pubkey *id)
{
struct peer *peer;
list_for_each(&dstate->peers, peer, list) {
if (peer->state != STATE_INIT && pubkey_eq(&peer->id, id))
return peer;
}
return NULL;
}
static struct peer *find_peer_json(struct lightningd_state *dstate,
const char *buffer,
jsmntok_t *peeridtok)
{
struct pubkey peerid;
struct peer *peer;
if (!pubkey_from_hexstr(dstate->secpctx,
buffer + peeridtok->start,
peeridtok->end - peeridtok->start, &peerid))
return NULL;
list_for_each(&dstate->peers, peer, list) {
if (peer->state != STATE_INIT && pubkey_eq(&peer->id, &peerid))
return peer;
}
return NULL;
return find_peer(dstate, &peerid);
}
static struct json_result *null_response(const tal_t *ctx)
@ -2499,7 +2505,7 @@ static void json_newhtlc(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2592,7 +2598,7 @@ static void json_fulfillhtlc(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2653,7 +2659,7 @@ static void json_failhtlc(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2709,7 +2715,7 @@ static void json_commit(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2748,7 +2754,7 @@ static void json_close(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2788,7 +2794,7 @@ static void json_disconnect(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2825,7 +2831,7 @@ static void json_signcommit(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
@ -2864,7 +2870,7 @@ static void json_output(struct command *cmd,
return;
}
peer = find_peer(cmd->dstate, buffer, peeridtok);
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;

2
daemon/peer.h

@ -220,6 +220,8 @@ struct peer {
void setup_listeners(struct lightningd_state *dstate, unsigned int portnum);
struct peer *find_peer(struct lightningd_state *dstate, const struct pubkey *id);
/* Populates very first peer->{local,remote}.commit->{tx,cstate} */
bool setup_first_commit(struct peer *peer);

Loading…
Cancel
Save