-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
87 lines (80 loc) · 2.73 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
82
83
84
85
86
87
package session
import (
"github.com/imdario/mergo"
ncp "github.com/nknorg/ncp-go"
"github.com/nknorg/tuna"
"github.com/nknorg/tuna/filter"
"github.com/nknorg/tuna/geo"
)
type Config struct {
NumTunaListeners int
TunaDialTimeout int // in millisecond
TunaMaxPrice string
TunaNanoPayFee string
TunaMinNanoPayFee string
TunaNanoPayFeeRatio float64
TunaServiceName string
TunaSubscriptionPrefix string
TunaIPFilter *geo.IPFilter
TunaNknFilter *filter.NknFilter
TunaDownloadGeoDB bool
TunaGeoDBPath string
TunaMeasureBandwidth bool
TunaMeasureStoragePath string
TunaMeasurementBytesDownLink int32
TunaMinBalance string
SessionConfig *ncp.Config
ReconnectRetries int // negative value: unlimited retries, 0: no reconnect, positive value: limit retries.
ReconnectInterval int // millisecond
UDPRecvBufferSize int // UDP user data receive buffer size, bytes
MaxUdpDatagramBuffered int // Maximum udp datagrams can be buffered. It works with UDPRecvBufferSize together go decide if a datagram is buffered.
Verbose bool
}
var defaultConfig = Config{
NumTunaListeners: 4,
TunaDialTimeout: 10000,
TunaMaxPrice: "0",
TunaNanoPayFee: "",
TunaMinNanoPayFee: "0",
TunaNanoPayFeeRatio: 0.1,
TunaServiceName: tuna.DefaultReverseServiceName,
TunaSubscriptionPrefix: tuna.DefaultSubscriptionPrefix,
TunaIPFilter: nil,
TunaNknFilter: nil,
TunaDownloadGeoDB: false,
TunaGeoDBPath: "",
TunaMeasureBandwidth: false,
TunaMeasureStoragePath: "",
TunaMeasurementBytesDownLink: 0, // use tuna default value
TunaMinBalance: "0",
SessionConfig: nil,
ReconnectRetries: 0,
ReconnectInterval: 2000,
UDPRecvBufferSize: 1 << 20, // 1 mega bytes
MaxUdpDatagramBuffered: 1024,
Verbose: false,
}
func DefaultConfig() *Config {
conf := defaultConfig
conf.TunaIPFilter = &geo.IPFilter{}
conf.TunaNknFilter = &filter.NknFilter{}
conf.SessionConfig = DefaultSessionConfig()
return &conf
}
var defaultSessionConfig = ncp.Config{
MTU: 1300,
}
func DefaultSessionConfig() *ncp.Config {
sessionConf := defaultSessionConfig
return &sessionConf
}
func MergedConfig(conf *Config) (*Config, error) {
merged := DefaultConfig()
if conf != nil {
err := mergo.Merge(merged, conf, mergo.WithOverride)
if err != nil {
return nil, err
}
}
return merged, nil
}