@@ -80,20 +80,61 @@ impl OffersMessageHandler for TestOffersMessageHandler {
8080
8181#[ derive( Clone , Debug , PartialEq ) ]
8282enum TestCustomMessage {
83+ /// A variant to test the onion exchange request mechanism.
84+ /// When this variant is used, [`handle_custom_message`] will create
85+ /// the corresponding [`Response`] and interpret that no further response
86+ /// is expected from the peer.
87+ /// Therefore, it will not signal the addition of a reply path to the onion
88+ /// message and will create a [`ResponseInstruction::WithoutReplyPath`] for it.
89+ ///
90+ /// [`handle_custom_message`]: TestCustomMessageHandler::handle_custom_message
91+ /// [`Response`]: TestCustomMessage::Response
8392 Request ,
93+
94+ /// The counterpart to the [`Request`] variant in the onion exchange
95+ /// request-response mechanism.
96+ ///
97+ /// [`Request`]: TestCustomMessage::Request
8498 Response ,
99+
100+ /// A variant to enable response ping-pong.
101+ /// When this variant is used, [`handle_custom_message`] interprets that
102+ /// a reply path should be appended to the onion message to facilitate response
103+ /// ping-pong. Consequently, it will create the corresponding
104+ /// [`ResponseInstruction::WithReplyPath`] for it.
105+ ///
106+ /// [`handle_custom_message`]: TestCustomMessageHandler::handle_custom_message
107+ ResponseA ,
108+
109+ /// The counterpart to the [`ResponseA`] variant for the response
110+ /// ping-pong mechanism.
111+ /// Similar to [`ResponseA`], when this variant is used, [`handle_custom_message`]
112+ /// interprets that a reply path should be appended to the onion message
113+ /// to facilitate response ping-pong. Therefore, it will create the corresponding
114+ /// [`ResponseInstruction::WithReplyPath`] for it.
115+ ///
116+ /// [`handle_custom_message`]: TestCustomMessageHandler::handle_custom_message
117+ /// [`ResponseA`]: TestCustomMessage::ResponseA
118+ ResponseB ,
85119}
86120
87121const CUSTOM_REQUEST_MESSAGE_TYPE : u64 = 4242 ;
88122const CUSTOM_RESPONSE_MESSAGE_TYPE : u64 = 4343 ;
123+ const CUSTOM_RESPONSE_A_MESSAGE_TYPE : u64 = 4344 ;
124+ const CUSTOM_RESPONSE_B_MESSAGE_TYPE : u64 = 4345 ;
125+
89126const CUSTOM_REQUEST_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 42 ; 32 ] ;
90127const CUSTOM_RESPONSE_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 43 ; 32 ] ;
128+ const CUSTOM_RESPONSE_A_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 44 ; 32 ] ;
129+ const CUSTOM_RESPONSE_B_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 45 ; 32 ] ;
91130
92131impl OnionMessageContents for TestCustomMessage {
93132 fn tlv_type ( & self ) -> u64 {
94133 match self {
95134 TestCustomMessage :: Request => CUSTOM_REQUEST_MESSAGE_TYPE ,
96135 TestCustomMessage :: Response => CUSTOM_RESPONSE_MESSAGE_TYPE ,
136+ TestCustomMessage :: ResponseA => CUSTOM_RESPONSE_A_MESSAGE_TYPE ,
137+ TestCustomMessage :: ResponseB => CUSTOM_RESPONSE_B_MESSAGE_TYPE ,
97138 }
98139 }
99140 fn msg_type ( & self ) -> & ' static str {
@@ -106,6 +147,8 @@ impl Writeable for TestCustomMessage {
106147 match self {
107148 TestCustomMessage :: Request => Ok ( CUSTOM_REQUEST_MESSAGE_CONTENTS . write ( w) ?) ,
108149 TestCustomMessage :: Response => Ok ( CUSTOM_RESPONSE_MESSAGE_CONTENTS . write ( w) ?) ,
150+ TestCustomMessage :: ResponseA => Ok ( CUSTOM_RESPONSE_A_MESSAGE_CONTENTS . write ( w) ?) ,
151+ TestCustomMessage :: ResponseB => Ok ( CUSTOM_RESPONSE_B_MESSAGE_CONTENTS . write ( w) ?) ,
109152 }
110153 }
111154}
@@ -145,6 +188,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
145188 let response_option = match msg {
146189 TestCustomMessage :: Request => Some ( TestCustomMessage :: Response ) ,
147190 TestCustomMessage :: Response => None ,
191+ TestCustomMessage :: ResponseA => Some ( TestCustomMessage :: ResponseB ) ,
192+ TestCustomMessage :: ResponseB => Some ( TestCustomMessage :: ResponseA ) ,
148193 } ;
149194 if let ( Some ( response) , Some ( responder) ) = ( response_option, responder) {
150195 responder. respond ( response)
@@ -164,6 +209,16 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
164209 assert_eq ! ( buf, CUSTOM_RESPONSE_MESSAGE_CONTENTS ) ;
165210 Ok ( Some ( TestCustomMessage :: Response ) )
166211 } ,
212+ CUSTOM_RESPONSE_A_MESSAGE_TYPE => {
213+ let buf = read_to_end ( buffer) ?;
214+ assert_eq ! ( buf, CUSTOM_RESPONSE_A_MESSAGE_CONTENTS ) ;
215+ Ok ( Some ( TestCustomMessage :: ResponseA ) )
216+ } ,
217+ CUSTOM_RESPONSE_B_MESSAGE_TYPE => {
218+ let buf = read_to_end ( buffer) ?;
219+ assert_eq ! ( buf, CUSTOM_RESPONSE_B_MESSAGE_CONTENTS ) ;
220+ Ok ( Some ( TestCustomMessage :: ResponseB ) )
221+ }
167222 _ => Ok ( None ) ,
168223 }
169224 }
0 commit comments