@@ -283,7 +283,14 @@ where
283
283
& self , path : OnionMessagePath , message : OnionMessageContents < T > ,
284
284
reply_path : Option < BlindedPath >
285
285
) -> Result < ( ) , SendError > {
286
- let ( introduction_node_id, onion_msg) = self . make_onion_message ( path, message, reply_path) ?;
286
+ let ( introduction_node_id, onion_msg) = Self :: make_onion_message (
287
+ & self . entropy_source ,
288
+ & self . node_signer ,
289
+ & self . secp_ctx ,
290
+ path,
291
+ message,
292
+ reply_path
293
+ ) ?;
287
294
288
295
let mut pending_per_peer_msgs = self . pending_messages . lock ( ) . unwrap ( ) ;
289
296
if outbound_buffer_full ( & introduction_node_id, & pending_per_peer_msgs) { return Err ( SendError :: BufferFull ) }
@@ -296,19 +303,15 @@ where
296
303
}
297
304
}
298
305
299
- /// Construct an onion message with contents `message` to the destination of `path`.
300
- pub fn construct_onion_message < T : CustomOnionMessageContents > (
301
- & self , path : OnionMessagePath , message : OnionMessageContents < T > ,
302
- reply_path : Option < BlindedPath >
303
- ) -> Result < Vec < u8 > , SendError > {
304
- let ( _, onion_routing_packet) = self . make_onion_message ( path, message, reply_path) ?;
305
- Ok ( onion_routing_packet. onion_routing_packet . hop_data )
306
- }
307
-
308
- // returns (introduction_node_id, onion_msg)
309
- fn make_onion_message < T : CustomOnionMessageContents > (
310
- & self , path : OnionMessagePath , message : OnionMessageContents < T > ,
311
- reply_path : Option < BlindedPath >
306
+ /// Make an onion message with contents `message` to the destination of `path`.
307
+ /// Returns (introduction_node_id, onion_msg)
308
+ pub fn make_onion_message < T : CustomOnionMessageContents > (
309
+ entropy_source : & ES ,
310
+ node_signer : & NS ,
311
+ secp_ctx : & Secp256k1 < secp256k1:: All > ,
312
+ path : OnionMessagePath ,
313
+ message : OnionMessageContents < T > ,
314
+ reply_path : Option < BlindedPath > ,
312
315
) -> Result < ( PublicKey , msgs:: OnionMessage ) , SendError > {
313
316
let OnionMessagePath { intermediate_nodes, mut destination } = path;
314
317
if let Destination :: BlindedPath ( BlindedPath { ref blinded_hops, .. } ) = destination {
@@ -323,31 +326,31 @@ where
323
326
// advance the blinded path by 1 hop so the second hop is the new introduction node.
324
327
if intermediate_nodes. len ( ) == 0 {
325
328
if let Destination :: BlindedPath ( ref mut blinded_path) = destination {
326
- let our_node_id = self . node_signer . get_node_id ( Recipient :: Node )
329
+ let our_node_id = node_signer. get_node_id ( Recipient :: Node )
327
330
. map_err ( |( ) | SendError :: GetNodeIdFailed ) ?;
328
331
if blinded_path. introduction_node_id == our_node_id {
329
- advance_path_by_one ( blinded_path, & self . node_signer , & self . secp_ctx )
332
+ advance_path_by_one ( blinded_path, node_signer, & secp_ctx)
330
333
. map_err ( |( ) | SendError :: BlindedPathAdvanceFailed ) ?;
331
334
}
332
335
}
333
336
}
334
337
335
- let blinding_secret_bytes = self . entropy_source . get_secure_random_bytes ( ) ;
338
+ let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
336
339
let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
337
340
let ( introduction_node_id, blinding_point) = if intermediate_nodes. len ( ) != 0 {
338
- ( intermediate_nodes[ 0 ] , PublicKey :: from_secret_key ( & self . secp_ctx , & blinding_secret) )
341
+ ( intermediate_nodes[ 0 ] , PublicKey :: from_secret_key ( & secp_ctx, & blinding_secret) )
339
342
} else {
340
343
match destination {
341
- Destination :: Node ( pk) => ( pk, PublicKey :: from_secret_key ( & self . secp_ctx , & blinding_secret) ) ,
344
+ Destination :: Node ( pk) => ( pk, PublicKey :: from_secret_key ( & secp_ctx, & blinding_secret) ) ,
342
345
Destination :: BlindedPath ( BlindedPath { introduction_node_id, blinding_point, .. } ) =>
343
346
( introduction_node_id, blinding_point) ,
344
347
}
345
348
} ;
346
349
let ( packet_payloads, packet_keys) = packet_payloads_and_keys (
347
- & self . secp_ctx , & intermediate_nodes, destination, message, reply_path, & blinding_secret)
350
+ & secp_ctx, & intermediate_nodes, destination, message, reply_path, & blinding_secret)
348
351
. map_err ( |e| SendError :: Secp256k1 ( e) ) ?;
349
352
350
- let prng_seed = self . entropy_source . get_secure_random_bytes ( ) ;
353
+ let prng_seed = entropy_source. get_secure_random_bytes ( ) ;
351
354
let onion_routing_packet = construct_onion_message_packet (
352
355
packet_payloads, packet_keys, prng_seed) . map_err ( |( ) | SendError :: TooBigPacket ) ?;
353
356
0 commit comments