@@ -80,20 +80,61 @@ impl OffersMessageHandler for TestOffersMessageHandler {
80
80
81
81
#[ derive( Clone , Debug , PartialEq ) ]
82
82
enum 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
83
92
Request ,
93
+
94
+ /// The counterpart to the [`Request`] variant in the onion exchange
95
+ /// request-response mechanism.
96
+ ///
97
+ /// [`Request`]: TestCustomMessage::Request
84
98
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 ,
85
119
}
86
120
87
121
const CUSTOM_REQUEST_MESSAGE_TYPE : u64 = 4242 ;
88
122
const 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
+
89
126
const CUSTOM_REQUEST_MESSAGE_CONTENTS : [ u8 ; 32 ] = [ 42 ; 32 ] ;
90
127
const 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 ] ;
91
130
92
131
impl OnionMessageContents for TestCustomMessage {
93
132
fn tlv_type ( & self ) -> u64 {
94
133
match self {
95
134
TestCustomMessage :: Request => CUSTOM_REQUEST_MESSAGE_TYPE ,
96
135
TestCustomMessage :: Response => CUSTOM_RESPONSE_MESSAGE_TYPE ,
136
+ TestCustomMessage :: ResponseA => CUSTOM_RESPONSE_A_MESSAGE_TYPE ,
137
+ TestCustomMessage :: ResponseB => CUSTOM_RESPONSE_B_MESSAGE_TYPE ,
97
138
}
98
139
}
99
140
fn msg_type ( & self ) -> & ' static str {
@@ -106,6 +147,8 @@ impl Writeable for TestCustomMessage {
106
147
match self {
107
148
TestCustomMessage :: Request => Ok ( CUSTOM_REQUEST_MESSAGE_CONTENTS . write ( w) ?) ,
108
149
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) ?) ,
109
152
}
110
153
}
111
154
}
@@ -145,6 +188,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
145
188
let response_option = match msg {
146
189
TestCustomMessage :: Request => Some ( TestCustomMessage :: Response ) ,
147
190
TestCustomMessage :: Response => None ,
191
+ TestCustomMessage :: ResponseA => Some ( TestCustomMessage :: ResponseB ) ,
192
+ TestCustomMessage :: ResponseB => Some ( TestCustomMessage :: ResponseA ) ,
148
193
} ;
149
194
if let ( Some ( response) , Some ( responder) ) = ( response_option, responder) {
150
195
responder. respond ( response)
@@ -164,6 +209,16 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
164
209
assert_eq ! ( buf, CUSTOM_RESPONSE_MESSAGE_CONTENTS ) ;
165
210
Ok ( Some ( TestCustomMessage :: Response ) )
166
211
} ,
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
+ }
167
222
_ => Ok ( None ) ,
168
223
}
169
224
}
0 commit comments