Documentation
¶
Overview ¶
Package socks implements the SOCKS5 proxy protocol.
Package socks implements the SOCKS protocol for network connections.
Package socks implements the SOCKS5 protocol for proxying TCP connections.
Package socks implements the SOCKS protocol for network communication.
Package socks implements the server side SOCKS5 proxy protocol.
Index ¶
- Constants
- type Conn
- func (c *Conn) GetHandshakeComplete() bool
- func (c *Conn) GetHandshakeResult() (protocol.AddressHeader, error)
- func (c *Conn) Handshake() error
- func (c *Conn) HandshakeContext(ctx context.Context) error
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) SetHandshakeComplete()
- func (c *Conn) Write(b []byte) (int, error)
- type Listener
- type ServerConfig
- type ServerCredentials
Constants ¶
const (
MaxInitialGreetingSize = 1 + 1 + 256 // Max size of initial greeting
)
Constants for SOCKS5 protocol
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { // Embed the standard net.Conn interface to inherit its methods net.Conn // contains filtered or unexported fields }
Conn represents a SOCKS connection. Conn represents a SOCKS connection.
func (*Conn) GetHandshakeComplete ¶
GetHandshakeComplete returns the current handshake completion status. It returns true if the handshake has been completed, false otherwise. This method uses atomic operations to ensure thread-safe access to the completion status.
Returns:
- bool: True if the handshake is complete, false otherwise.
func (*Conn) GetHandshakeResult ¶
func (c *Conn) GetHandshakeResult() (protocol.AddressHeader, error)
GetHandshakeResult returns the address header from the request after completing the handshake. If the handshake is not complete, it performs the handshake before returning the result.
func (*Conn) Handshake ¶
Handshake initiates the SOCKS handshake process. It's a convenience method that calls HandshakeContext with a background context. This method is useful when you don't need to specify a custom context for cancellation or timeout.
Returns:
- error: Any error encountered during the handshake process.
func (*Conn) HandshakeContext ¶
HandshakeContext initiates the SOCKS handshake process with a given context. The context allows for cancellation and timeout control of the handshake process. This method is useful when you need fine-grained control over the handshake process, such as setting a timeout or allowing for cancellation.
Parameters:
- ctx: A context.Context for controlling the handshake process.
Returns:
- error: Any error encountered during the handshake process.
func (*Conn) Read ¶
Read reads data from the connection. If the handshake is not complete, it performs the handshake before reading.
func (*Conn) SetHandshakeComplete ¶
func (c *Conn) SetHandshakeComplete()
SetHandshakeComplete marks the handshake as complete. This method is used to indicate that the SOCKS handshake process has finished successfully. It sets an atomic boolean flag to true, ensuring thread-safe access.
type Listener ¶
Listener wraps a net.Listener and associates it with a ServerConfig.
func NewListener ¶
func NewListener(laddr string, config *ServerConfig) (*Listener, error)
NewListener creates a new TCP listener with the given local address and ServerConfig.
func NewWrapListener ¶
func NewWrapListener(inner net.Listener, config *ServerConfig) *Listener
NewWrapListener wraps an existing net.Listener with a ServerConfig.
type ServerConfig ¶
type ServerConfig struct {
// contains filtered or unexported fields
}
ServerConfig holds the configuration for the SOCKS5 server.
func NewServerConfig ¶
func NewServerConfig(credentials ServerCredentials, handshakeTimeout int) *ServerConfig
NewServerConfig creates and returns a new ServerConfig with the given credentials and handshake timeout.
type ServerCredentials ¶
ServerCredentials is a map that stores username-password pairs for authentication.