Skip to content

Commit 4c63fb3

Browse files
authored
Merge pull request #16 from threefoldtech/update_docs
Update docs
2 parents d441010 + 9aa60ef commit 4c63fb3

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

docs/README.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ We have two toml sections so far
5353
addr = "0.0.0.0"
5454
port = 443
5555
httpport = 80
56+
clientsport = 18000
5657
```
5758

5859
in `[server]` section we define the listening interface/port the tcprouter intercepting: typically that's 443 for TLS connections.
@@ -64,7 +65,7 @@ in `[server]` section we define the listening interface/port the tcprouter inter
6465
type = "redis"
6566
addr = "127.0.0.1"
6667
port = 6379
67-
refresh = 10
68+
refresh = 5
6869
```
6970

7071
in `server.dbbackend` we define the backend kv store and its connection information `addr,port` and how often we want to reload the data from the kv store using `refresh` key in seconds.
@@ -128,8 +129,8 @@ func init() {
128129

129130
type Service struct {
130131
Addr string `json:"addr"`
131-
SNI string `json:"sni"`
132-
Name string `json:"bing"`
132+
TLSPort int `json:"tlsport"`
133+
HTTPPort int `json:"httpport"`
133134
}
134135

135136
func main() {
@@ -145,9 +146,9 @@ func main() {
145146
if err != nil {
146147
log.Fatal("Cannot create store redis")
147148
}
148-
google := &Service{Addr:"172.217.19.46:443", SNI:"www.google.com", Name:"google"}
149+
google := &Service{Addr:"172.217.19.46", HTTPPort: 80, TLSPort: 443}
149150
encGoogle, _ := json.Marshal(google)
150-
bing := &Service{Addr:"13.107.21.200:443", SNI:"www.bing.com", Name:"bing"}
151+
bing := &Service{Addr:"13.107.21.200", HTTPPort: 80, TLSPort: 443}
151152
encBing, _ := json.Marshal(bing)
152153

153154
kv.Put("/tcprouter/services/google", encGoogle, nil)
@@ -157,25 +158,25 @@ func main() {
157158

158159
### Python
159160

160-
```python3
161+
```python
161162
import base64
162163
import json
163164
import redis
164165

165166
r = redis.Redis()
166167

167-
def create_service(name, sni, addr):
168+
def create_service(domain, addr, tlsport=443, httpport=80):
168169
service = {}
169-
service['Key'] = '/tcprouter/service/{}'.format(name)
170-
record = {"addr":addr, "sni":sni, "name":name}
170+
service['Key'] = '/tcprouter/service/{}'.format(domain)
171+
record = {"addr":addr, "tlsport": tlsport, "httpport": httpport}
171172
json_dumped_record_bytes = json.dumps(record).encode()
172173
b64_record = base64.b64encode(json_dumped_record_bytes).decode()
173174
service['Value'] = b64_record
174175
r.set(service['Key'], json.dumps(service))
175176

176-
create_service('facebook', "www.facebook.com", "102.132.97.35:443")
177-
create_service('google', 'www.google.com', '172.217.19.46:443')
178-
create_service('bing', 'www.bing.com', '13.107.21.200:443')
177+
create_service("www.facebook.com", "102.132.97.35")
178+
create_service('www.google.com', '172.217.19.46')
179+
create_service('www.bing.com', '13.107.21.200')
179180
```
180181

181182
If you want to test that locally you can modify `/etc/hosts`
@@ -190,17 +191,31 @@ So your browser go to your `127.0.0.1:443` on requesting google or bing.
190191

191192
## CATCH_ALL
192193

193-
to add a global `catch all` service
194-
195-
`python3 create_service.py CATCH_ALL 'CATCH_ALL' '127.0.0.1:9092'`
194+
To add a global `catch all` service
196195

196+
`create_service("CATCH_ALL", "102.132.97.35")`
197197

198198
# Client
199199

200200
![tcprouterclient](./images/tcprouterclient.png)
201201

202202
is small network component that's supposed to live in a container (on a private network) and it will connect to tcprouter and allows sockets to be forwarded into the container using a handshake
203203

204+
## Examples
205+
206+
Adding records in backend as the previous [example](#examples), but instead of `addr`, `tlsport` and `httpport` in the record, `clientsecret` will be used.
207+
208+
```python
209+
record = {"clientsecret": <secret>}
210+
```
211+
212+
## Running
213+
214+
```bash
215+
./trc -local <local_application_address> -remote <tcp_router_server_address> -secret <secret>
216+
```
217+
218+
**Note:** The `secret` used in running the client, MUST be the same as the one stored in backend.
204219

205220
# Handshake
206221

@@ -212,4 +227,4 @@ type Handshake struct {
212227
Secret []byte
213228
}
214229
```
215-
a packet starts with MagicNr `0x1111` and followed by secret
230+
a packet starts with MagicNr `0x1111` and followed by secret

0 commit comments

Comments
 (0)