Browse Source

json-rpc: Restrict custommsgs to be odd-typed

This solves a couple of issues with the need to synchronously drop the
connection in case we were required to understand what the peer was talking
about while still allowing users to experiment, just not kill connections.
travis-debug
Christian Decker 5 years ago
parent
commit
b18c1ea543
  1. 10
      lightningd/peer_control.c
  2. 6
      tests/test_misc.py

10
lightningd/peer_control.c

@ -2404,6 +2404,16 @@ static struct command_result *json_sendcustommsg(struct command *cmd,
type, wire_type_name(type));
}
if (type % 2 == 0) {
return command_fail(
cmd, JSONRPC2_INVALID_REQUEST,
"Cannot send even-typed %d custom message. Currently "
"custom messages are limited to odd-numbered message "
"types, as even-numbered types might result in "
"disconnections.",
type);
}
peer = peer_by_id(cmd->ld, dest);
if (!peer) {
return command_fail(cmd, JSONRPC2_INVALID_REQUEST,

6
tests/test_misc.py

@ -2096,6 +2096,12 @@ def test_sendcustommsg(node_factory):
with pytest.raises(RpcError, match=r'Cannot send messages of type 18 .WIRE_PING.'):
l2.rpc.dev_sendcustommsg(l2.info['id'], r'0012')
# The sendcustommsg RPC call is currently limited to odd-typed messages,
# since they will not result in disconnections or even worse channel
# failures.
with pytest.raises(RpcError, match=r'Cannot send even-typed [0-9]+ custom message'):
l2.rpc.dev_sendcustommsg(l2.info['id'], r'00FE')
# This should work since the peer is currently owned by `channeld`
l2.rpc.dev_sendcustommsg(l1.info['id'], msg)
l2.daemon.wait_for_log(

Loading…
Cancel
Save