@@ -64,10 +64,19 @@ use super::{Discovery, DiscoveryError, DiscoveryItem, NodeData, NodeInfo};
6464/// ```
6565///
6666/// [`NodeTicket`]: https://docs.rs/iroh-base/latest/iroh_base/ticket/struct.NodeTicket
67- #[ derive( Debug , Default , Clone ) ]
68- #[ repr( transparent) ]
67+ #[ derive( Debug , Clone ) ]
6968pub struct StaticProvider {
7069 nodes : Arc < RwLock < BTreeMap < NodeId , StoredNodeInfo > > > ,
70+ provenance : & ' static str ,
71+ }
72+
73+ impl Default for StaticProvider {
74+ fn default ( ) -> Self {
75+ Self {
76+ nodes : Default :: default ( ) ,
77+ provenance : Self :: PROVENANCE ,
78+ }
79+ }
7180}
7281
7382#[ derive( Debug ) ]
@@ -90,6 +99,20 @@ impl StaticProvider {
9099 Self :: default ( )
91100 }
92101
102+ /// Creates a new static discovery instance with the provided `provenance`.
103+ ///
104+ /// The provenance is part of [`DiscoveryItem`]s returned from [`Self::resolve`].
105+ /// It is mostly used for debugging information and allows understanding the origin of
106+ /// addressing information used by an iroh [`Endpoint`].
107+ ///
108+ /// [`Endpoint`]: crate::Endpoint
109+ pub fn with_provenance ( provenance : & ' static str ) -> Self {
110+ Self {
111+ nodes : Default :: default ( ) ,
112+ provenance,
113+ }
114+ }
115+
93116 /// Creates a static discovery instance from node addresses.
94117 ///
95118 /// # Examples
@@ -196,7 +219,7 @@ impl Discovery for StaticProvider {
196219 . as_micros ( ) as u64 ;
197220 let item = DiscoveryItem :: new (
198221 NodeInfo :: from_parts ( node_id, node_info. data . clone ( ) ) ,
199- Self :: PROVENANCE ,
222+ self . provenance ,
200223 Some ( last_updated) ,
201224 ) ;
202225 Some ( stream:: iter ( Some ( Ok ( item) ) ) . boxed ( ) )
@@ -248,4 +271,22 @@ mod tests {
248271
249272 Ok ( ( ) )
250273 }
274+
275+ #[ tokio:: test]
276+ async fn test_provenance ( ) -> Result {
277+ let discovery = StaticProvider :: with_provenance ( "foo" ) ;
278+ let key = SecretKey :: from_bytes ( & [ 0u8 ; 32 ] ) ;
279+ let addr = NodeAddr {
280+ node_id : key. public ( ) ,
281+ relay_url : Some ( "https://example.com" . parse ( ) ?) ,
282+ direct_addresses : Default :: default ( ) ,
283+ } ;
284+ discovery. add_node_info ( addr) ;
285+ let mut stream = discovery. resolve ( key. public ( ) ) . unwrap ( ) ;
286+ let item = stream. next ( ) . await . unwrap ( ) ?;
287+ assert_eq ! ( item. provenance( ) , "foo" ) ;
288+ assert_eq ! ( item. relay_url( ) , Some ( & ( "https://example.com" . parse( ) ?) ) ) ;
289+
290+ Ok ( ( ) )
291+ }
251292}
0 commit comments