@@ -581,7 +581,7 @@ where
581
581
/// [`IgnoringMessageHandler`].
582
582
pub custom_message_handler : CustomM ,
583
583
584
- /// A message handler which only allows sending messages. This should generally be a
584
+ /// A message handler which can be used to send messages. This should generally be a
585
585
/// [`ChainMonitor`].
586
586
///
587
587
/// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
@@ -1373,6 +1373,7 @@ where
1373
1373
| self . message_handler . route_handler . provided_init_features ( their_node_id)
1374
1374
| self . message_handler . onion_message_handler . provided_init_features ( their_node_id)
1375
1375
| self . message_handler . custom_message_handler . provided_init_features ( their_node_id)
1376
+ | self . message_handler . send_only_message_handler . provided_init_features ( their_node_id)
1376
1377
}
1377
1378
1378
1379
/// Indicates a new outbound connection has been established to a node with the given `node_id`
@@ -2175,6 +2176,19 @@ where
2175
2176
self . message_handler . onion_message_handler . peer_disconnected ( their_node_id) ;
2176
2177
return Err ( PeerHandleError { } . into ( ) ) ;
2177
2178
}
2179
+ let sends_handler = & self . message_handler . send_only_message_handler ;
2180
+ if let Err ( ( ) ) = sends_handler. peer_connected ( their_node_id, & msg, inbound) {
2181
+ log_debug ! (
2182
+ logger,
2183
+ "Sending-Only Message Handler decided we couldn't communicate with peer {}" ,
2184
+ log_pubkey!( their_node_id)
2185
+ ) ;
2186
+ self . message_handler . route_handler . peer_disconnected ( their_node_id) ;
2187
+ self . message_handler . chan_handler . peer_disconnected ( their_node_id) ;
2188
+ self . message_handler . onion_message_handler . peer_disconnected ( their_node_id) ;
2189
+ self . message_handler . custom_message_handler . peer_disconnected ( their_node_id) ;
2190
+ return Err ( PeerHandleError { } . into ( ) ) ;
2191
+ }
2178
2192
2179
2193
peer_lock. awaiting_pong_timer_tick_intervals = 0 ;
2180
2194
peer_lock. their_features = Some ( msg. features ) ;
@@ -3394,6 +3408,7 @@ where
3394
3408
self . message_handler . chan_handler . peer_disconnected ( node_id) ;
3395
3409
self . message_handler . onion_message_handler . peer_disconnected ( node_id) ;
3396
3410
self . message_handler . custom_message_handler . peer_disconnected ( node_id) ;
3411
+ self . message_handler . send_only_message_handler . peer_disconnected ( node_id) ;
3397
3412
}
3398
3413
descriptor. disconnect_socket ( ) ;
3399
3414
}
@@ -3426,6 +3441,7 @@ where
3426
3441
self . message_handler . chan_handler . peer_disconnected ( node_id) ;
3427
3442
self . message_handler . onion_message_handler . peer_disconnected ( node_id) ;
3428
3443
self . message_handler . custom_message_handler . peer_disconnected ( node_id) ;
3444
+ self . message_handler . send_only_message_handler . peer_disconnected ( node_id) ;
3429
3445
}
3430
3446
} ,
3431
3447
} ;
@@ -3611,7 +3627,8 @@ where
3611
3627
let features = self . message_handler . chan_handler . provided_node_features ( )
3612
3628
| self . message_handler . route_handler . provided_node_features ( )
3613
3629
| self . message_handler . onion_message_handler . provided_node_features ( )
3614
- | self . message_handler . custom_message_handler . provided_node_features ( ) ;
3630
+ | self . message_handler . custom_message_handler . provided_node_features ( )
3631
+ | self . message_handler . send_only_message_handler . provided_node_features ( ) ;
3615
3632
let announcement = msgs:: UnsignedNodeAnnouncement {
3616
3633
features,
3617
3634
timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) ,
@@ -3735,6 +3752,7 @@ mod tests {
3735
3752
chan_handler : test_utils:: TestChannelMessageHandler ,
3736
3753
routing_handler : test_utils:: TestRoutingMessageHandler ,
3737
3754
custom_handler : TestCustomMessageHandler ,
3755
+ send_only_handler : TestBaseMsgHandler ,
3738
3756
logger : test_utils:: TestLogger ,
3739
3757
node_signer : test_utils:: TestNodeSigner ,
3740
3758
}
@@ -3787,6 +3805,32 @@ mod tests {
3787
3805
}
3788
3806
}
3789
3807
3808
+ struct TestBaseMsgHandler ( test_utils:: ConnectionTracker ) ;
3809
+
3810
+ impl BaseMessageHandler for TestBaseMsgHandler {
3811
+ fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
3812
+ Vec :: new ( )
3813
+ }
3814
+
3815
+ fn peer_disconnected ( & self , their_node_id : PublicKey ) {
3816
+ self . 0 . peer_disconnected ( their_node_id) ;
3817
+ }
3818
+
3819
+ fn peer_connected (
3820
+ & self , their_node_id : PublicKey , _msg : & Init , _inbound : bool ,
3821
+ ) -> Result < ( ) , ( ) > {
3822
+ self . 0 . peer_connected ( their_node_id)
3823
+ }
3824
+
3825
+ fn provided_node_features ( & self ) -> NodeFeatures {
3826
+ NodeFeatures :: empty ( )
3827
+ }
3828
+
3829
+ fn provided_init_features ( & self , _: PublicKey ) -> InitFeatures {
3830
+ InitFeatures :: empty ( )
3831
+ }
3832
+ }
3833
+
3790
3834
fn create_peermgr_cfgs ( peer_count : usize ) -> Vec < PeerManagerCfg > {
3791
3835
let mut cfgs = Vec :: new ( ) ;
3792
3836
for i in 0 ..peer_count {
@@ -3803,6 +3847,7 @@ mod tests {
3803
3847
logger : test_utils:: TestLogger :: with_id ( i. to_string ( ) ) ,
3804
3848
routing_handler : test_utils:: TestRoutingMessageHandler :: new ( ) ,
3805
3849
custom_handler : TestCustomMessageHandler :: new ( features) ,
3850
+ send_only_handler : TestBaseMsgHandler ( test_utils:: ConnectionTracker :: new ( ) ) ,
3806
3851
node_signer : test_utils:: TestNodeSigner :: new ( node_secret) ,
3807
3852
} ) ;
3808
3853
}
@@ -3826,6 +3871,7 @@ mod tests {
3826
3871
logger : test_utils:: TestLogger :: new ( ) ,
3827
3872
routing_handler : test_utils:: TestRoutingMessageHandler :: new ( ) ,
3828
3873
custom_handler : TestCustomMessageHandler :: new ( features) ,
3874
+ send_only_handler : TestBaseMsgHandler ( test_utils:: ConnectionTracker :: new ( ) ) ,
3829
3875
node_signer : test_utils:: TestNodeSigner :: new ( node_secret) ,
3830
3876
} ) ;
3831
3877
}
@@ -3844,6 +3890,7 @@ mod tests {
3844
3890
logger : test_utils:: TestLogger :: new ( ) ,
3845
3891
routing_handler : test_utils:: TestRoutingMessageHandler :: new ( ) ,
3846
3892
custom_handler : TestCustomMessageHandler :: new ( features) ,
3893
+ send_only_handler : TestBaseMsgHandler ( test_utils:: ConnectionTracker :: new ( ) ) ,
3847
3894
node_signer : test_utils:: TestNodeSigner :: new ( node_secret) ,
3848
3895
} ) ;
3849
3896
}
@@ -3860,7 +3907,7 @@ mod tests {
3860
3907
route_handler : & cfgs[ i] . routing_handler ,
3861
3908
onion_message_handler : IgnoringMessageHandler { } ,
3862
3909
custom_message_handler : & cfgs[ i] . custom_handler ,
3863
- send_only_message_handler : IgnoringMessageHandler { } ,
3910
+ send_only_message_handler : & cfgs [ i ] . send_only_handler ,
3864
3911
} ;
3865
3912
let peer = PeerManager :: new (
3866
3913
msg_handler,
@@ -3883,7 +3930,7 @@ mod tests {
3883
3930
& ' a test_utils:: TestLogger ,
3884
3931
& ' a TestCustomMessageHandler ,
3885
3932
& ' a test_utils:: TestNodeSigner ,
3886
- IgnoringMessageHandler ,
3933
+ & ' a TestBaseMsgHandler ,
3887
3934
> ;
3888
3935
3889
3936
fn try_establish_connection < ' a > (
@@ -4259,6 +4306,7 @@ mod tests {
4259
4306
let chan_handler = peers[ handler & 1 ] . message_handler . chan_handler ;
4260
4307
let route_handler = peers[ handler & 1 ] . message_handler . route_handler ;
4261
4308
let custom_message_handler = peers[ handler & 1 ] . message_handler . custom_message_handler ;
4309
+ let send_only_msg_handler = peers[ handler & 1 ] . message_handler . send_only_message_handler ;
4262
4310
4263
4311
match handler & !1 {
4264
4312
0 => {
@@ -4270,6 +4318,9 @@ mod tests {
4270
4318
4 => {
4271
4319
custom_message_handler. conn_tracker . fail_connections . store ( true , Ordering :: Release ) ;
4272
4320
} ,
4321
+ 6 => {
4322
+ send_only_msg_handler. 0 . fail_connections . store ( true , Ordering :: Release ) ;
4323
+ } ,
4273
4324
_ => panic ! ( ) ,
4274
4325
}
4275
4326
let ( _sd1, _sd2, a_refused, b_refused) = try_establish_connection ( & peers[ 0 ] , & peers[ 1 ] ) ;
@@ -4285,16 +4336,18 @@ mod tests {
4285
4336
chan_handler. conn_tracker. had_peers. load( Ordering :: Acquire )
4286
4337
|| route_handler. conn_tracker. had_peers. load( Ordering :: Acquire )
4287
4338
|| custom_message_handler. conn_tracker. had_peers. load( Ordering :: Acquire )
4339
+ || send_only_msg_handler. 0 . had_peers. load( Ordering :: Acquire )
4288
4340
) ;
4289
4341
// And both message handlers doing tracking should see the disconnection
4290
4342
assert ! ( chan_handler. conn_tracker. connected_peers. lock( ) . unwrap( ) . is_empty( ) ) ;
4291
4343
assert ! ( route_handler. conn_tracker. connected_peers. lock( ) . unwrap( ) . is_empty( ) ) ;
4292
4344
assert ! ( custom_message_handler. conn_tracker. connected_peers. lock( ) . unwrap( ) . is_empty( ) ) ;
4345
+ assert ! ( send_only_msg_handler. 0 . connected_peers. lock( ) . unwrap( ) . is_empty( ) ) ;
4293
4346
}
4294
4347
4295
4348
#[ test]
4296
4349
fn test_peer_connected_error_disconnects ( ) {
4297
- for i in 0 ..6 {
4350
+ for i in 0 ..8 {
4298
4351
do_test_peer_connected_error_disconnects ( i) ;
4299
4352
}
4300
4353
}
0 commit comments