-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
81 lines (67 loc) · 1.65 KB
/
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 torproxy
import (
"context"
"fmt"
"strconv"
"time"
"github.com/cretz/bine/tor"
"github.com/caddyserver/caddy"
)
// TorProxy config
type Config struct {
To map[string]string
Client *Tor
}
// Tor instance config struct
type Tor struct {
// Socks5 proxy port
Port int
DataDir string
Torrc string
DebugMode bool
LogFile string
instance *tor.Tor
contextCanceler context.CancelFunc
onion *tor.OnionService
}
// DefaultOnionServicePort is the port used to serve the onion service on
const DefaultOnionServicePort = 4242
// TODO: Discuss these values
const (
torProxyKeepalive = 30000000
torFallbackDelay = 30000000 * time.Millisecond
torProxyTimeout = 30000000 * time.Second
)
// ParseTor parses advanced config for Tor client
func (t *Tor) ParseTor(c *caddy.Controller) error {
switch c.Val() {
case "port":
value, err := strconv.Atoi(c.RemainingArgs()[0])
if err != nil {
return fmt.Errorf("The given value for port field is not standard. It should be an integer")
}
t.Port = value
case "datadir":
t.DataDir = c.RemainingArgs()[0]
case "torrc":
t.Torrc = c.RemainingArgs()[0]
case "debug_mode":
value, err := strconv.ParseBool(c.RemainingArgs()[0])
if err != nil {
return fmt.Errorf("The given value for debug_mode field is not standard. It should be a boolean")
}
t.DebugMode = value
case "logfile":
t.LogFile = c.RemainingArgs()[0]
default:
return c.ArgErr() // unhandled option for tor
}
return nil
}
// SetDefaults sets the default values for prometheus config
// if the fields are empty
func (t *Tor) SetDefaults() {
if t.Port == 0 {
t.Port = DefaultOnionServicePort
}
}