
Implement a simplified version of STCP functionality. * **Client Proxy Configuration and Handling** - Add `STCPProxyConfig` to the `pxyConfs` slice in `client/proxy/general_tcp.go`. * **Client Visitor Configuration and Handling** - Add `STCPVisitorConfig` to the `cfg` struct in `client/visitor/stcp.go`. * **Command Registration and Initialization** - Add `STCP` to the `proxyTypes` and `visitorTypes` slices in `cmd/frpc/sub/proxy.go`. * **Configuration Examples** - Add example configurations for `STCP` proxy and visitor in `conf/frpc_full_example.toml`. - Add example configurations for `STCP` proxy and visitor in `conf/legacy/frpc_legacy_full.ini`. * **Configuration Structures** - Add `STCPProxyConfig` struct and include it in the `proxyConfigTypeMap` in `pkg/config/v1/proxy.go`. - Add `STCPVisitorConfig` struct and include it in the `visitorConfigTypeMap` in `pkg/config/v1/visitor.go`. * **Configuration Validation** - Add validation for `STCPProxyConfig` in `pkg/config/v1/validation/proxy.go`. - Add validation for `STCPVisitorConfig` in `pkg/config/v1/validation/visitor.go`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/fatedier/frp?shareId=XXXX-XXXX-XXXX-XXXX).
49 lines
979 B
Go
49 lines
979 B
Go
package validation
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"slices"
|
|
|
|
v1 "github.com/fatedier/frp/pkg/config/v1"
|
|
)
|
|
|
|
func ValidateVisitorConfigurer(c v1.VisitorConfigurer) error {
|
|
base := c.GetBaseConfig()
|
|
if err := validateVisitorBaseConfig(base); err != nil {
|
|
return err
|
|
}
|
|
|
|
switch v := c.(type) {
|
|
case *v1.STCPVisitorConfig:
|
|
case *v1.SUDPVisitorConfig:
|
|
case *v1.XTCPVisitorConfig:
|
|
return validateXTCPVisitorConfig(v)
|
|
default:
|
|
return errors.New("unknown visitor config type")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateVisitorBaseConfig(c *v1.VisitorBaseConfig) error {
|
|
if c.Name == "" {
|
|
return errors.New("name is required")
|
|
}
|
|
|
|
if c.ServerName == "" {
|
|
return errors.New("server name is required")
|
|
}
|
|
|
|
if c.BindPort == 0 {
|
|
return errors.New("bind port is required")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateXTCPVisitorConfig(c *v1.XTCPVisitorConfig) error {
|
|
if !slices.Contains([]string{"kcp", "quic"}, c.Protocol) {
|
|
return fmt.Errorf("protocol should be kcp or quic")
|
|
}
|
|
return nil
|
|
}
|