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
Copy file name to clipboardExpand all lines: concepts/discovery.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ Discovery is the glue that connects an [Endpoint](/concepts/endpoints#endpoint-i
11
11
12
12
Endpoint discovery is an automated system for an [Endpoint](/concepts/endpoints) to retrieve addressing information. Each iroh endpoint will automatically publish their own addressing information with configured discovery services. Usually this means publishing which [Home Relay](/concepts/relay#home-relay) an endpoint is findable at, but they could also publish their direct addresses.
13
13
14
+
14
15
## Discovery Services
15
16
16
17
There are four different implementations of the discovery service in iroh. iroh
Copy file name to clipboardExpand all lines: concepts/endpoints.mdx
+60-10Lines changed: 60 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,18 +13,9 @@ endpoints, while still remaining independent connections. This will result in
13
13
more optimal network behaviour.
14
14
15
15
16
-
## Endpoint Identifiers
17
-
18
-
Each endpoint in iroh has a unique identifier (`EndpointID`) created as a
19
-
cryptographic key. This can be used to globally identify an endpoint. Because
20
-
`EndpointIDs` are cryptographic keys, they are also the mechanism by which all
21
-
traffic is always encrypted for a specific endpoint only.
22
-
23
-
See the [EndpointID](https://docs.rs/iroh/latest/iroh/type.EndpointId.html) documentation for more information.
24
-
25
16
## Connections
26
17
27
-
Because we're in a peer-2-peer context, either endpoint might be operating as
18
+
Because we're in a peer-to-peer context, either endpoint might be operating as
28
19
the "server", so we use `connect` and `accept` to distinguish between the two.
29
20
The `connect` method is used to create a new connection to a remote endpoint,
30
21
while `accept` is used to accept incoming connections from a remote endpoint.
@@ -38,6 +29,65 @@ A [Relay](/concepts/relays) server can be used to make the connections reliable.
38
29
Due to the light-weight properties of QUIC streams a stream can only be accepted once the initiating peer has sent some data on it.
39
30
</Note>
40
31
32
+
33
+
## Endpoint Identifiers
34
+
35
+
Each endpoint in iroh has a unique identifier (`EndpointID`) created as a
36
+
cryptographic key. This can be used to globally identify an endpoint. Because
37
+
`EndpointIDs` are cryptographic keys, they are also the mechanism by which all
38
+
traffic is always encrypted for a specific endpoint only.
39
+
40
+
See the [EndpointID](https://docs.rs/iroh/latest/iroh/type.EndpointId.html) documentation for more information.
41
+
42
+
# Endpoint Addresses
43
+
44
+
Endpoint Addresses or [`EndpointAddrs`](https://docs.rs/iroh/latest/iroh/struct.EndpointAddr.html) are a common struct you'll interact when working with iroh to tell iroh what & where to dial. In rust they look like this:
45
+
46
+
```rust
47
+
pubstructAddr {
48
+
pubid:PublicKey,
49
+
pubaddrs:BTreeSet<TransportAddr>,
50
+
}
51
+
```
52
+
53
+
You'll interact with `EndpointAddr`s a fair amount when working with iroh. It's also quite normal to construct addresses manually from, say, endpoint identifiers stored in your application database.
54
+
55
+
When we call [`connect`](https://docs.rs/iroh/latest/iroh/endpoint/struct.Endpoint.html#method.connect) on an [Endpoint](https://www.iroh.computer/docs/concepts/endpoint), we need to pass either a `EndpointAddr`, or something that can turn into a `EndpointAddr`. In iroh `Endpoint`s will have different fields populated depending on where they came from, and the discovery services you've configured your endpoint with.
56
+
57
+
### Interaction with discovery
58
+
59
+
From the above struct, the only _required_ field is the `id`. And because of
60
+
this, there's an implementation of `From` that can turn `EndpointIDs` directly
61
+
into EndpointAddrs. _but this will only work if you have a discovery service
62
+
that can resolve EndpointIDs enabled_. Thankfully, we enable discovery by
63
+
default:
64
+
65
+
```rust
66
+
useiroh::Endpoint;
67
+
68
+
// enables dialing by EndpointAddrs that only have EndpointIDs by default:
69
+
letep=Endpoint::builder()
70
+
.bind()
71
+
.await?;
72
+
```
73
+
74
+
This is why we actively encourage configuring a discovery service, and DNS is the most common one we recommend. Because we're in p2p land dialing details & even home relays for an endpoint can change on very short notice, making this data go stale quickly. Endpoint Identifiers are a practical source of stability that counteracts this.
75
+
76
+
### When to provide full details
77
+
78
+
If you have full dialing details, it's well worth providing them as part of a
79
+
`EndpointAddr` passed to `connect`. Iroh can use this to skip the network
80
+
roundtrip required to either do initial address discovery, or update cached
81
+
addresses. So if you have a source of up to date home relay & dialing info,
82
+
provide it!
83
+
84
+
### Don't store relay_url & direct_addresses values
85
+
86
+
If you're persisting the contents of `EndpointAddrs` in your app, it's probably
87
+
not worth keeping the `relay_url` and `direct_address` fields, unless you _know_
88
+
these details are unlikely to change. Providing stale details to the endpoint
89
+
can slow down connection construction.
90
+
41
91
## Building on Endpoints
42
92
43
93
Endpoints are a low-level primitive that iroh exposes on purpose. For some
Tickets are a way to share dialing information between iroh endpoints. They're a
2
+
single token that contains everything needed to connect to another endpoint or gossip topic.
3
+
4
+
You can use the default iroh endpoint tickets or build your own tickets using the `iroh-tickets` crate.
5
+
6
+
<Note>
7
+
Have a ticket? Try pasting it into the [iroh ticket explorer](https://ticket.iroh.computer) to break it down! Here's an [example](https://ticket.iroh.computer?ticket=docaaacarwhmusoqf362j3jpzrehzkw3bqamcp2mmbhn3fmag3mzzfjp4beahj2v7aezhojvfqi5wltr4vxymgzqnctryyup327ct7iy4s5noxy6aaa)
8
+
</Note>
9
+
10
+
Tickets are a single serialized token containing everything needed to kick off an interaction with another endpoint running iroh. Here's an example of one:
They're also very powerful. Tickets combine a piece of info with _dialing information for the endpoint to fetch from_. We've seen numerous content-addressed systems force users to copy and paste long hashes around, and we figure if you're going to have to copy and paste something, it might as well contain both the hash and a hint about where to find the data. Tickets also work very well in QR codes!
19
+
20
+
In practice this is a _massive_ speed pickup for iroh. When you're given a ticket, you have everything you need to construct a request
21
+
22
+
## Kinds of Tickets
23
+
24
+
Currently, there are three kinds of tickets:
25
+
26
+
| Type | Description | Contents |
27
+
| --- | --- | --- |
28
+
|`endpoint`| A token for connecting to an iroh endpoint |`Endpoint Address`|
29
+
|`blob`| A token for fetching a [blob](/docs/layers/blobs) or [collection](/docs/layers/blobs#collections)|`Hash`, `HashOrCollection`, `Endpoint Address`|
30
+
|`document`| A read/write access token to a [document](/proto/iroh-docs), plus an endpoint address |`DocID`, `Read/Write Capability`, `[Endpoint Address]`|
31
+
32
+
Tickets always start with an ascii string that describes the type of ticket (eg: `blob`), followed by a base32-lowercase-encoded payload. The payload is [postcard-encoded data](https://postcard.jamesmunns.com/wire-format.html) that contains the information needed to use the ticket. We chose postcard because it's extremely succinct.
33
+
34
+
## Tickets are sensitive
35
+
36
+
When you create a ticket, it embeds the IP addresses of the machines you're using to create the ticket. This means that if you share a ticket with someone, they can use it to connect to your machine. This is a feature, not a bug. It's a way to bootstrap connections between peers without needing a central server. It also means you should be careful about sharing tickets with people you don't want to have your IP address.
37
+
38
+
It's worth pointing out this setup is considerably better than full peer-2-peer systems, which _broadcast_ your IP to peers. Instead in iroh, we use tickets to form a "cozy network" between peers you explicitly want to connect with. It's possible to go "full p2p" & configure your app to broadcast dialing details, but we think tickets represent a better middle-ground default.
39
+
40
+
## Document Tickets are _secrets_
41
+
42
+
When you create a document ticket, you're creating a secret that allows someone to read or write to a document. This means that you should be careful about sharing document tickets with people you don't trust. What's more, someone who has a document ticket can use it to create new tickets for the same document. This means that if you share a document ticket with someone, they can use it to create new tickets for the same document, and share those tickets with others.
43
+
44
+
## Tickets in Apps
45
+
Using tickets in your app comes down to what you're trying to accomplish. For short-lived sessions where both devices are online at the same time, tickets are an incredibly powerful way to bootstrap connections, and require no additional servers for coordination.
46
+
47
+
If you have any means of automating (like, a central database or server to bootstrap from) we recommend you _do not_ use tickets in your app, and instead program around the idea that you can _dial by EndpointID_. Tickets can contain information that can go stale quickly. instead focus on caching `endpointIDs`, and letting iroh transparently resolve dialing details at runtime.
Copy file name to clipboardExpand all lines: examples/chat.mdx
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,7 @@
1
-
---
2
-
title: "Building a P2P Chat Application with Iroh"
3
-
---
4
1
import { YouTube } from'@/components/youtube'
5
2
3
+
## Building a P2P Chat Application with Iroh
4
+
6
5
<iframewidth="560"height="315"src="https://www.youtube.com/embed/ogN_mBkWu7o?si=Y-GqkmGBRZfRhclc"title="YouTube video player"frameborder="0"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"referrerpolicy="strict-origin-when-cross-origin"allowfullscreen></iframe>
7
6
8
7
This tutorial demonstrates how to build a peer-to-peer chat application from scratch using Rust and the Iroh library. While this implementation is simplified, it illustrates core concepts of P2P networking and the Iroh gossip protocol.
With these two lines, we've initialized iroh-blobs and gave it access to our `Endpoint`.
123
126
127
+
### Ping: Send
124
128
At this point what we want to do depends on whether we want to accept incoming iroh connections from the network or create outbound iroh connections to other endpoints.
125
129
Which one we want to do depends on if the executable was called with `send` as
126
130
an argument or `receive`, so let's parse these two options out from the CLI
@@ -171,10 +175,126 @@ cargo run
171
175
I Compiling ping-quickstart v0.1.0 (/Users/raemckelvey/dev/ping-quickstart)
172
176
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.62s
173
177
Running `target/debug/ping-quickstart`
174
-
accepted connection from 32c5772d26bff78923ef6e85f665f23b96ee06655832649910a560af59c84e22
175
178
ping took: 1.189375ms to complete
176
179
```
177
180
181
+
## Part 2: Separate Sender and Receiver
182
+
183
+
Round-trip time isn't very useful when both roles live in the same binary
184
+
instance. Let's split the app into two subcommands so you can run the receiver
185
+
on one machine and the sender on another.
186
+
187
+
### What is a ticket?
188
+
189
+
When an iroh endpoint comes online, it has an address containing its node ID,
190
+
relay URL, and direct addresses. An `EndpointTicket` wraps this address into a
191
+
serializable ticket—a short string you can copy and paste. Share this ticket
192
+
with senders so they can dial the receiver without manually exchanging
193
+
networking details.
194
+
195
+
A ticket is made from an endpoint's address like this:
0 commit comments