@@ -3338,6 +3338,17 @@ const RETARGET_BACKFILL: u64 = RETARGET_INTERVAL; // request a full retarget win
33383338 }
33393339 }
33403340 }
3341+ NetworkCommand :: InitiateHandshake ( peer_id) => {
3342+ // Create and send a handshake request to the specified peer
3343+ let latest_epoch = db. get:: <Anchor >( "epoch" , b"latest" ) . ok( ) . flatten( ) . map( |a| a. num) ;
3344+ let handshake_req = HandshakeRequest {
3345+ version: 1 ,
3346+ peer_id: peer_id. to_string( ) ,
3347+ latest_epoch,
3348+ } ;
3349+ let _ = swarm. behaviour_mut( ) . handshake. send_request( & peer_id, handshake_req) ;
3350+ net_log!( "🤝 Initiated handshake with peer: {}" , peer_id) ;
3351+ }
33413352 _ => {
33423353 // For other commands, push to pending to be published via gossipsub
33433354 let mut allow_enqueue = true ;
@@ -3485,6 +3496,16 @@ impl Network {
34853496 self . connected_peers . lock ( ) . map ( |s| s. len ( ) ) . unwrap_or ( 0 )
34863497 }
34873498 pub async fn redial_bootstraps ( & self ) { let _ = self . command_tx . send ( NetworkCommand :: RedialBootstraps ) ; }
3499+
3500+ /// Initiate a handshake with a specific peer
3501+ pub async fn initiate_handshake ( & self , peer_id : PeerId ) {
3502+ let _ = self . command_tx . send ( NetworkCommand :: InitiateHandshake ( peer_id) ) ;
3503+ }
3504+
3505+ /// Send a handshake request directly to a peer
3506+ pub async fn send_handshake_request ( & self , peer_id : PeerId , request : HandshakeRequest ) {
3507+ let _ = self . handshake_tx . send ( ( peer_id, request) ) ;
3508+ }
34883509}
34893510
34903511#[ derive( Debug ) ]
0 commit comments