-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
64 lines (54 loc) · 1.48 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
package config
import (
"io"
"time"
"berty.tech/go-libp2p-tor-transport/internal/confStore"
"github.com/joomcode/errorx"
)
// Check that all configurator are correctly done :
var _ = []Configurator{
AllowTcpDial,
DoSlowStart,
}
type Configurator func(*confStore.Config) error
// ConfMerge Merges different configs, starting at the first ending at the last.
func Merge(cs ...Configurator) Configurator {
return func(c *confStore.Config) error {
for _, v := range cs {
if err := v(c); err != nil {
return err
}
}
return nil
}
}
// AllowTcpDial allows the tor transport to dial tcp address.
// By Default TcpDial is off.
func AllowTcpDial(c *confStore.Config) error {
c.AllowTcpDial = true
return nil
}
// DoSlowStart set the tor node to bootstrap only when a Dial or a Listen is issued.
// By Default DoSlowStart is off.
func DoSlowStart(c *confStore.Config) error {
c.TorStart.EnableNetwork = false
return nil
}
// SetSetupTimeout change the timeout for the bootstrap of the node and the publication of the tunnel.
// By Default SetupTimeout is at 5 minutes.
func SetSetupTimeout(t time.Duration) Configurator {
return func(c *confStore.Config) error {
if t == 0 {
return errorx.IllegalArgument.New("Timeout can't be 0.")
}
c.SetupTimeout = t
return nil
}
}
// SetNodeDebug set the writer for the tor node debug output.
func SetNodeDebug(debug io.Writer) Configurator {
return func(c *confStore.Config) error {
c.TorStart.DebugWriter = debug
return nil
}
}