Esempio n. 1
0
func (this *TransportConfig) Build() (*transport.Config, error) {
	config := new(transport.Config)

	if this.TCPConfig != nil {
		ts, err := this.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 this.KCPConfig != nil {
		ts, err := this.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 this.WSConfig != nil {
		ts, err := this.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
}
Esempio n. 2
0
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.Base(err).Message("Failed to build TCP config.")
		}
		config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
			Protocol: internet.TransportProtocol_TCP,
			Settings: ts,
		})
	}

	if v.KCPConfig != nil {
		ts, err := v.KCPConfig.Build()
		if err != nil {
			return nil, errors.Base(err).Message("Failed to build mKCP config.")
		}
		config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
			Protocol: internet.TransportProtocol_MKCP,
			Settings: ts,
		})
	}

	if v.WSConfig != nil {
		ts, err := v.WSConfig.Build()
		if err != nil {
			return nil, errors.Base(err).Message("Failed to build WebSocket config.")
		}
		config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
			Protocol: internet.TransportProtocol_WebSocket,
			Settings: ts,
		})
	}
	return config, nil
}