socks

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

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

View Source
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

func (c *Conn) GetHandshakeComplete() bool

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

func (c *Conn) Handshake() error

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

func (c *Conn) HandshakeContext(ctx context.Context) error

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

func (c *Conn) Read(b []byte) (int, error)

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.

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write writes data to the connection. If the handshake is not complete, it performs the handshake before writing.

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

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.

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

Accept waits for and returns the next connection to the listener. It performs the SOCKS5 handshake before returning the connection.

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

type ServerCredentials map[string]string

ServerCredentials is a map that stores username-password pairs for authentication.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL