forked from nknorg/nkn-tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
52 lines (47 loc) · 1.16 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
package tunnel
import (
"github.com/imdario/mergo"
"github.com/nknorg/nkn-sdk-go"
ts "github.com/nknorg/nkn-tuna-session"
"github.com/nknorg/nkngomobile"
"github.com/nknorg/tuna/types"
)
type Config struct {
NumSubClients int
OriginalClient bool
AcceptAddrs *nkngomobile.StringArray
ClientConfig *nkn.ClientConfig
WalletConfig *nkn.WalletConfig
DialConfig *nkn.DialConfig
TunaSessionConfig *ts.Config
UDP bool
UDPIdleTime int32 // Seconds. Time to purge idle udp connections, 0 is for no purge.
Verbose bool
TunaNode *types.Node
}
var defaultConfig = Config{
NumSubClients: 4,
OriginalClient: false,
AcceptAddrs: nil,
ClientConfig: nil,
WalletConfig: nil,
DialConfig: nil,
TunaSessionConfig: nil,
UDP: false,
UDPIdleTime: 0,
Verbose: false,
}
func DefaultConfig() *Config {
conf := defaultConfig
return &conf
}
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
}