You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/tools/conf/transport.go

52 lines
1.3 KiB

package conf
import (
"v2ray.com/core/common/errors"
"v2ray.com/core/transport"
"v2ray.com/core/transport/internet"
)
type TransportConfig struct {
TCPConfig *TCPConfig `json:"tcpSettings"`
KCPConfig *KCPConfig `json:"kcpSettings"`
WSConfig *WebSocketConfig `json:"wsSettings"`
}
8 years ago
func (v *TransportConfig) Build() (*transport.Config, error) {
config := new(transport.Config)
8 years ago
if v.TCPConfig != nil {
ts, err := v.TCPConfig.Build()
if err != nil {
8 years ago
return nil, errors.Base(err).Message("Failed to build TCP config.")
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
Protocol: internet.TransportProtocol_TCP,
Settings: ts,
})
}
8 years ago
if v.KCPConfig != nil {
ts, err := v.KCPConfig.Build()
if err != nil {
8 years ago
return nil, errors.Base(err).Message("Failed to build mKCP config.")
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
Protocol: internet.TransportProtocol_MKCP,
Settings: ts,
})
}
8 years ago
if v.WSConfig != nil {
ts, err := v.WSConfig.Build()
if err != nil {
8 years ago
return nil, errors.Base(err).Message("Failed to build WebSocket config.")
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
Protocol: internet.TransportProtocol_WebSocket,
Settings: ts,
})
}
return config, nil
}