1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/tools/conf/transport.go

54 lines
1.3 KiB
Go
Raw Normal View History

2016-10-17 08:35:13 -04:00
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"`
}
2016-11-27 15:39:09 -05:00
func (v *TransportConfig) Build() (*transport.Config, error) {
2016-10-17 08:35:13 -04:00
config := new(transport.Config)
2016-11-27 15:39:09 -05:00
if v.TCPConfig != nil {
ts, err := v.TCPConfig.Build()
2016-10-17 08:35:13 -04:00
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,
})
}
2016-11-27 15:39:09 -05:00
if v.KCPConfig != nil {
ts, err := v.KCPConfig.Build()
2016-10-17 08:35:13 -04:00
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,
})
}
2016-11-27 15:39:09 -05:00
if v.WSConfig != nil {
ts, err := v.WSConfig.Build()
2016-10-17 08:35:13 -04:00
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
}