Browse Source

ping: no longer a dev_ command.

Fixes: #1407
Suggested-by: conanoc@gmail.com
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
71575b2115
  1. 3
      CHANGELOG.md
  2. 4
      contrib/pylightning/lightning/lightning.py
  3. 2
      lightningd/Makefile
  4. 18
      lightningd/ping.c
  5. 12
      tests/test_misc.py

3
CHANGELOG.md

@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Documentation: Added CHANGELOG.md - Documentation: Added CHANGELOG.md
- JSON API: `getinfo` has new fields `alias` and `color`. - JSON API: `getinfo` has new fields `alias` and `color`.
- JSON API: `listpeers` has new fields `global_features` and `local_features`. - 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`. - Protocol: gossipd now deliberately delays spamming with `channel_update`.
- Config: `--conf` option to set config file. - Config: `--conf` option to set config file.
- JSON API: Added description to invoices and payments (#1740). - JSON API: Added description to invoices and payments (#1740).

4
contrib/pylightning/lightning/lightning.py

@ -394,7 +394,7 @@ class LightningRpc(UnixDomainSocketRpc):
} }
return self.call("dev-reenable-commit", payload) 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}" Send {peer_id} a ping of length {len} asking for {pongbytes}"
""" """
@ -403,7 +403,7 @@ class LightningRpc(UnixDomainSocketRpc):
"len": length, "len": length,
"pongbytes": pongbytes "pongbytes": pongbytes
} }
return self.call("dev-ping", payload) return self.call("ping", payload)
def dev_memdump(self): def dev_memdump(self):
""" """

2
lightningd/Makefile

@ -80,7 +80,7 @@ LIGHTNINGD_SRC := \
# Source files without corresponding headers # Source files without corresponding headers
LIGHTNINGD_SRC_NOHDR := \ LIGHTNINGD_SRC_NOHDR := \
lightningd/dev_ping.c \ lightningd/ping.c \
lightningd/memdump.c lightningd/memdump.c
LIGHTNINGD_OBJS := $(LIGHTNINGD_SRC:.c=.o) $(LIGHTNINGD_SRC_NOHDR:.c=.o) LIGHTNINGD_OBJS := $(LIGHTNINGD_SRC:.c=.o) $(LIGHTNINGD_SRC_NOHDR:.c=.o)

18
lightningd/dev_ping.c → 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, static void json_ping(struct command *cmd,
const char *buffer, const jsmntok_t *params) const char *buffer, const jsmntok_t *params)
{ {
u8 *msg; u8 *msg;
unsigned int len, pongbytes; unsigned int len, pongbytes;
@ -44,8 +44,8 @@ static void json_dev_ping(struct command *cmd,
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", json_tok_pubkey, &id), p_req("id", json_tok_pubkey, &id),
p_req("len", json_tok_number, &len), p_opt_def("len", json_tok_number, &len, 128),
p_req("pongbytes", json_tok_number, &pongbytes), p_opt_def("pongbytes", json_tok_number, &pongbytes, 128),
NULL)) NULL))
return; return;
@ -83,9 +83,9 @@ static void json_dev_ping(struct command *cmd,
command_still_pending(cmd); command_still_pending(cmd);
} }
static const struct json_command dev_ping_command = { static const struct json_command ping_command = {
"dev-ping", "ping",
json_dev_ping, json_ping,
"Send {peerid} a ping of length {len} asking for {pongbytes}" "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);

12
tests/test_misc.py

@ -110,30 +110,30 @@ def test_ping(node_factory):
def ping_tests(l1, l2): def ping_tests(l1, l2):
# 0-byte pong gives just type + length field. # 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 assert ret['totlen'] == 4
# 1000-byte ping, 0-byte pong. # 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 assert ret['totlen'] == 4
# 1000 byte pong. # 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 assert ret['totlen'] == 1004
# Maximum length pong. # 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 assert ret['totlen'] == 65535
# Overlength -> no reply. # Overlength -> no reply.
for s in range(65532, 65536): 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 assert ret['totlen'] == 0
# 65535 - type(2 bytes) - num_pong_bytes(2 bytes) - byteslen(2 bytes) # 65535 - type(2 bytes) - num_pong_bytes(2 bytes) - byteslen(2 bytes)
# = 65529 max. # = 65529 max.
with pytest.raises(RpcError, match=r'oversize ping'): 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. # Test gossip pinging.
ping_tests(l1, l2) ping_tests(l1, l2)

Loading…
Cancel
Save