@@ -67,8 +67,8 @@ use libp2p::{
6767 mdns:: { Mdns , MdnsConfig , MdnsEvent } ,
6868 multiaddr:: Protocol ,
6969 swarm:: {
70- protocols_handler :: multi:: IntoMultiHandler , DialError , IntoProtocolsHandler ,
71- NetworkBehaviour , NetworkBehaviourAction , PollParameters , ProtocolsHandler ,
70+ handler :: multi:: IntoMultiHandler , ConnectionHandler , DialError , IntoConnectionHandler ,
71+ NetworkBehaviour , NetworkBehaviourAction , PollParameters ,
7272 } ,
7373} ;
7474use log:: { debug, error, info, trace, warn} ;
@@ -355,9 +355,9 @@ impl DiscoveryBehaviour {
355355 /// Start fetching a record from the DHT.
356356 ///
357357 /// A corresponding `ValueFound` or `ValueNotFound` event will later be generated.
358- pub fn get_value ( & mut self , key : & record:: Key ) {
358+ pub fn get_value ( & mut self , key : record:: Key ) {
359359 for k in self . kademlias . values_mut ( ) {
360- k. get_record ( key, Quorum :: One ) ;
360+ k. get_record ( key. clone ( ) , Quorum :: One ) ;
361361 }
362362 }
363363
@@ -433,7 +433,7 @@ impl DiscoveryBehaviour {
433433 & mut self ,
434434 pid : ProtocolId ,
435435 handler : KademliaHandlerProto < QueryId > ,
436- ) -> <DiscoveryBehaviour as NetworkBehaviour >:: ProtocolsHandler {
436+ ) -> <DiscoveryBehaviour as NetworkBehaviour >:: ConnectionHandler {
437437 let mut handlers: HashMap < _ , _ > = self
438438 . kademlias
439439 . iter_mut ( )
@@ -498,10 +498,10 @@ pub enum DiscoveryOut {
498498}
499499
500500impl NetworkBehaviour for DiscoveryBehaviour {
501- type ProtocolsHandler = IntoMultiHandler < ProtocolId , KademliaHandlerProto < QueryId > > ;
501+ type ConnectionHandler = IntoMultiHandler < ProtocolId , KademliaHandlerProto < QueryId > > ;
502502 type OutEvent = DiscoveryOut ;
503503
504- fn new_handler ( & mut self ) -> Self :: ProtocolsHandler {
504+ fn new_handler ( & mut self ) -> Self :: ConnectionHandler {
505505 let iter = self
506506 . kademlias
507507 . iter_mut ( )
@@ -568,6 +568,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
568568 conn : & ConnectionId ,
569569 endpoint : & ConnectedPoint ,
570570 failed_addresses : Option < & Vec < Multiaddr > > ,
571+ other_established : usize ,
571572 ) {
572573 self . num_connections += 1 ;
573574 for k in self . kademlias . values_mut ( ) {
@@ -577,37 +578,37 @@ impl NetworkBehaviour for DiscoveryBehaviour {
577578 conn,
578579 endpoint,
579580 failed_addresses,
581+ other_established,
580582 )
581583 }
582584 }
583585
584- fn inject_connected ( & mut self , peer_id : & PeerId ) {
585- for k in self . kademlias . values_mut ( ) {
586- NetworkBehaviour :: inject_connected ( k, peer_id)
587- }
588- }
589-
590586 fn inject_connection_closed (
591587 & mut self ,
592- _peer_id : & PeerId ,
593- _conn : & ConnectionId ,
594- _endpoint : & ConnectedPoint ,
595- _handler : <Self :: ProtocolsHandler as IntoProtocolsHandler >:: Handler ,
588+ peer_id : & PeerId ,
589+ conn : & ConnectionId ,
590+ endpoint : & ConnectedPoint ,
591+ handler : <Self :: ConnectionHandler as IntoConnectionHandler >:: Handler ,
592+ remaining_established : usize ,
596593 ) {
597594 self . num_connections -= 1 ;
598- // NetworkBehaviour::inject_connection_closed on Kademlia<MemoryStore> does nothing.
599- }
600-
601- fn inject_disconnected ( & mut self , peer_id : & PeerId ) {
602- for k in self . kademlias . values_mut ( ) {
603- NetworkBehaviour :: inject_disconnected ( k, peer_id)
595+ for ( pid, event) in handler. into_iter ( ) {
596+ if let Some ( kad) = self . kademlias . get_mut ( & pid) {
597+ kad. inject_connection_closed ( peer_id, conn, endpoint, event, remaining_established)
598+ } else {
599+ error ! (
600+ target: "sub-libp2p" ,
601+ "inject_connection_closed: no kademlia instance registered for protocol {:?}" ,
602+ pid,
603+ )
604+ }
604605 }
605606 }
606607
607608 fn inject_dial_failure (
608609 & mut self ,
609610 peer_id : Option < PeerId > ,
610- _: Self :: ProtocolsHandler ,
611+ _: Self :: ConnectionHandler ,
611612 error : & DialError ,
612613 ) {
613614 if let Some ( peer_id) = peer_id {
@@ -630,7 +631,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
630631 & mut self ,
631632 peer_id : PeerId ,
632633 connection : ConnectionId ,
633- ( pid, event) : <<Self :: ProtocolsHandler as IntoProtocolsHandler >:: Handler as ProtocolsHandler >:: OutEvent ,
634+ ( pid, event) : <<Self :: ConnectionHandler as IntoConnectionHandler >:: Handler as ConnectionHandler >:: OutEvent ,
634635 ) {
635636 if let Some ( kad) = self . kademlias . get_mut ( & pid) {
636637 return kad. inject_event ( peer_id, connection, event)
@@ -689,7 +690,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
689690 }
690691 }
691692
692- fn inject_listen_failure ( & mut self , _: & Multiaddr , _: & Multiaddr , _: Self :: ProtocolsHandler ) {
693+ fn inject_listen_failure ( & mut self , _: & Multiaddr , _: & Multiaddr , _: Self :: ConnectionHandler ) {
693694 // NetworkBehaviour::inject_listen_failure on Kademlia<MemoryStore> does nothing.
694695 }
695696
@@ -709,7 +710,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
709710 & mut self ,
710711 cx : & mut Context ,
711712 params : & mut impl PollParameters ,
712- ) -> Poll < NetworkBehaviourAction < Self :: OutEvent , Self :: ProtocolsHandler > > {
713+ ) -> Poll < NetworkBehaviourAction < Self :: OutEvent , Self :: ConnectionHandler > > {
713714 // Immediately process the content of `discovered`.
714715 if let Some ( ev) = self . pending_events . pop_front ( ) {
715716 return Poll :: Ready ( NetworkBehaviourAction :: GenerateEvent ( ev) )
@@ -770,12 +771,8 @@ impl NetworkBehaviour for DiscoveryBehaviour {
770771 let ev = DiscoveryOut :: Discovered ( peer) ;
771772 return Poll :: Ready ( NetworkBehaviourAction :: GenerateEvent ( ev) )
772773 } ,
773- KademliaEvent :: InboundPutRecordRequest { .. } |
774- KademliaEvent :: InboundAddProviderRequest { .. } => {
775- debug_assert ! ( false , "We don't use kad filtering at the moment" ) ;
776- } ,
777774 KademliaEvent :: PendingRoutablePeer { .. } |
778- KademliaEvent :: InboundRequestServed { .. } => {
775+ KademliaEvent :: InboundRequest { .. } => {
779776 // We are not interested in this event at the moment.
780777 } ,
781778 KademliaEvent :: OutboundQueryCompleted {
@@ -890,19 +887,10 @@ impl NetworkBehaviour for DiscoveryBehaviour {
890887 warn ! ( target: "sub-libp2p" , "Libp2p => Unhandled Kademlia event: {:?}" , e)
891888 } ,
892889 } ,
893- NetworkBehaviourAction :: DialAddress { address, handler } => {
894- let pid = pid. clone ( ) ;
895- let handler = self . new_handler_with_replacement ( pid, handler) ;
896- return Poll :: Ready ( NetworkBehaviourAction :: DialAddress { address, handler } )
897- } ,
898- NetworkBehaviourAction :: DialPeer { peer_id, condition, handler } => {
890+ NetworkBehaviourAction :: Dial { opts, handler } => {
899891 let pid = pid. clone ( ) ;
900892 let handler = self . new_handler_with_replacement ( pid, handler) ;
901- return Poll :: Ready ( NetworkBehaviourAction :: DialPeer {
902- peer_id,
903- condition,
904- handler,
905- } )
893+ return Poll :: Ready ( NetworkBehaviourAction :: Dial { opts, handler } )
906894 } ,
907895 NetworkBehaviourAction :: NotifyHandler { peer_id, handler, event } =>
908896 return Poll :: Ready ( NetworkBehaviourAction :: NotifyHandler {
@@ -941,10 +929,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
941929 } ,
942930 MdnsEvent :: Expired ( _) => { } ,
943931 } ,
944- NetworkBehaviourAction :: DialAddress { .. } => {
945- unreachable ! ( "mDNS never dials!" ) ;
946- } ,
947- NetworkBehaviourAction :: DialPeer { .. } => {
932+ NetworkBehaviourAction :: Dial { .. } => {
948933 unreachable ! ( "mDNS never dials!" ) ;
949934 } ,
950935 NetworkBehaviourAction :: NotifyHandler { event, .. } => match event { } , /* `event` is an enum with no variant */
@@ -995,7 +980,7 @@ impl MdnsWrapper {
995980 & mut self ,
996981 cx : & mut Context < ' _ > ,
997982 params : & mut impl PollParameters ,
998- ) -> Poll < NetworkBehaviourAction < MdnsEvent , <Mdns as NetworkBehaviour >:: ProtocolsHandler > > {
983+ ) -> Poll < NetworkBehaviourAction < MdnsEvent , <Mdns as NetworkBehaviour >:: ConnectionHandler > > {
999984 loop {
1000985 match self {
1001986 Self :: Instantiating ( fut) =>
0 commit comments