mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
channeld: restore ping command, but only for channeld.
It's probably not worth fixing for the other daemons. Changelog-Changed: JSON-RPC: `ping` now only works if we have a channel with the peer. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
be2622a4ff
commit
c9b82bf1d2
@@ -1,9 +1,11 @@
|
||||
#include <channeld/channeld_wiregen.h>
|
||||
#include <common/json_command.h>
|
||||
#include <common/json_tok.h>
|
||||
#include <common/param.h>
|
||||
#include <gossipd/gossipd_wiregen.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/peer_control.h>
|
||||
#include <lightningd/ping.h>
|
||||
#include <lightningd/subd.h>
|
||||
|
||||
@@ -45,33 +47,37 @@ static struct ping_command *new_ping_command(const tal_t *ctx,
|
||||
return pc;
|
||||
}
|
||||
|
||||
void ping_reply(struct subd *subd, const u8 *msg)
|
||||
void ping_reply(struct subd *channeld, const u8 *msg)
|
||||
{
|
||||
(void)find_ping_cmd;
|
||||
#if 0 /* Disabled until channeld sends us ping info */
|
||||
u16 totlen;
|
||||
bool ok, sent = true;
|
||||
struct node_id id;
|
||||
bool sent;
|
||||
struct ping_command *pc;
|
||||
struct channel *c = channeld->channel;
|
||||
|
||||
log_debug(subd->ld->log, "Got ping reply!");
|
||||
ok = fromwire_gossipd_ping_reply(msg, &id, &sent, &totlen);
|
||||
log_debug(channeld->log, "Got ping reply!");
|
||||
pc = find_ping_cmd(channeld->ld, &c->peer->id);
|
||||
if (!pc) {
|
||||
log_broken(channeld->log, "Unexpected ping reply?");
|
||||
return;
|
||||
}
|
||||
|
||||
pc = find_ping_cmd(subd->ld, &id);
|
||||
assert(pc);
|
||||
|
||||
if (!ok)
|
||||
if (!fromwire_channeld_ping_reply(msg, &sent, &totlen)) {
|
||||
log_broken(channeld->log, "Malformed ping reply %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
was_pending(command_fail(pc->cmd, LIGHTNINGD,
|
||||
"Bad reply message"));
|
||||
else if (!sent)
|
||||
was_pending(command_fail(pc->cmd, LIGHTNINGD, "Unknown peer"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sent)
|
||||
was_pending(command_fail(pc->cmd, LIGHTNINGD,
|
||||
"Ping already pending"));
|
||||
else {
|
||||
struct json_stream *response = json_stream_success(pc->cmd);
|
||||
|
||||
json_add_num(response, "totlen", totlen);
|
||||
was_pending(command_success(pc->cmd, response));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct command_result *json_ping(struct command *cmd,
|
||||
@@ -81,6 +87,9 @@ static struct command_result *json_ping(struct command *cmd,
|
||||
{
|
||||
unsigned int *len, *pongbytes;
|
||||
struct node_id *id;
|
||||
struct peer *peer;
|
||||
struct channel *channel;
|
||||
u8 *msg;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("id", param_node_id, &id),
|
||||
@@ -114,14 +123,20 @@ static struct command_result *json_ping(struct command *cmd,
|
||||
"pongbytes %u > 65535", *pongbytes);
|
||||
}
|
||||
|
||||
peer = peer_by_id(cmd->ld, id);
|
||||
if (!peer)
|
||||
return command_fail(cmd, LIGHTNINGD, "Peer not connected");
|
||||
|
||||
channel = peer_active_channel(peer);
|
||||
if (!channel || !channel->owner || channel->state != CHANNELD_NORMAL)
|
||||
return command_fail(cmd, LIGHTNINGD, "Peer bad state");
|
||||
|
||||
/* parent is cmd, so when we complete cmd, we free this. */
|
||||
new_ping_command(cmd, cmd->ld, id, cmd);
|
||||
|
||||
#if 0 /* FIXME: make channeld take this message */
|
||||
/* gossipd handles all pinging, even if it's in another daemon. */
|
||||
msg = towire_gossipd_ping(NULL, id, *pongbytes, *len);
|
||||
subd_send_msg(cmd->ld->gossip, take(msg));
|
||||
#endif
|
||||
msg = towire_channeld_ping(NULL, *pongbytes, *len);
|
||||
subd_send_msg(channel->owner, take(msg));
|
||||
|
||||
return command_still_pending(cmd);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user