forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.go
53 lines (46 loc) · 1.3 KB
/
transport.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
package conf
import (
"errors"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport"
"v2ray.com/core/transport/internet"
)
type TransportConfig struct {
TCPConfig *TCPConfig `json:"tcpSettings"`
KCPConfig *KCPConfig `json:"kcpSettings"`
WSConfig *WebSocketConfig `json:"wsSettings"`
}
func (v *TransportConfig) Build() (*transport.Config, error) {
config := new(transport.Config)
if v.TCPConfig != nil {
ts, err := v.TCPConfig.Build()
if err != nil {
return nil, errors.New("Failed to build TCP config: " + err.Error())
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_TCP,
Settings: ts,
})
}
if v.KCPConfig != nil {
ts, err := v.KCPConfig.Build()
if err != nil {
return nil, errors.New("Failed to build KCP config: " + err.Error())
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_KCP,
Settings: ts,
})
}
if v.WSConfig != nil {
ts, err := v.WSConfig.Build()
if err != nil {
return nil, errors.New("Failed to build WebSocket config: " + err.Error())
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_WebSocket,
Settings: ts,
})
}
return config, nil
}