/
tunnel_config.go
81 lines (50 loc) · 1.29 KB
/
tunnel_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package rpc
import "errors"
func configureTunnel() {
if !o.tunEnable {
return
}
log.I.Ln("enabling rpc tunnel")
configureTunnelPort()
log.I.Ln("rpc tunnel listeners:")
log.I.F("- [/ip4/0.0.0.0/udp/%d /ip6/:::/udp/%d]", o.tunPort, o.tunPort)
configureTunnelKey()
configurePeerWhitelist()
}
func configureTunnelKey() {
log.I.Ln("looking for key in storage")
var err error
tunKey, err = o.store.GetKey()
if err == nil {
log.I.Ln("rpc tunnel public key:")
log.I.Ln("-", tunKey.PubKey().Encode())
return
}
if !errors.Is(err, ErrKeyNotExists) {
return
}
log.I.Ln("key not provided, generating a new one.")
tunKey, _ = NewPrivateKey()
o.store.SetKey(tunKey)
log.I.Ln("rpc tunnel public key:")
log.I.Ln("-", tunKey.PubKey().Encode())
}
func configureTunnelPort() {
if o.tunPort != NullPort {
return
}
log.I.Ln("rpc tunnel port not provided, generating a random one.")
o.tunPort = genRandomPort(10000) // no paricular reason why 10000 minimum, would be better to just use 0 bind?
}
func configurePeerWhitelist() {
if len(o.tunPeers) == 0 {
return
}
log.I.Ln("rpc tunnel whitelisted peers:")
for _, peer := range o.tunPeers {
var pubKey PublicKey
pubKey.Decode(peer)
log.I.Ln("-", pubKey.Encode())
tunWhitelist = append(tunWhitelist, pubKey)
}
}