Skip to content

Commit b24ab8c

Browse files
committed
docs: Add docs on rest of the subsystems
1 parent 00ef7a3 commit b24ab8c

File tree

1 file changed

+205
-4
lines changed

1 file changed

+205
-4
lines changed

README.md

Lines changed: 205 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ Overlay networks based on WebRTC.
1616

1717
weron provides lean, fast & secure overlay networks based on WebRTC.
1818

19-
🚧 This project is a work-in-progress! Instructions will be added as soon as it is usable. 🚧
19+
It enables you too ...
20+
21+
- **Access to nodes behind NAT**: Because weron uses WebRTC to establish connections between nodes, it can easily traverse corporate firewalls and NATs using STUN, or even use a TURN server to tunnel traffic. This can be very useful to i.e. SSH into your homelab without forwarding any ports on your router.
22+
- **Secure your home network**: By using the inbuilt interactive TLS verification and running the signaling server locally, weron can be used to secure traffic between nodes in a LAN without depending on any external infrastructure.
23+
- **Join local nodes into a cloud network**: If you run e.g. a Kubernetes cluster with nodes based on cloud instances but also want to join your on-prem nodes into it, you can use weron to create a trusted network for it.
24+
- **Write your own peer-to-peer protocols**: The simple API makes writing distributed applications with automatic reconnects, multiple datachannels etc. approachable and fun!
2025

2126
## Installation
2227

@@ -83,9 +88,9 @@ $ sudo podman run -d --name weron-signaler --network weron -p 1337:1337 -e DATAB
8388

8489
It should now be reachable on `ws://localhost:1337/`.
8590

86-
To use it in production, put this signaling server behind a TLS-enabled reverse proxy such as [Caddy](https://caddyserver.com/) or [Traefik](https://traefik.io/). You may also either want to keep `API_PASSWORD` empty to disable the management API completely or use OpenID Connect to authenticate instead; for more information, see the [signaling server reference](#signaling-server). You can also embed the signaling server in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@v0.0.0-20220505182851-8eabe8595f05/pkg/wrtcsgl).
91+
To use it in production, put this signaling server behind a TLS-enabled reverse proxy such as [Caddy](https://caddyserver.com/) or [Traefik](https://traefik.io/). You may also either want to keep `API_PASSWORD` empty to disable the management API completely or use OpenID Connect to authenticate instead; for more information, see the [signaling server reference](#signaling-server). You can also embed the signaling server in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcsgl).
8792

88-
### Manage Communities with `weron manager`
93+
### 2. Manage Communities with `weron manager`
8994

9095
While it is possible to create ephermal communities on a signaling server without any kind of authorization, you probably want to create a persistent community for most applications. Ephermal communities get created and deleted automatically as clients join or leave, persistent communities will never get deleted automatically. You can manage these communities using the manager CLI.
9196

@@ -129,7 +134,203 @@ It is also possible to delete communities using `weron delete`, which will also
129134
$ weron manager delete --community mycommunity
130135
```
131136

132-
For more information, see the [manager reference](#manager). You can also embed the manager in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/[email protected]/pkg/wrtcmgr).
137+
For more information, see the [manager reference](#manager). You can also embed the manager in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcmgr).
138+
139+
### 3. Test the System with `weron chat`
140+
141+
The chat is an easy way to test if everything is working correctly. To join a chatroom, run the following:
142+
143+
```shell
144+
$ weron chat --community mycommunity --password mypassword --key mykey --names user1,user2,user3 --channels one,two,three
145+
```
146+
147+
On another peer, run the following (if your signaling server is public, you can run this anywhere on the planet):
148+
149+
```shell
150+
$ weron chat --community mycommunity --password mypassword --key mykey --names user1,user2,user3 --channels one,two,three
151+
.wss://weron.herokuapp.com/
152+
user2!
153+
+user1@one
154+
+user1@two
155+
+user1@three
156+
user2>
157+
```
158+
159+
You can now start sending and receiving messages or add new peers to your chatroom to test the network.
160+
161+
For more information, see the [chat reference](#chat). You can also embed the chat in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcchat).
162+
163+
### 4. Measure Latency with `weron utility latency`
164+
165+
An insightful metric of your network is it's latency, which you can measure with this utility; think of this as `ping`, but for WebRTC. First, start the latency measurement server like so:
166+
167+
```shell
168+
$ weron utility latency --community mycommunity --password mypassword --key mykey --server
169+
```
170+
171+
On another peer, launch the client, which should start measuring the latency immediately; press <kbd>CTRL</kbd> <kbd>C</kbd> to stop it and get the total statistics:
172+
173+
```shell
174+
$ weron utility latency --community mycommunity --password mypassword --key mykey
175+
# ...
176+
128 B written and acknowledged in 110.111µs
177+
128 B written and acknowledged in 386.12µs
178+
128 B written and acknowledged in 310.458µs
179+
128 B written and acknowledged in 335.341µs
180+
128 B written and acknowledged in 264.149µs
181+
^CAverage latency: 281.235µs (5 packets written) Min: 110.111µs Max: 386.12µs
182+
```
183+
184+
For more information, see the [latency measurement utility reference](#latency-measurement-utility). You can also embed the utility in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcltc).
185+
186+
### 5. Measure Throughput with `weron utility throughput`
187+
188+
If you want to transfer large amounts of data, your network's throughput is a key characteristic. This utility allows you to measure this metric between two nodes; think of it as `iperf`, but for WebRTC. First, start the throughput measurement server like so:
189+
190+
```shell
191+
$ weron utility throughput --community mycommunity --password mypassword --key mykey --server
192+
```
193+
194+
On another peer, launch the client, which should start measuring the throughput immediately; press <kbd>CTRL</kbd> <kbd>C</kbd> to stop it and get the total statistics:
195+
196+
```shell
197+
$ weron utility throughput --community mycommunity --password mypassword --key mykey
198+
# ...
199+
97.907 MB/s (783.253 Mb/s) (50 MB read in 510.690403ms)
200+
64.844 MB/s (518.755 Mb/s) (50 MB read in 771.076908ms)
201+
103.360 MB/s (826.881 Mb/s) (50 MB read in 483.745832ms)
202+
89.335 MB/s (714.678 Mb/s) (50 MB read in 559.692495ms)
203+
85.582 MB/s (684.657 Mb/s) (50 MB read in 584.233931ms)
204+
^CAverage throughput: 74.295 MB/s (594.359 Mb/s) (250 MB written in 3.364971672s) Min: 64.844 MB/s Max: 103.360 MB/s
205+
```
206+
207+
For more information, see the [throughput measurement utility reference](#throughput-measurement-utility). You can also embed the utility in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcthr).
208+
209+
### 6. Create a Layer 3 (IP) Overlay Network with `weron vpn ip`
210+
211+
If you want to join multiple nodes into a overlay network, the IP VPN is the best choice. It works in a similar way to i.e. Tailscale/WireGuard and can either dynamically allocate an IP address from a CIDR notation or statically assign one for you. On Windows, make sure to install [TAP-Windows](https://duckduckgo.com/?q=TAP-Windows&t=h_&ia=web) first. To get started, launch the VPN on the first peer:
212+
213+
```shell
214+
$ sudo weron vpn ip --community mycommunity --password mypassword --key mykey --ips 2001:db8::1/64,192.0.2.1/24
215+
{"level":"info","addr":"wss://weron.herokuapp.com/","time":"2022-05-06T22:20:51+02:00","message":"Connecting to signaler"}
216+
{"level":"info","id":"[\"2001:db8::6a/64\",\"192.0.2.107/24\"]","time":"2022-05-06T22:20:56+02:00","message":"Connected to signaler"}
217+
```
218+
219+
On another peer, launch the VPN as well:
220+
221+
```shell
222+
$ sudo weron vpn ip --community mycommunity --password mypassword --key mykey --ips 2001:db8::1/64,192.0.2.1/24
223+
{"level":"info","addr":"wss://weron.herokuapp.com/","time":"2022-05-06T22:22:30+02:00","message":"Connecting to signaler"}
224+
{"level":"info","id":"[\"2001:db8::b9/64\",\"192.0.2.186/24\"]","time":"2022-05-06T22:22:36+02:00","message":"Connected to signaler"}
225+
{"level":"info","id":"[\"2001:db8::6a/64\",\"192.0.2.107/24\"]","time":"2022-05-06T22:22:36+02:00","message":"Connected to peer"}
226+
```
227+
228+
You can now communicate between the peers:
229+
230+
```shell
231+
$ ping 2001:db8::b9
232+
PING 2001:db8::b9(2001:db8::b9) 56 data bytes
233+
64 bytes from 2001:db8::b9: icmp_seq=1 ttl=64 time=1.07 ms
234+
64 bytes from 2001:db8::b9: icmp_seq=2 ttl=64 time=1.36 ms
235+
64 bytes from 2001:db8::b9: icmp_seq=3 ttl=64 time=1.20 ms
236+
64 bytes from 2001:db8::b9: icmp_seq=4 ttl=64 time=1.10 ms
237+
^C
238+
--- 2001:db8::b9 ping statistics ---
239+
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
240+
rtt min/avg/max/mdev = 1.066/1.180/1.361/0.114 ms
241+
```
242+
243+
If you temporarly loose the network connection, the network topology changes etc. it will automatically reconnect. For more information and limitations on proprietary operating systems like macOS, see the [IP VPN reference](#layer-3-ip-overlay-networks). You can also embed the utility in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcip).
244+
245+
### 7. Create a Layer 2 (Ethernet) Overlay Network with `weron vpn ethernet`
246+
247+
If you want more flexibility or work on non-IP networks, the ethernet VPN is a good choice. It works in a similar way to `n2n` or ZeroTier. Due to API restrictions, this VPN type [is not available on macOS](https://support.apple.com/guide/deployment/system-and-kernel-extensions-in-macos-depa5fb8376f/web); use [Asahi Linux](https://asahilinux.org/), a computer that respects your freedoms or the layer 3 (IP) VPN instead. To get started, launch the VPN on the first peer:
248+
249+
```shell
250+
$ sudo weron vpn ethernet --community mycommunity --password mypassword --key mykey
251+
{"level":"info","addr":"wss://weron.herokuapp.com/","time":"2022-05-06T22:42:10+02:00","message":"Connecting to signaler"}
252+
{"level":"info","id":"fe:60:a5:8b:81:36","time":"2022-05-06T22:42:11+02:00","message":"Connected to signaler"}
253+
```
254+
255+
If you want to add an IP address to the TAP interface, do so with `iproute2` or your OS tools:
256+
257+
```shell
258+
$ sudo ip addr add 192.0.2.1/24 dev tap0
259+
$ sudo ip addr add 2001:db8::1/32 dev tap0
260+
```
261+
262+
On another peer, launch the VPN as well:
263+
264+
```shell
265+
$ sudo weron vpn ethernet --community mycommunity --password mypassword --key mykey
266+
{"level":"info","addr":"wss://weron.herokuapp.com/","time":"2022-05-06T22:52:56+02:00","message":"Connecting to signaler"}
267+
{"level":"info","id":"b2:ac:ae:b6:32:8c","time":"2022-05-06T22:52:57+02:00","message":"Connected to signaler"}
268+
{"level":"info","id":"fe:60:a5:8b:81:36","time":"2022-05-06T22:52:57+02:00","message":"Connected to peer"}
269+
```
270+
271+
And add the IP addresses:
272+
273+
```shell
274+
$ sudo ip addr add 192.0.2.2/24 dev tap0
275+
$ sudo ip addr add 2001:db8::2/32 dev tap0
276+
```
277+
278+
You can now communicate between the peers:
279+
280+
```shell
281+
$ ping 2001:db8::2
282+
PING 2001:db8::2(2001:db8::2) 56 data bytes
283+
64 bytes from 2001:db8::2: icmp_seq=1 ttl=64 time=1.20 ms
284+
64 bytes from 2001:db8::2: icmp_seq=2 ttl=64 time=1.14 ms
285+
64 bytes from 2001:db8::2: icmp_seq=3 ttl=64 time=1.24 ms
286+
^C
287+
--- 2001:db8::2 ping statistics ---
288+
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
289+
rtt min/avg/max/mdev = 1.136/1.193/1.239/0.042 ms
290+
```
291+
292+
If you temporarly loose the network connection, the network topology changes etc. it will automatically reconnect. You can also embed the utility in your own application using it's [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtceth).
293+
294+
### 8. Write your own protocol with `wrtcconn`
295+
296+
It is almost trivial to build your own dstributed applications with weron, similarly to how [PeerJS](https://peerjs.com/) works. Here is the core logic behind a simple echo example:
297+
298+
```go
299+
// ...
300+
for {
301+
select {
302+
case id := <-ids:
303+
log.Println("Connected to signaler", id)
304+
case peer := <-adapter.Accept():
305+
log.Println("Connected to peer", peer.PeerID, "and channel", peer.ChannelID)
306+
307+
go func() {
308+
defer func() {
309+
log.Println("Disconnected from peer", peer.PeerID, "and channel", peer.ChannelID)
310+
}()
311+
312+
reader := bufio.NewScanner(peer.Conn)
313+
for reader.Scan() {
314+
log.Printf("%s", reader.Bytes())
315+
}
316+
}()
317+
318+
go func() {
319+
for {
320+
if _, err := peer.Conn.Write([]byte("Hello!\n")); err != nil {
321+
return
322+
}
323+
324+
time.Sleep(time.Second)
325+
}
326+
}()
327+
}
328+
}
329+
```
330+
331+
You can either use the [minimal adapter](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcconn#Adapter) or the [named adapter](https://pkg.go.dev/github.com/pojntfx/weron@main/pkg/wrtcconn#NamedAdapter); the latter negotiates a username between the peers, while the former does not check for duplicates. For more information, check out the [Go API](https://pkg.go.dev/github.com/pojntfx/weron@main) and take a look at the other utilities and services in the package for examples.
332+
333+
🚀 **That's it!** We hope you enjoy using weron.
133334

134335
## Reference
135336

0 commit comments

Comments
 (0)