2016-10-17 08:35:13 -04:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
2016-12-04 03:10:47 -05:00
|
|
|
"v2ray.com/core/common/errors"
|
2016-10-17 08:35:13 -04:00
|
|
|
"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 {
|
2016-12-04 03:43:33 -05:00
|
|
|
return nil, errors.Base(err).Message("Failed to build TCP config.")
|
2016-10-17 08:35:13 -04:00
|
|
|
}
|
2017-01-12 06:54:34 -05:00
|
|
|
config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
|
|
|
|
Protocol: internet.TransportProtocol_TCP,
|
2016-10-17 08:35:13 -04:00
|
|
|
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 {
|
2016-12-04 03:43:33 -05:00
|
|
|
return nil, errors.Base(err).Message("Failed to build mKCP config.")
|
2016-10-17 08:35:13 -04:00
|
|
|
}
|
2017-01-12 06:54:34 -05:00
|
|
|
config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
|
|
|
|
Protocol: internet.TransportProtocol_MKCP,
|
2016-10-17 08:35:13 -04:00
|
|
|
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 {
|
2016-12-04 03:43:33 -05:00
|
|
|
return nil, errors.Base(err).Message("Failed to build WebSocket config.")
|
2016-10-17 08:35:13 -04:00
|
|
|
}
|
2017-01-12 06:54:34 -05:00
|
|
|
config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
|
|
|
|
Protocol: internet.TransportProtocol_WebSocket,
|
2016-10-17 08:35:13 -04:00
|
|
|
Settings: ts,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return config, nil
|
|
|
|
}
|