From 71575b2115e2e74aa74c3aca15c6fa5031f2f97c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 9 Aug 2018 09:59:30 +0930 Subject: [PATCH] ping: no longer a dev_ command. Fixes: #1407 Suggested-by: conanoc@gmail.com Signed-off-by: Rusty Russell --- CHANGELOG.md | 3 ++- contrib/pylightning/lightning/lightning.py | 4 ++-- lightningd/Makefile | 2 +- lightningd/{dev_ping.c => ping.c} | 18 +++++++++--------- tests/test_misc.py | 12 ++++++------ 5 files changed, 20 insertions(+), 19 deletions(-) rename lightningd/{dev_ping.c => ping.c} (83%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae414326e..e3a493d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index 08a3c06e6..2513b4bd6 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -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): """ diff --git a/lightningd/Makefile b/lightningd/Makefile index 56bfba92d..540c2cf37 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -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) diff --git a/lightningd/dev_ping.c b/lightningd/ping.c similarity index 83% rename from lightningd/dev_ping.c rename to lightningd/ping.c index 8e962b629..ae216644c 100644 --- a/lightningd/dev_ping.c +++ b/lightningd/ping.c @@ -35,8 +35,8 @@ static void ping_reply(struct subd *subd, const u8 *msg, const int *fds UNUSED, } } -static void json_dev_ping(struct command *cmd, - const char *buffer, const jsmntok_t *params) +static void json_ping(struct command *cmd, + const char *buffer, const jsmntok_t *params) { u8 *msg; unsigned int len, pongbytes; @@ -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); diff --git a/tests/test_misc.py b/tests/test_misc.py index 21968dcb4..abad97db8 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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)