You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, we're specifically configuring the `Endpoint`'s builder to include "number 0 discovery".
62
-
This makes it connect to DNS servers that [number 0](https://n0.computer) runs to find which relay to talk to for specific `EndpointId`s.
63
-
It's a great default!
64
-
65
-
The iroh toolkit is built to be modular and flexible, so if you want to use a different discovery mechanism, you can!
66
-
67
-
If all of this is too much magic for your taste, it's possible for the endpoint to work entirely without any discovery services.
68
-
In that case, you'll need to make sure you're not only dialing by `EndpointId`, but also help the `Endpoint` out with giving it the whole [`EndpointAddr`](https://docs.rs/iroh/latest/iroh/struct.EndpointAddr.html) when connecting.
69
-
</Note>
70
-
71
61
72
-
## Protocols
62
+
###Protocols
73
63
74
-
Now that we have an `Endpoint`, we can start using protocols over it. A protocol
75
-
is a specific way of exchanging messages over a connection.
64
+
Now that we have an `Endpoint`, we can start using protocols over it.
76
65
77
-
Similar to how HTTP is a protocol for exchanging web pages, iroh protocols define
78
-
ways to exchange data over iroh connections.
66
+
A **protocol** defines how two endpoints exchange messages. Just like HTTP
67
+
defines how web browsers talk to servers, iroh protocols define how peers
68
+
communicate over iroh connections.
79
69
80
-
Each endpoint can support multiple protocols, identified by a string called
81
-
an ALPN string. This just tells the program which handler to use for
82
-
processing data as it arrives.
70
+
Each protocol is identified by an **ALPN** (Application-Layer Protocol
71
+
Negotiation) string. When a connection arrives, the router uses this string to
72
+
decide which handler processes the data.
83
73
84
-
When building applications with iroh, you can either build your own custom
85
-
protocol handlers, or use existing ones.
74
+
You can build custom protocol handlers or use existing ones like `iroh-ping`.
86
75
87
76
<Note>
88
77
Learn more about writing your own protocol on the [protocol documentation page](/protocols/writing-a-protocol).
@@ -103,16 +92,16 @@ use iroh_ping::Ping;
103
92
asyncfnmain() ->anyhow::Result<()> {
104
93
// Create an endpoint, it allows creating and accepting
105
94
// connections in the iroh p2p world
106
-
letrecv_ep=Endpoint::builder().bind().await?;
95
+
letendpoint=Endpoint::builder().bind().await?;
107
96
108
97
// bring the endpoint online before accepting connections
109
-
recv_ep.online().await;
98
+
endpoint.online().await;
110
99
111
100
// Then we initialize a struct that can accept ping requests over iroh connections
112
101
letping=Ping::new();
113
102
114
103
// receiving ping requests
115
-
letrecv_router=Router::builder(recv_ep)
104
+
letrecv_router=Router::builder(endpoint)
116
105
.accept(iroh_ping::ALPN, ping)
117
106
.spawn();
118
107
@@ -139,13 +128,13 @@ use iroh_ping::Ping;
139
128
asyncfnmain() ->Result<()> {
140
129
// Create an endpoint, it allows creating and accepting
141
130
// connections in the iroh p2p world
142
-
letrecv_ep=Endpoint::builder().bind().await?;
131
+
letendpoint=Endpoint::builder().bind().await?;
143
132
144
133
// Then we initialize a struct that can accept ping requests over iroh connections
For more details on tickets, see [Discovery](/concepts/discovery).
193
+
For more details on how it works, see[Tickets](/concepts/tickets) and[Discovery](/concepts/discovery).
205
194
206
195
### Receiver
207
196
@@ -217,15 +206,15 @@ use iroh_tickets::{Ticket, endpoint::EndpointTicket};
217
206
usestd::env;
218
207
219
208
asyncfnrun_receiver() ->Result<()> {
220
-
letrecv_ep=Endpoint::builder().bind().await?;
221
-
recv_ep.online().await;
209
+
letendpoint=Endpoint::builder().bind().await?;
210
+
endpoint.online().await;
222
211
223
212
letping=Ping::new();
224
213
225
-
letticket=EndpointTicket::new(recv_ep.addr());
214
+
letticket=EndpointTicket::new(endpoint.addr());
226
215
println!("{ticket}");
227
216
228
-
Router::builder(recv_ep)
217
+
Router::builder(endpoint)
229
218
.accept(iroh_ping::ALPN, ping)
230
219
.spawn();
231
220
@@ -296,13 +285,14 @@ cargo run -- sender <TICKET>
296
285
297
286
You should see the round-trip time printed by the sender.
298
287
299
-
## That's it!
288
+
## More Tutorials
300
289
301
290
You've now successfully built a small tool for sending messages over a peer to peer network! 🎉
302
291
303
-
The full example with the very latest version of iroh and iroh-ping can be [viewed on github](https://github.com/n0-computer/iroh-blobs/blob/main/examples/transfer.rs).
292
+
The full example with the very latest version of iroh and iroh-ping can be
293
+
[viewed on github](https://github.com/n0-computer/iroh-ping).
0 commit comments