|
@@ -40,50 +40,50 @@ type KCPConfig struct {
|
|
|
HeaderConfig json.RawMessage `json:"header"`
|
|
HeaderConfig json.RawMessage `json:"header"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (this *KCPConfig) Build() (*loader.TypedSettings, error) {
|
|
|
|
|
|
|
+func (v *KCPConfig) Build() (*loader.TypedSettings, error) {
|
|
|
config := new(kcp.Config)
|
|
config := new(kcp.Config)
|
|
|
|
|
|
|
|
- if this.Mtu != nil {
|
|
|
|
|
- mtu := *this.Mtu
|
|
|
|
|
|
|
+ if v.Mtu != nil {
|
|
|
|
|
+ mtu := *v.Mtu
|
|
|
if mtu < 576 || mtu > 1460 {
|
|
if mtu < 576 || mtu > 1460 {
|
|
|
return nil, fmt.Errorf("KCP|Config: Invalid MTU size: %d", mtu)
|
|
return nil, fmt.Errorf("KCP|Config: Invalid MTU size: %d", mtu)
|
|
|
}
|
|
}
|
|
|
config.Mtu = &kcp.MTU{Value: mtu}
|
|
config.Mtu = &kcp.MTU{Value: mtu}
|
|
|
}
|
|
}
|
|
|
- if this.Tti != nil {
|
|
|
|
|
- tti := *this.Tti
|
|
|
|
|
|
|
+ if v.Tti != nil {
|
|
|
|
|
+ tti := *v.Tti
|
|
|
if tti < 10 || tti > 100 {
|
|
if tti < 10 || tti > 100 {
|
|
|
return nil, fmt.Errorf("KCP|Config: Invalid TTI: %d", tti)
|
|
return nil, fmt.Errorf("KCP|Config: Invalid TTI: %d", tti)
|
|
|
}
|
|
}
|
|
|
config.Tti = &kcp.TTI{Value: tti}
|
|
config.Tti = &kcp.TTI{Value: tti}
|
|
|
}
|
|
}
|
|
|
- if this.UpCap != nil {
|
|
|
|
|
- config.UplinkCapacity = &kcp.UplinkCapacity{Value: *this.UpCap}
|
|
|
|
|
|
|
+ if v.UpCap != nil {
|
|
|
|
|
+ config.UplinkCapacity = &kcp.UplinkCapacity{Value: *v.UpCap}
|
|
|
}
|
|
}
|
|
|
- if this.DownCap != nil {
|
|
|
|
|
- config.DownlinkCapacity = &kcp.DownlinkCapacity{Value: *this.DownCap}
|
|
|
|
|
|
|
+ if v.DownCap != nil {
|
|
|
|
|
+ config.DownlinkCapacity = &kcp.DownlinkCapacity{Value: *v.DownCap}
|
|
|
}
|
|
}
|
|
|
- if this.Congestion != nil {
|
|
|
|
|
- config.Congestion = *this.Congestion
|
|
|
|
|
|
|
+ if v.Congestion != nil {
|
|
|
|
|
+ config.Congestion = *v.Congestion
|
|
|
}
|
|
}
|
|
|
- if this.ReadBufferSize != nil {
|
|
|
|
|
- size := *this.ReadBufferSize
|
|
|
|
|
|
|
+ if v.ReadBufferSize != nil {
|
|
|
|
|
+ size := *v.ReadBufferSize
|
|
|
if size > 0 {
|
|
if size > 0 {
|
|
|
config.ReadBuffer = &kcp.ReadBuffer{Size: size * 1024 * 1024}
|
|
config.ReadBuffer = &kcp.ReadBuffer{Size: size * 1024 * 1024}
|
|
|
} else {
|
|
} else {
|
|
|
config.ReadBuffer = &kcp.ReadBuffer{Size: 512 * 1024}
|
|
config.ReadBuffer = &kcp.ReadBuffer{Size: 512 * 1024}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if this.WriteBufferSize != nil {
|
|
|
|
|
- size := *this.WriteBufferSize
|
|
|
|
|
|
|
+ if v.WriteBufferSize != nil {
|
|
|
|
|
+ size := *v.WriteBufferSize
|
|
|
if size > 0 {
|
|
if size > 0 {
|
|
|
config.WriteBuffer = &kcp.WriteBuffer{Size: size * 1024 * 1024}
|
|
config.WriteBuffer = &kcp.WriteBuffer{Size: size * 1024 * 1024}
|
|
|
} else {
|
|
} else {
|
|
|
config.WriteBuffer = &kcp.WriteBuffer{Size: 512 * 1024}
|
|
config.WriteBuffer = &kcp.WriteBuffer{Size: 512 * 1024}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if len(this.HeaderConfig) > 0 {
|
|
|
|
|
- headerConfig, _, err := kcpHeaderLoader.Load(this.HeaderConfig)
|
|
|
|
|
|
|
+ if len(v.HeaderConfig) > 0 {
|
|
|
|
|
+ headerConfig, _, err := kcpHeaderLoader.Load(v.HeaderConfig)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, errors.New("KCP|Config: Failed to parse header config: " + err.Error())
|
|
return nil, errors.New("KCP|Config: Failed to parse header config: " + err.Error())
|
|
|
}
|
|
}
|
|
@@ -102,15 +102,15 @@ type TCPConfig struct {
|
|
|
HeaderConfig json.RawMessage `json:"header"`
|
|
HeaderConfig json.RawMessage `json:"header"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (this *TCPConfig) Build() (*loader.TypedSettings, error) {
|
|
|
|
|
|
|
+func (v *TCPConfig) Build() (*loader.TypedSettings, error) {
|
|
|
config := new(tcp.Config)
|
|
config := new(tcp.Config)
|
|
|
- if this.ConnectionReuse != nil {
|
|
|
|
|
|
|
+ if v.ConnectionReuse != nil {
|
|
|
config.ConnectionReuse = &tcp.ConnectionReuse{
|
|
config.ConnectionReuse = &tcp.ConnectionReuse{
|
|
|
- Enable: *this.ConnectionReuse,
|
|
|
|
|
|
|
+ Enable: *v.ConnectionReuse,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if len(this.HeaderConfig) > 0 {
|
|
|
|
|
- headerConfig, _, err := tcpHeaderLoader.Load(this.HeaderConfig)
|
|
|
|
|
|
|
+ if len(v.HeaderConfig) > 0 {
|
|
|
|
|
+ headerConfig, _, err := tcpHeaderLoader.Load(v.HeaderConfig)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, errors.New("TCP|Config: Failed to parse header config: " + err.Error())
|
|
return nil, errors.New("TCP|Config: Failed to parse header config: " + err.Error())
|
|
|
}
|
|
}
|
|
@@ -129,13 +129,13 @@ type WebSocketConfig struct {
|
|
|
Path string `json:"Path"`
|
|
Path string `json:"Path"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (this *WebSocketConfig) Build() (*loader.TypedSettings, error) {
|
|
|
|
|
|
|
+func (v *WebSocketConfig) Build() (*loader.TypedSettings, error) {
|
|
|
config := &ws.Config{
|
|
config := &ws.Config{
|
|
|
- Path: this.Path,
|
|
|
|
|
|
|
+ Path: v.Path,
|
|
|
}
|
|
}
|
|
|
- if this.ConnectionReuse != nil {
|
|
|
|
|
|
|
+ if v.ConnectionReuse != nil {
|
|
|
config.ConnectionReuse = &ws.ConnectionReuse{
|
|
config.ConnectionReuse = &ws.ConnectionReuse{
|
|
|
- Enable: *this.ConnectionReuse,
|
|
|
|
|
|
|
+ Enable: *v.ConnectionReuse,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return loader.NewTypedSettings(config), nil
|
|
return loader.NewTypedSettings(config), nil
|
|
@@ -150,10 +150,10 @@ type TLSConfig struct {
|
|
|
Certs []*TLSCertConfig `json:"certificates"`
|
|
Certs []*TLSCertConfig `json:"certificates"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (this *TLSConfig) Build() (*loader.TypedSettings, error) {
|
|
|
|
|
|
|
+func (v *TLSConfig) Build() (*loader.TypedSettings, error) {
|
|
|
config := new(tls.Config)
|
|
config := new(tls.Config)
|
|
|
- config.Certificate = make([]*tls.Certificate, len(this.Certs))
|
|
|
|
|
- for idx, certConf := range this.Certs {
|
|
|
|
|
|
|
+ config.Certificate = make([]*tls.Certificate, len(v.Certs))
|
|
|
|
|
+ for idx, certConf := range v.Certs {
|
|
|
cert, err := ioutil.ReadFile(certConf.CertFile)
|
|
cert, err := ioutil.ReadFile(certConf.CertFile)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, errors.New("TLS: Failed to load certificate file: " + err.Error())
|
|
return nil, errors.New("TLS: Failed to load certificate file: " + err.Error())
|
|
@@ -167,7 +167,7 @@ func (this *TLSConfig) Build() (*loader.TypedSettings, error) {
|
|
|
Certificate: cert,
|
|
Certificate: cert,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- config.AllowInsecure = this.Insecure
|
|
|
|
|
|
|
+ config.AllowInsecure = v.Insecure
|
|
|
return loader.NewTypedSettings(config), nil
|
|
return loader.NewTypedSettings(config), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -180,15 +180,15 @@ type StreamConfig struct {
|
|
|
WSSettings *WebSocketConfig `json:"wsSettings"`
|
|
WSSettings *WebSocketConfig `json:"wsSettings"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (this *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|
|
|
|
|
|
+func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|
|
config := &internet.StreamConfig{
|
|
config := &internet.StreamConfig{
|
|
|
Network: v2net.Network_RawTCP,
|
|
Network: v2net.Network_RawTCP,
|
|
|
}
|
|
}
|
|
|
- if this.Network != nil {
|
|
|
|
|
- config.Network = (*this.Network).Build()
|
|
|
|
|
|
|
+ if v.Network != nil {
|
|
|
|
|
+ config.Network = (*v.Network).Build()
|
|
|
}
|
|
}
|
|
|
- if strings.ToLower(this.Security) == "tls" {
|
|
|
|
|
- tlsSettings := this.TLSSettings
|
|
|
|
|
|
|
+ if strings.ToLower(v.Security) == "tls" {
|
|
|
|
|
+ tlsSettings := v.TLSSettings
|
|
|
if tlsSettings == nil {
|
|
if tlsSettings == nil {
|
|
|
tlsSettings = &TLSConfig{}
|
|
tlsSettings = &TLSConfig{}
|
|
|
}
|
|
}
|
|
@@ -198,8 +198,8 @@ func (this *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|
|
}
|
|
}
|
|
|
config.SecuritySettings = append(config.SecuritySettings, ts)
|
|
config.SecuritySettings = append(config.SecuritySettings, ts)
|
|
|
}
|
|
}
|
|
|
- if this.TCPSettings != nil {
|
|
|
|
|
- ts, err := this.TCPSettings.Build()
|
|
|
|
|
|
|
+ if v.TCPSettings != nil {
|
|
|
|
|
+ ts, err := v.TCPSettings.Build()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, errors.New("Failed to build TCP config: " + err.Error())
|
|
return nil, errors.New("Failed to build TCP config: " + err.Error())
|
|
|
}
|
|
}
|
|
@@ -208,8 +208,8 @@ func (this *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|
|
Settings: ts,
|
|
Settings: ts,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- if this.KCPSettings != nil {
|
|
|
|
|
- ts, err := this.KCPSettings.Build()
|
|
|
|
|
|
|
+ if v.KCPSettings != nil {
|
|
|
|
|
+ ts, err := v.KCPSettings.Build()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, errors.New("Failed to build KCP config: " + err.Error())
|
|
return nil, errors.New("Failed to build KCP config: " + err.Error())
|
|
|
}
|
|
}
|
|
@@ -218,8 +218,8 @@ func (this *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|
|
Settings: ts,
|
|
Settings: ts,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- if this.WSSettings != nil {
|
|
|
|
|
- ts, err := this.WSSettings.Build()
|
|
|
|
|
|
|
+ if v.WSSettings != nil {
|
|
|
|
|
+ ts, err := v.WSSettings.Build()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, errors.New("Failed to build WebSocket config: " + err.Error())
|
|
return nil, errors.New("Failed to build WebSocket config: " + err.Error())
|
|
|
}
|
|
}
|
|
@@ -235,11 +235,11 @@ type ProxyConfig struct {
|
|
|
Tag string `json:"tag"`
|
|
Tag string `json:"tag"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (this *ProxyConfig) Build() (*internet.ProxyConfig, error) {
|
|
|
|
|
- if len(this.Tag) == 0 {
|
|
|
|
|
|
|
+func (v *ProxyConfig) Build() (*internet.ProxyConfig, error) {
|
|
|
|
|
+ if len(v.Tag) == 0 {
|
|
|
return nil, errors.New("Proxy tag is not set.")
|
|
return nil, errors.New("Proxy tag is not set.")
|
|
|
}
|
|
}
|
|
|
return &internet.ProxyConfig{
|
|
return &internet.ProxyConfig{
|
|
|
- Tag: this.Tag,
|
|
|
|
|
|
|
+ Tag: v.Tag,
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|