-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
135 lines (114 loc) · 3.24 KB
/
config.go
File metadata and controls
135 lines (114 loc) · 3.24 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package accelerator
import (
"strings"
"time"
"github.com/pkg/errors"
)
// ServerConfig contains accelerator server configurations.
type ServerConfig struct {
Common struct {
Interface string `toml:"interface"`
PassHash string `toml:"pwd_hash"`
LogPath string `toml:"log_path"`
} `toml:"common"`
Server struct {
ConnPoolSize int `toml:"conn_pool_size"`
NumFrameSender int `toml:"num_frame_sender"`
Timeout duration `toml:"timeout"`
} `toml:"server"`
TCP struct {
Enabled bool `toml:"enabled"`
Network string `toml:"network"`
Address string `toml:"address"`
} `toml:"tcp"`
UDP struct {
Enabled bool `toml:"enabled"`
Network string `toml:"network"`
Address string `toml:"address"`
} `toml:"udp"`
TLS struct {
ServerCert string `toml:"server_cert"`
ServerKey string `toml:"server_key"`
ClientCA string `toml:"client_ca"`
} `toml:"tls"`
NAT struct {
Enabled bool `toml:"enabled"`
Timeout duration `toml:"timeout"`
MAC struct {
Local string `toml:"local"`
Gateway string `toml:"gateway"`
} `toml:"mac"`
IPv4 struct {
Enabled bool `toml:"enabled"`
Local string `toml:"local"`
Gateway string `toml:"gateway"`
} `toml:"ipv4"`
IPv6 struct {
Enabled bool `toml:"enabled"`
Local string `toml:"local"`
Gateway string `toml:"gateway"`
} `toml:"ipv6"`
} `toml:"nat"`
}
// ClientConfig contains accelerator client configurations.
type ClientConfig struct {
Common struct {
Interface string `toml:"interface"`
PassHash string `toml:"pwd_hash"`
LogPath string `toml:"log_path"`
} `toml:"common"`
Client struct {
Mode string `toml:"mode"`
ConnPoolSize int `toml:"conn_pool_size"`
Timeout duration `toml:"timeout"`
} `toml:"client"`
TCP struct {
RemoteNetwork string `toml:"remote_network"`
RemoteAddress string `toml:"remote_address"`
LocalNetwork string `toml:"local_network"`
LocalAddress string `toml:"local_address"`
} `toml:"tcp"`
UDP struct {
RemoteNetwork string `toml:"remote_network"`
RemoteAddress string `toml:"remote_address"`
LocalNetwork string `toml:"local_network"`
LocalAddress string `toml:"local_address"`
} `toml:"udp"`
TLS struct {
ClientCert string `toml:"client_cert"`
ClientKey string `toml:"client_key"`
RootCA string `toml:"root_ca"`
} `toml:"tls"`
TAP struct {
ComponentID string `toml:"component_id"`
DeviceName string `toml:"device_name"`
} `toml:"tap"`
}
// duration is patch for toml v2.
type duration time.Duration
// MarshalText implement encoding.TextMarshaler.
func (d *duration) MarshalText() ([]byte, error) {
return []byte(time.Duration(*d).String()), nil
}
// UnmarshalText implement encoding.TextUnmarshaler.
func (d *duration) UnmarshalText(b []byte) error {
x, err := time.ParseDuration(string(b))
if err != nil {
return err
}
*d = duration(x)
return nil
}
// checkNetworkAndAddress is used to check network is supported and address is valid.
func checkNetworkAndAddress(network, address string) error {
switch network {
case "tcp", "tcp4", "tcp6":
case "udp", "udp4", "udp6":
default:
return errors.Errorf("unsupported network: \"%s\"", network)
}
if !strings.Contains(address, ":") {
return errors.New("missing port in address")
}
return nil
}