Documentation ¶
Index ¶
- Constants
- Variables
- func AEADBlockCipher(preSharedKey, salt []byte) (cipher.AEAD, error)
- func CopyWithTimeout(destConn net.PacketConn, client net.Addr, srv net.PacketConn) error
- func DecryptUDPPacket(n int, buf []byte, derivedPassword []byte) (int, error)
- func GetDerivedKey(password string) []byte
- func IncreaseNounce(nounceBuf []byte)
- func IsReservedAddr(addr net.IP) bool
- func ListenPacket(network, address string, handleFunc func(net.PacketConn) net.PacketConn) (net.PacketConn, error)
- func PipeTCPConnection(src, dest net.Conn, doWriteRand bool)
- func RandNum(absMin, variableLower, randMore int) int
- func RandomText(length int) string
- func ReadWithRetry(conn net.Conn, buf []byte) (n int, err error)
- func TestSockd(sockd *Daemon, t testingstub.T)
- func WriteRandomToTCP(conn net.Conn) (totalBytes int)
- func WriteRandomToUDP(srv *net.UDPConn, client *net.UDPAddr) (totalBytes int)
- func WriteWithRetry(conn net.Conn, buf []byte) (totalWritten int, err error)
- type Daemon
- type EncryptedReader
- type EncryptedTCPConn
- func (conn *EncryptedTCPConn) Initialise() error
- func (conn *EncryptedTCPConn) InitialiseWriter() error
- func (conn *EncryptedTCPConn) Read(buf []byte) (int, error)
- func (conn *EncryptedTCPConn) ReadFrom(reader io.Reader) (int64, error)
- func (conn *EncryptedTCPConn) Write(buf []byte) (int, error)
- func (conn *EncryptedTCPConn) WriteTo(writer io.Writer) (int64, error)
- type EncryptedUDPConn
- type EncryptedWriter
- type SocksDestAddr
- type TCPDaemon
- type UDPBacklog
- type UDPDaemon
- func (daemon *UDPDaemon) GetUDPStatsCollector() *misc.Stats
- func (daemon *UDPDaemon) HandleUDPClient(logger *lalog.Logger, ip string, client *net.UDPAddr, packet []byte, ...)
- func (daemon *UDPDaemon) Initialise() error
- func (daemon *UDPDaemon) StartAndBlock() error
- func (daemon *UDPDaemon) Stop()
- func (daemon *UDPDaemon) WriteRand(server net.PacketConn, dest net.Addr)
Constants ¶
const ( IOTimeout = 120 * time.Second PayloadSizeMask = 16*1024 - 1 LenPayloadSize = 2 LenDerivedPassword = 32 MaxPacketSize = 64 * 1024 MagicKeyDerivationInfo = "ss-subkey" ProxyDestAddrTypeV4 = 1 ProxyDestAddrTypeName = 3 ProxyDestAddrTypeV6 = 4 LenProxyConnectRequest = 1 + 1 + 1 + 254 + 2 )
Variables ¶
var ( ZeroBytes [128]byte RandSeed = int(time.Now().UnixNano()) BlockedReservedCIDR = []net.IPNet{ {IP: net.IPv4(0, 0, 0, 0), Mask: net.CIDRMask(32, 32)}, {IP: net.IPv4(10, 0, 0, 0), Mask: net.CIDRMask(8, 32)}, {IP: net.IPv4(100, 64, 0, 0), Mask: net.CIDRMask(10, 32)}, {IP: net.IPv4(127, 0, 0, 0), Mask: net.CIDRMask(8, 32)}, {IP: net.IPv4(169, 254, 0, 0), Mask: net.CIDRMask(16, 32)}, {IP: net.IPv4(172, 16, 0, 0), Mask: net.CIDRMask(12, 32)}, {IP: net.IPv4(192, 0, 0, 0), Mask: net.CIDRMask(24, 32)}, {IP: net.IPv4(192, 0, 2, 0), Mask: net.CIDRMask(24, 32)}, {IP: net.IPv4(192, 168, 0, 0), Mask: net.CIDRMask(16, 32)}, {IP: net.IPv4(198, 18, 0, 0), Mask: net.CIDRMask(15, 32)}, {IP: net.IPv4(198, 51, 100, 0), Mask: net.CIDRMask(24, 32)}, {IP: net.IPv4(203, 0, 113, 0), Mask: net.CIDRMask(24, 32)}, {IP: net.IPv4(240, 0, 0, 0), Mask: net.CIDRMask(4, 32)}, } ErrMalformedPacket = errors.New("received a malformed packet") )
Functions ¶
func CopyWithTimeout ¶
func CopyWithTimeout(destConn net.PacketConn, client net.Addr, srv net.PacketConn) error
func DecryptUDPPacket ¶
func GetDerivedKey ¶
func IncreaseNounce ¶
func IncreaseNounce(nounceBuf []byte)
func IsReservedAddr ¶
func ListenPacket ¶
func ListenPacket(network, address string, handleFunc func(net.PacketConn) net.PacketConn) (net.PacketConn, error)
func PipeTCPConnection ¶
PipeTCPConnection receives data from the first connection and copies the data into the second connection. The function returns after the first connection is closed or other IO error occurs, and before returning the function closes the second connection and optionally writes a random amount of data into the supposedly already terminated first connection.
func RandomText ¶
RandomText returns a string consisting of letters and spaces only.
func ReadWithRetry ¶
ReadWithRetry makes at most 3 attempts to read incoming data from the connection. If an IO error occurs, the connection will be closed.
func TestSockd ¶
func TestSockd(sockd *Daemon, t testingstub.T)
func WriteRandomToTCP ¶
WriteRandomToTCP writes a random amount of data (up to couple of KB) to the connection.
func WriteRandomToUDP ¶
Types ¶
type Daemon ¶
type Daemon struct { Address string `json:"Address"` Password string `json:"Password"` PerIPLimit int `json:"PerIPLimit"` TCPPorts []int `json:"TCPPorts"` UDPPorts []int `json:"UDPPorts"` // DNSDaemon is an initialised DNS daemon. It must not be nil. DNSDaemon *dnsd.Daemon `json:"-"` // contains filtered or unexported fields }
Daemon is intentionally undocumented magic ^____^
func (*Daemon) Initialise ¶
func (*Daemon) StartAndBlock ¶
type EncryptedReader ¶
func NewEncryptedReader ¶
func NewEncryptedReader(reader io.Reader, blockCipher cipher.AEAD) *EncryptedReader
type EncryptedTCPConn ¶
type EncryptedTCPConn struct { net.Conn DerivedPassword []byte // contains filtered or unexported fields }
func (*EncryptedTCPConn) Initialise ¶
func (conn *EncryptedTCPConn) Initialise() error
func (*EncryptedTCPConn) InitialiseWriter ¶
func (conn *EncryptedTCPConn) InitialiseWriter() error
type EncryptedUDPConn ¶
type EncryptedUDPConn struct { net.PacketConn DerivedPassword []byte sync.Mutex // contains filtered or unexported fields }
type EncryptedWriter ¶
func NewEncryptedWriter ¶
func NewEncryptedWriter(writer io.Writer, blockCipher cipher.AEAD) *EncryptedWriter
type SocksDestAddr ¶
type SocksDestAddr []byte
func GetSocksAddr ¶
func GetSocksAddr(netAddr net.Addr) SocksDestAddr
func ParseDestAddr ¶
func ParseDestAddr(buf []byte) SocksDestAddr
func ReadProxyDestAddr ¶
func ReadProxyDestAddr(client io.Reader, destWithPort []byte) (addr SocksDestAddr, err error)
func (SocksDestAddr) HostPort ¶
func (addr SocksDestAddr) HostPort() (nameOrIP string, port int)
type TCPDaemon ¶
type TCPDaemon struct { Address string `json:"Address"` Password string `json:"Password"` PerIPLimit int `json:"PerIPLimit"` TCPPort int `json:"TCPPort"` DNSDaemon *dnsd.Daemon `json:"-"` // it is assumed to be already initialised // contains filtered or unexported fields }
func (*TCPDaemon) GetTCPStatsCollector ¶
func (*TCPDaemon) HandleTCPConnection ¶
func (*TCPDaemon) Initialise ¶
func (*TCPDaemon) StartAndBlock ¶
type UDPBacklog ¶
func (*UDPBacklog) Add ¶
func (backlog *UDPBacklog) Add(client net.Addr, dest, srv net.PacketConn)
func (*UDPBacklog) Delete ¶
func (backlog *UDPBacklog) Delete(addr string) net.PacketConn
func (*UDPBacklog) Get ¶
func (backlog *UDPBacklog) Get(addr string) net.PacketConn
type UDPDaemon ¶
type UDPDaemon struct { Address string Password string PerIPLimit int UDPPort int DNSDaemon *dnsd.Daemon // contains filtered or unexported fields }