1strelaysrv
2==========
3
4This is the relay server for the `syncthing` project.
5
6:exclamation:Warnings:exclamation: - Read or regret
7-----
8
9By default, all relay servers will join to the default public relay pool, which means that the relay server will be available for public use, and **will consume your bandwidth** helping others to connect.
10
11If you wish to disable this behaviour, please specify the `-pools=""` argument.
12
13Please note that `strelaysrv` is only usable by `syncthing` **version v0.12 and onwards**.
14
15To run `strelaysrv` you need to have port 22067 available to the internet, which means you might need to port forward it and/or allow it through your firewall.
16
17Furthermore, by default `strelaysrv` will also expose a /status HTTP endpoint on port 22070, which is used by the pool servers to read metrics of the `strelaysrv`, such as  the current transfer rates, how many clients are connected, etc. If you wish this information to be available you may need to port forward and allow it through your firewall. This is not mandatory for the `strelaysrv` to function, and is used only to gather metrics and present them in the overview page of the pool server.
18
19At the point of writing the endpoint output looks as follows:
20
21```
22{
23    "bytesProxied": 0,
24    "goArch": "amd64",
25    "goMaxProcs": 1,
26    "goNumRoutine": 13,
27    "goOS": "linux",
28    "goVersion": "go1.6",
29    "kbps10s1m5m15m30m60m": [
30        0,
31        0,
32        0,
33        0,
34        0,
35        0
36    ],
37    "numActiveSessions": 0,
38    "numConnections": 0,
39    "numPendingSessionKeys": 2,
40    "numProxies": 0,
41    "options": {
42        "global-rate": 0,
43        "message-timeout": 60,
44        "network-timeout": 120,
45        "per-session-rate": 0,
46        "ping-interval": 60,
47        "pools": [
48            "https://relays.syncthing.net/endpoint"
49        ],
50        "provided-by": ""
51    },
52    "startTime": "2016-03-06T12:53:07.090847749-05:00",
53    "uptimeSeconds": 17
54}
55```
56
57If you wish to disable the /status endpoint, provide `-status-srv=""` as one of the arguments when starting the strelaysrv.
58
59Running for public use
60----
61Make sure you have a public IP with port 22067 open, or have forwarded port 22067 if you are behind a NAT.
62
63Run the `strelaysrv` with no arguments (or `-debug` if you want more output), and that should be enough for the server to join the public relay pool.
64You should see a message saying:
65```
662015/09/21 22:45:46 pool.go:60: Joined https://relays.syncthing.net/endpoint rejoining in 48m0s
67```
68
69See `strelaysrv -help` for other options, such as rate limits, timeout intervals, etc.
70
71Running for private use
72-----
73
74Once you've started the `strelaysrv`, it will generate a key pair and print a URI:
75```bash
76relay://:22067/?id=EZQOIDM-6DDD4ZI-DJ65NSM-4OQWRAT-EIKSMJO-OZ552BO-WQZEGYY-STS5RQM&pingInterval=1m0s&networkTimeout=2m0s&sessionLimitBps=0&globalLimitBps=0&statusAddr=:22070
77```
78
79This URI contains a partial address of the relay server, as well as its options which in the future may be taken into account when choosing the most suitable relay.
80
81Because the `-listen` option was not used `strelaysrv` does not know its external IP, therefore you should replace the host part of the URI with your public IP address on which the `strelaysrv` will be available:
82
83```bash
84relay://192.0.2.1:22067/?id=EZQOIDM-6DDD4ZI-DJ65NSM-4OQWRAT-EIKSMJO-OZ552BO-WQZEGYY-STS5RQM&pingInterval=1m0s&networkTimeout=2m0s&sessionLimitBps=0&globalLimitBps=0&statusAddr=:22070
85```
86
87If you do not care about certificate pinning (improved security) or do not care about passing verbose settings to the clients, you can shorten the URL to just the host part:
88
89```bash
90relay://192.0.2.1:22067
91```
92
93This URI can then be used in `syncthing` clients as one of the relay servers by adding the URI to the "Sync Protocol Listen Address" field, under Actions and Settings.
94
95See `strelaysrv -help` for other options, such as rate limits, timeout intervals, etc.
96
97Other items available in this repo
98----
99##### testutil
100A test utility which can be used to test the connectivity of a relay server.
101You need to generate two x509 key pairs (key.pem and cert.pem), one for the client and one for the server, in separate directories.
102Afterwards, start the client:
103```bash
104./testutil -relay="relay://192.0.2.1:22067" -keys=certs/client/ -join
105```
106
107This prints out the client ID:
108```
1092015/09/21 23:00:52 main.go:42: ID: BG2C5ZA-W7XPFDO-LH222Z6-65F3HJX-ADFTGRT-3SBFIGM-KV26O2Q-E5RMRQ2
110```
111
112In the other terminal run the following:
113
114```bash
115 ./testutil -relay="relay://192.0.2.1:22067" -keys=certs/server/ -connect=BG2C5ZA-W7XPFDO-LH222Z6-65F3HJX-ADFTGRT-3SBFIGM-KV26O2Q-E5RMRQ2
116```
117
118Which should then give you an interactive prompt, where you can type things in one terminal, and they get relayed to the other terminal.
119
120Relay related libraries used by this repo
121----
122##### Relay protocol definition.
123
124[Available here](https://github.com/syncthing/syncthing/tree/main/lib/relay/protocol)
125
126
127##### Relay client
128
129Only used by the testutil.
130
131[Available here](https://github.com/syncthing/syncthing/tree/main/lib/relay/client)
132