Documentation
¶
Index ¶
- Constants
- Variables
- func GetEnv(name, def string) string
- func SecFromEnv(name string, defVal uint64) time.Duration
- type Backend
- type BackendCheckConfig
- type Configure
- type Pool
- type Server
- func (s *Server) AddBackend() error
- func (s *Server) Engine() *gin.Engine
- func (s *Server) ListenHTTPAdmin(addr string) (err error)
- func (s *Server) ListenSocks5(addr string) (err error)
- func (s *Server) ListenTProxy(addr string) (err error)
- func (s *Server) Start() (err error)
- func (s *Server) Stop() (e error)
- func (s *Server) Transport(dst, src io.ReadWriter) (err error)
- type ServerConfig
- type Status
Constants ¶
const ( // DefaultDialTimeout is the default timeout for dialing backend connections DefaultDialTimeout = 10 * time.Second // DefaultKeepAlivePeriod is the interval for TCP keepalive probes DefaultKeepAlivePeriod = 30 * time.Second )
const AppName = "socks5lb"
const ( // BufferSize defines the size of buffers used for copying data between connections BufferSize = 32 * 1024 // 32KB buffer for better performance )
const (
// DefaultCheckTimeout is the default timeout for health checks
DefaultCheckTimeout = 10
)
Variables ¶
var ( Version = "n/a" BuildCommit = "n/a" BuildDate = "n/a" DebugMode = false StartTime time.Time )
Functions ¶
Types ¶
type Backend ¶
type Backend struct {
Addr string `yaml:"addr" json:"addr" binding:"required"`
UserName string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
CheckConfig BackendCheckConfig `yaml:"check_config" json:"check_config"`
// contains filtered or unexported fields
}
func NewBackend ¶
func NewBackend(addr string, config BackendCheckConfig) (backend *Backend)
NewBackend creates a new Backend instance with the specified configuration
func (*Backend) Alive ¶
Alive returns the current health status of the backend Uses atomic operation for thread-safe read
func (*Backend) Check ¶
Check performs health check on the backend by testing connectivity Returns error if the backend is not reachable or unhealthy
type BackendCheckConfig ¶
type Configure ¶
type Configure struct {
ServerConfig ServerConfig `yaml:"server"`
Backends []Backend `yaml:"backends"`
}
Configure represents the complete application configuration
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func (*Pool) AllHealthy ¶
AllHealthy returns all healthy backends from the pool
func (*Pool) Check ¶
func (b *Pool) Check()
Check performs health checks on all backends in the pool
func (*Pool) Next ¶
Next returns the next available healthy backend using round-robin algorithm Returns nil if no healthy backend is available
type Server ¶
type Server struct {
Pool *Pool
Config *ServerConfig
// contains filtered or unexported fields
}
Server represents the main SOCKS5 load balancer server
func NewServer ¶
func NewServer(pool *Pool, config ServerConfig) (*Server, error)
NewServer creates a new Server instance with the given pool and configuration
func (*Server) AddBackend ¶
AddBackend adds a new backend to the server's pool TODO: Implementation needed
func (*Server) ListenHTTPAdmin ¶
ListenHTTPAdmin starts the HTTP administration server
func (*Server) ListenSocks5 ¶
ListenSocks5 listens on a specific address and handles SOCKS5 connections
func (*Server) ListenTProxy ¶
ListenTProxy is listening the local tcp port on the given address Deprecated: this feature will be disabled in the future
func (*Server) Start ¶
Start initializes and starts all server components - Health check timer for periodic backend monitoring - HTTP admin interface (if configured) - SOCKS5 proxy listener
type ServerConfig ¶
type ServerConfig struct {
// HTTP admin interface configuration
HTTP struct {
Addr string `yaml:"addr"`
} `yaml:"http"`
// TProxy transparent proxy configuration (not yet implemented)
TProxy struct {
Addr string `yaml:"addr"`
} `yaml:"tproxy"`
// Sock5 SOCKS5 proxy configuration
Sock5 struct {
Addr string `yaml:"addr"`
} `yaml:"socks5"`
}
ServerConfig holds the configuration for all server components
