@@ -98,10 +98,10 @@ pub struct MdnsDiscovery {
9898enum Message {
9999 Discovery ( String , Peer ) ,
100100 Resolve (
101- EndpointId ,
101+ PublicKey ,
102102 mpsc:: Sender < Result < DiscoveryItem , DiscoveryError > > ,
103103 ) ,
104- Timeout ( EndpointId , usize ) ,
104+ Timeout ( PublicKey , usize ) ,
105105 Subscribe ( mpsc:: Sender < DiscoveryEvent > ) ,
106106}
107107
@@ -190,7 +190,7 @@ impl MdnsDiscoveryBuilder {
190190 /// # Panics
191191 /// This relies on [`tokio::runtime::Handle::current`] and will panic if called outside of the context of a tokio runtime.
192192 pub fn build ( self , endpoint_id : EndpointId ) -> Result < MdnsDiscovery , IntoDiscoveryError > {
193- MdnsDiscovery :: new ( endpoint_id, self . advertise , self . service_name )
193+ MdnsDiscovery :: new ( endpoint_id. expect_ed ( ) , self . advertise , self . service_name )
194194 }
195195}
196196
@@ -241,7 +241,7 @@ impl MdnsDiscovery {
241241 /// # Panics
242242 /// This relies on [`tokio::runtime::Handle::current`] and will panic if called outside of the context of a tokio runtime.
243243 fn new (
244- endpoint_id : EndpointId ,
244+ endpoint_id : PublicKey ,
245245 advertise : bool ,
246246 service_name : String ,
247247 ) -> Result < Self , IntoDiscoveryError > {
@@ -332,7 +332,7 @@ impl MdnsDiscovery {
332332 ) ;
333333 endpoint_addrs. remove ( & discovered_endpoint_id) ;
334334 subscribers. send ( DiscoveryEvent :: Expired {
335- endpoint_id : discovered_endpoint_id,
335+ endpoint_id : discovered_endpoint_id. into ( ) ,
336336 } ) ;
337337 continue ;
338338 }
@@ -352,7 +352,8 @@ impl MdnsDiscovery {
352352 ) ;
353353
354354 let mut resolved = false ;
355- let item = peer_to_discovery_item ( & peer_info, & discovered_endpoint_id) ;
355+ let item =
356+ peer_to_discovery_item ( & peer_info, & discovered_endpoint_id. into ( ) ) ;
356357 if let Some ( senders) = senders. get ( & discovered_endpoint_id) {
357358 trace ! ( ?item, senders = senders. len( ) , "sending DiscoveryItem" ) ;
358359 resolved = true ;
@@ -372,21 +373,21 @@ impl MdnsDiscovery {
372373 } ) ;
373374 }
374375 }
375- Message :: Resolve ( endpoint_id , sender) => {
376+ Message :: Resolve ( public_key , sender) => {
376377 let id = last_id + 1 ;
377378 last_id = id;
378- trace ! ( ?endpoint_id , "MdnsDiscovery Message::SendAddrs" ) ;
379- if let Some ( peer_info) = endpoint_addrs. get ( & endpoint_id ) {
380- let item = peer_to_discovery_item ( peer_info, & endpoint_id ) ;
379+ trace ! ( ?public_key , "MdnsDiscovery Message::SendAddrs" ) ;
380+ if let Some ( peer_info) = endpoint_addrs. get ( & public_key ) {
381+ let item = peer_to_discovery_item ( peer_info, & public_key ) ;
381382 debug ! ( ?item, "sending DiscoveryItem" ) ;
382383 sender. send ( Ok ( item) ) . await . ok ( ) ;
383384 }
384- if let Some ( senders_for_endpoint_id) = senders. get_mut ( & endpoint_id ) {
385+ if let Some ( senders_for_endpoint_id) = senders. get_mut ( & public_key ) {
385386 senders_for_endpoint_id. insert ( id, sender) ;
386387 } else {
387388 let mut senders_for_endpoint_id = HashMap :: new ( ) ;
388389 senders_for_endpoint_id. insert ( id, sender) ;
389- senders. insert ( endpoint_id , senders_for_endpoint_id) ;
390+ senders. insert ( public_key , senders_for_endpoint_id) ;
390391 }
391392 let timeout_sender = task_sender. clone ( ) ;
392393 timeouts. spawn ( async move {
@@ -398,12 +399,12 @@ impl MdnsDiscovery {
398399 . ok ( ) ;
399400 } ) ;
400401 }
401- Message :: Timeout ( endpoint_id , id) => {
402- trace ! ( ?endpoint_id , "MdnsDiscovery Message::Timeout" ) ;
403- if let Some ( senders_for_endpoint_id) = senders. get_mut ( & endpoint_id ) {
402+ Message :: Timeout ( public_key , id) => {
403+ trace ! ( ?public_key , "MdnsDiscovery Message::Timeout" ) ;
404+ if let Some ( senders_for_endpoint_id) = senders. get_mut ( & public_key ) {
404405 senders_for_endpoint_id. remove ( & id) ;
405406 if senders_for_endpoint_id. is_empty ( ) {
406- senders. remove ( & endpoint_id ) ;
407+ senders. remove ( & public_key ) ;
407408 }
408409 }
409410 }
@@ -488,7 +489,7 @@ impl MdnsDiscovery {
488489 }
489490}
490491
491- fn peer_to_discovery_item ( peer : & Peer , endpoint_id : & EndpointId ) -> DiscoveryItem {
492+ fn peer_to_discovery_item ( peer : & Peer , public_key : & PublicKey ) -> DiscoveryItem {
492493 let ip_addrs: BTreeSet < SocketAddr > = peer
493494 . addrs ( )
494495 . iter ( )
@@ -507,7 +508,7 @@ fn peer_to_discovery_item(peer: &Peer, endpoint_id: &EndpointId) -> DiscoveryIte
507508 } else {
508509 None
509510 } ;
510- let endpoint_info = EndpointInfo :: new ( * endpoint_id )
511+ let endpoint_info = EndpointInfo :: new ( * public_key )
511512 . with_ip_addrs ( ip_addrs)
512513 . with_user_data ( user_data) ;
513514 DiscoveryItem :: new ( endpoint_info, NAME , None )
@@ -520,11 +521,13 @@ impl Discovery for MdnsDiscovery {
520521 ) -> Option < BoxStream < Result < DiscoveryItem , DiscoveryError > > > {
521522 use futures_util:: FutureExt ;
522523
524+ let public_key = endpoint_id. as_ed ( ) ?;
525+
523526 let ( send, recv) = mpsc:: channel ( 20 ) ;
524527 let discovery_sender = self . sender . clone ( ) ;
525528 let stream = async move {
526529 discovery_sender
527- . send ( Message :: Resolve ( endpoint_id , send) )
530+ . send ( Message :: Resolve ( public_key , send) )
528531 . await
529532 . ok ( ) ;
530533 tokio_stream:: wrappers:: ReceiverStream :: new ( recv)
@@ -762,19 +765,19 @@ mod tests {
762765
763766 // Create a discovery service using the default
764767 // service name
765- let id_a = SecretKey :: generate ( & mut rng) . public ( ) ;
768+ let id_a = SecretKey :: generate ( & mut rng) . public ( ) . into ( ) ;
766769 let discovery_a = MdnsDiscovery :: builder ( ) . build ( id_a) ?;
767770
768771 // Create a discovery service using a custom
769772 // service name
770- let id_b = SecretKey :: generate ( & mut rng) . public ( ) ;
773+ let id_b = SecretKey :: generate ( & mut rng) . public ( ) . into ( ) ;
771774 let discovery_b = MdnsDiscovery :: builder ( )
772775 . service_name ( "different.name" )
773776 . build ( id_b) ?;
774777
775778 // Create a discovery service using the same
776779 // custom service name
777- let id_c = SecretKey :: generate ( & mut rng) . public ( ) ;
780+ let id_c = SecretKey :: generate ( & mut rng) . public ( ) . into ( ) ;
778781 let discovery_c = MdnsDiscovery :: builder ( )
779782 . service_name ( "different.name" )
780783 . build ( id_c) ?;
@@ -818,8 +821,8 @@ mod tests {
818821 fn make_discoverer < R : CryptoRng + ?Sized > (
819822 rng : & mut R ,
820823 advertise : bool ,
821- ) -> Result < ( PublicKey , MdnsDiscovery ) > {
822- let endpoint_id = SecretKey :: generate ( rng) . public ( ) ;
824+ ) -> Result < ( EndpointId , MdnsDiscovery ) > {
825+ let endpoint_id = SecretKey :: generate ( rng) . public ( ) . into ( ) ;
823826 Ok ( (
824827 endpoint_id,
825828 MdnsDiscovery :: builder ( )
0 commit comments