From e9fc9aef349642624810e77fa73b85b37637fb62 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 4 Dec 2019 17:03:49 +0100 Subject: [PATCH] channeld: Send messages if instructed to by lightningd --- channeld/channeld.c | 10 +++++++++- tests/test_misc.py | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 6506ae0db..031fe88a7 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2852,6 +2852,14 @@ static void handle_dev_memleak(struct peer *peer, const u8 *msg) take(towire_channel_dev_memleak_reply(NULL, found_leak))); } + +/* We were told to send a custommsg to the peer by `lightningd`. All the + * verification is done on the side of `lightningd` so we should be good to + * just forward it here. */ +static void channeld_send_custommsg(struct peer *peer, const u8 *msg) +{ + sync_crypto_write(peer->pps, take(msg)); +} #endif /* DEVELOPER */ static void req_in(struct peer *peer, const u8 *msg) @@ -2917,7 +2925,7 @@ static void req_in(struct peer *peer, const u8 *msg) switch ((enum common_wire_type)t) { #if DEVELOPER case WIRE_CUSTOMMSG_OUT: - /* TODO(cdecker) Add handling of custom messages. */ + channeld_send_custommsg(peer, msg); return; #else case WIRE_CUSTOMMSG_OUT: diff --git a/tests/test_misc.py b/tests/test_misc.py index dee1331f5..648374fa7 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2096,11 +2096,23 @@ 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') + # This should work since the peer is currently owned by `channeld` l2.rpc.dev_sendcustommsg(l1.info['id'], msg) + l2.daemon.wait_for_log( + r'{peer_id}-{owner}-chan#[0-9]: \[OUT\] {serialized}'.format( + owner='channeld', serialized=serialized, peer_id=l1.info['id'] + ) + ) + l1.daemon.wait_for_log(r'\[IN\] {}'.format(serialized)) + l1.daemon.wait_for_log( + r'Got a custom message {serialized} from peer {peer_id}'.format( + serialized=serialized, peer_id=l2.info['id'])) + + # This should work since the peer is currently owned by `openingd` l2.rpc.dev_sendcustommsg(l4.info['id'], msg) l2.daemon.wait_for_log( - r'{peer_id}-openingd-chan#[0-9]: \[OUT\] {serialized}'.format( - serialized=serialized, peer_id=l4.info['id'] + r'{peer_id}-{owner}-chan#[0-9]: \[OUT\] {serialized}'.format( + owner='openingd', serialized=serialized, peer_id=l4.info['id'] ) ) l4.daemon.wait_for_log(r'\[IN\] {}'.format(serialized))