1717//!
1818//! cargo run --example custom-protocol -- listen "hello-world" "foo-bar" "hello-moon"
1919//!
20- //! This spawns an iroh nodes with three blobs. It will print the node's node id.
20+ //! This spawns an iroh node with three blobs. It will print the node's endpoint id.
2121//!
2222//! In another terminal, run
2323//!
24- //! cargo run --example custom-protocol -- query <node -id> hello
24+ //! cargo run --example custom-protocol -- query <endpoint -id> hello
2525//!
26- //! Replace <node -id> with the node id from above. This will connect to the listening node with our
26+ //! Replace <endpoint -id> with the endpoint id from above. This will connect to the listening node with our
2727//! custom protocol and query for the string `hello`. The listening node will return a list of
2828//! blob hashes that contain `hello`. We will then download all these blobs with iroh-blobs,
2929//! and then print a list of the hashes with their content.
@@ -46,7 +46,7 @@ use iroh::{
4646 discovery:: pkarr:: PkarrResolver ,
4747 endpoint:: Connection ,
4848 protocol:: { AcceptError , ProtocolHandler , Router } ,
49- Endpoint , NodeId ,
49+ Endpoint , EndpointId ,
5050} ;
5151use iroh_blobs:: { api:: Store , store:: mem:: MemStore , BlobsProtocol , Hash } ;
5252mod common;
@@ -67,8 +67,8 @@ pub enum Command {
6767 } ,
6868 /// Query a remote node for data and print the results.
6969 Query {
70- /// The node id of the node we want to query.
71- node_id : NodeId ,
70+ /// The endpoint id of the node we want to query.
71+ endpoint_id : EndpointId ,
7272 /// The text we want to match.
7373 query : String ,
7474 } ,
@@ -81,17 +81,13 @@ pub enum Command {
8181const ALPN : & [ u8 ] = b"iroh-example/text-search/0" ;
8282
8383async fn listen ( text : Vec < String > ) -> Result < ( ) > {
84- // allow the user to provide a secret so we can have a stable node id.
84+ // allow the user to provide a secret so we can have a stable endpoint id.
8585 // This is only needed for the listen side.
8686 let secret_key = get_or_generate_secret_key ( ) ?;
8787 // Use an in-memory store for this example. You would use a persistent store in production code.
8888 let store = MemStore :: new ( ) ;
8989 // Create an endpoint with the secret key and discovery publishing to the n0 dns server enabled.
90- let endpoint = Endpoint :: builder ( )
91- . secret_key ( secret_key)
92- . discovery_n0 ( )
93- . bind ( )
94- . await ?;
90+ let endpoint = Endpoint :: builder ( ) . secret_key ( secret_key) . bind ( ) . await ?;
9591 // Build our custom protocol handler. The `builder` exposes access to various subsystems in the
9692 // iroh node. In our case, we need a blobs client and the endpoint.
9793 let proto = BlobSearch :: new ( & store) ;
@@ -108,30 +104,30 @@ async fn listen(text: Vec<String>) -> Result<()> {
108104 . accept ( iroh_blobs:: ALPN , blobs. clone ( ) )
109105 . spawn ( ) ;
110106
111- // Print our node id, so clients know how to connect to us.
112- let node_id = node. endpoint ( ) . node_id ( ) ;
113- println ! ( "our node id: {node_id}" ) ;
107+ // Print our endpoint id, so clients know how to connect to us.
108+ let node_id = node. endpoint ( ) . id ( ) ;
109+ println ! ( "our endpoint id: {node_id}" ) ;
114110
115111 // Wait for Ctrl-C to be pressed.
116112 tokio:: signal:: ctrl_c ( ) . await ?;
117113 node. shutdown ( ) . await ?;
118114 Ok ( ( ) )
119115}
120116
121- async fn query ( node_id : NodeId , query : String ) -> Result < ( ) > {
117+ async fn query ( endpoint_id : EndpointId , query : String ) -> Result < ( ) > {
122118 // Build a in-memory node. For production code, you'd want a persistent node instead usually.
123119 let store = MemStore :: new ( ) ;
124120 // Create an endpoint with a random secret key and no discovery publishing.
125121 // For a client we just need discovery resolution via the n0 dns server, which
126122 // the PkarrResolver provides.
127- let endpoint = Endpoint :: builder ( )
128- . add_discovery ( PkarrResolver :: n0_dns ( ) )
123+ let endpoint = Endpoint :: empty_builder ( iroh :: RelayMode :: Default )
124+ . discovery ( PkarrResolver :: n0_dns ( ) )
129125 . bind ( )
130126 . await ?;
131127 // Query the remote node.
132128 // This will send the query over our custom protocol, read hashes on the reply stream,
133129 // and download each hash over iroh-blobs.
134- let hashes = query_remote ( & endpoint, & store, node_id , & query) . await ?;
130+ let hashes = query_remote ( & endpoint, & store, endpoint_id , & query) . await ?;
135131
136132 // Print out our query results.
137133 for hash in hashes {
@@ -157,10 +153,10 @@ async fn main() -> Result<()> {
157153 listen ( text) . await ?;
158154 }
159155 Command :: Query {
160- node_id ,
156+ endpoint_id ,
161157 query : query_text,
162158 } => {
163- query ( node_id , query_text) . await ?;
159+ query ( endpoint_id , query_text) . await ?;
164160 }
165161 }
166162
@@ -180,8 +176,8 @@ impl ProtocolHandler for BlobSearch {
180176 /// the connection lasts.
181177 async fn accept ( & self , connection : Connection ) -> std:: result:: Result < ( ) , AcceptError > {
182178 let this = self . clone ( ) ;
183- // We can get the remote's node id from the connection.
184- let node_id = connection. remote_node_id ( ) ?;
179+ // We can get the remote's endpoint id from the connection.
180+ let node_id = connection. remote_id ( ) ?;
185181 println ! ( "accepted connection from {node_id}" ) ;
186182
187183 // Our protocol is a simple request-response protocol, so we expect the
@@ -269,14 +265,14 @@ impl BlobSearch {
269265pub async fn query_remote (
270266 endpoint : & Endpoint ,
271267 store : & Store ,
272- node_id : NodeId ,
268+ endpoint_id : EndpointId ,
273269 query : & str ,
274270) -> Result < Vec < Hash > > {
275271 // Establish a connection to our node.
276- // We use the default node discovery in iroh, so we can connect by node id without
272+ // We use the default node discovery in iroh, so we can connect by endpoint id without
277273 // providing further information.
278- let conn = endpoint. connect ( node_id , ALPN ) . await ?;
279- let blobs_conn = endpoint. connect ( node_id , iroh_blobs:: ALPN ) . await ?;
274+ let conn = endpoint. connect ( endpoint_id , ALPN ) . await ?;
275+ let blobs_conn = endpoint. connect ( endpoint_id , iroh_blobs:: ALPN ) . await ?;
280276
281277 // Open a bi-directional in our connection.
282278 let ( mut send, mut recv) = conn. open_bi ( ) . await ?;
0 commit comments