mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
ping: no longer a dev_ command.
Fixes: #1407 Suggested-by: conanoc@gmail.com Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
be7a27a765
commit
71575b2115
@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- Documentation: Added CHANGELOG.md
|
||||
- JSON API: `getinfo` has new fields `alias` and `color`.
|
||||
- JSON API: `listpeers` has new fields `global_features` and `local_features`.
|
||||
- JSON API:`listnodes` has new field `global_features`.
|
||||
- JSON API: `listnodes` has new field `global_features`.
|
||||
- JSON API: `ping` command to send a ping to a connected peer.
|
||||
- Protocol: gossipd now deliberately delays spamming with `channel_update`.
|
||||
- Config: `--conf` option to set config file.
|
||||
- JSON API: Added description to invoices and payments (#1740).
|
||||
|
@ -394,7 +394,7 @@ class LightningRpc(UnixDomainSocketRpc):
|
||||
}
|
||||
return self.call("dev-reenable-commit", payload)
|
||||
|
||||
def dev_ping(self, peer_id, length, pongbytes):
|
||||
def ping(self, peer_id, length=128, pongbytes=128):
|
||||
"""
|
||||
Send {peer_id} a ping of length {len} asking for {pongbytes}"
|
||||
"""
|
||||
@ -403,7 +403,7 @@ class LightningRpc(UnixDomainSocketRpc):
|
||||
"len": length,
|
||||
"pongbytes": pongbytes
|
||||
}
|
||||
return self.call("dev-ping", payload)
|
||||
return self.call("ping", payload)
|
||||
|
||||
def dev_memdump(self):
|
||||
"""
|
||||
|
@ -80,7 +80,7 @@ LIGHTNINGD_SRC := \
|
||||
|
||||
# Source files without corresponding headers
|
||||
LIGHTNINGD_SRC_NOHDR := \
|
||||
lightningd/dev_ping.c \
|
||||
lightningd/ping.c \
|
||||
lightningd/memdump.c
|
||||
|
||||
LIGHTNINGD_OBJS := $(LIGHTNINGD_SRC:.c=.o) $(LIGHTNINGD_SRC_NOHDR:.c=.o)
|
||||
|
@ -35,7 +35,7 @@ static void ping_reply(struct subd *subd, const u8 *msg, const int *fds UNUSED,
|
||||
}
|
||||
}
|
||||
|
||||
static void json_dev_ping(struct command *cmd,
|
||||
static void json_ping(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
u8 *msg;
|
||||
@ -44,8 +44,8 @@ static void json_dev_ping(struct command *cmd,
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("id", json_tok_pubkey, &id),
|
||||
p_req("len", json_tok_number, &len),
|
||||
p_req("pongbytes", json_tok_number, &pongbytes),
|
||||
p_opt_def("len", json_tok_number, &len, 128),
|
||||
p_opt_def("pongbytes", json_tok_number, &pongbytes, 128),
|
||||
NULL))
|
||||
return;
|
||||
|
||||
@ -83,9 +83,9 @@ static void json_dev_ping(struct command *cmd,
|
||||
command_still_pending(cmd);
|
||||
}
|
||||
|
||||
static const struct json_command dev_ping_command = {
|
||||
"dev-ping",
|
||||
json_dev_ping,
|
||||
"Send {peerid} a ping of length {len} asking for {pongbytes}"
|
||||
static const struct json_command ping_command = {
|
||||
"ping",
|
||||
json_ping,
|
||||
"Send {peerid} a ping of length {len} (default 128) asking for {pongbytes} (default 128)"
|
||||
};
|
||||
AUTODATA(json_command, &dev_ping_command);
|
||||
AUTODATA(json_command, &ping_command);
|
@ -110,30 +110,30 @@ def test_ping(node_factory):
|
||||
|
||||
def ping_tests(l1, l2):
|
||||
# 0-byte pong gives just type + length field.
|
||||
ret = l1.rpc.dev_ping(l2.info['id'], 0, 0)
|
||||
ret = l1.rpc.ping(l2.info['id'], 0, 0)
|
||||
assert ret['totlen'] == 4
|
||||
|
||||
# 1000-byte ping, 0-byte pong.
|
||||
ret = l1.rpc.dev_ping(l2.info['id'], 1000, 0)
|
||||
ret = l1.rpc.ping(l2.info['id'], 1000, 0)
|
||||
assert ret['totlen'] == 4
|
||||
|
||||
# 1000 byte pong.
|
||||
ret = l1.rpc.dev_ping(l2.info['id'], 1000, 1000)
|
||||
ret = l1.rpc.ping(l2.info['id'], 1000, 1000)
|
||||
assert ret['totlen'] == 1004
|
||||
|
||||
# Maximum length pong.
|
||||
ret = l1.rpc.dev_ping(l2.info['id'], 1000, 65531)
|
||||
ret = l1.rpc.ping(l2.info['id'], 1000, 65531)
|
||||
assert ret['totlen'] == 65535
|
||||
|
||||
# Overlength -> no reply.
|
||||
for s in range(65532, 65536):
|
||||
ret = l1.rpc.dev_ping(l2.info['id'], 1000, s)
|
||||
ret = l1.rpc.ping(l2.info['id'], 1000, s)
|
||||
assert ret['totlen'] == 0
|
||||
|
||||
# 65535 - type(2 bytes) - num_pong_bytes(2 bytes) - byteslen(2 bytes)
|
||||
# = 65529 max.
|
||||
with pytest.raises(RpcError, match=r'oversize ping'):
|
||||
l1.rpc.dev_ping(l2.info['id'], 65530, 1)
|
||||
l1.rpc.ping(l2.info['id'], 65530, 1)
|
||||
|
||||
# Test gossip pinging.
|
||||
ping_tests(l1, l2)
|
||||
|
Loading…
Reference in New Issue
Block a user