shadowsocks

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = 1
)

Variables

This section is empty.

Functions

func DecodeUDPPacket

func DecodeUDPPacket(account *MemoryAccount, payload *buf.Buffer) (*protocol.RequestHeader, *buf.Buffer, error)

func EncodeUDPPacket

func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buffer, error)

func ReadTCPResponse

func ReadTCPResponse(account *MemoryAccount, reader io.Reader) (buf.Reader, error)

func ReadTCPResponseIO

func ReadTCPResponseIO(account *MemoryAccount, reader io.Reader) (io.Reader, error)

func ReadTCPSession

func ReadTCPSession(account *MemoryAccount, reader io.Reader, drainOnError bool) (*protocol.RequestHeader, buf.Reader, error)

ReadTCPSession reads a Shadowsocks TCP session from the given reader, returns its header and remaining parts.

func WriteTCPRequest

func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Writer, error)

WriteTCPRequest writes Shadowsocks request into the given writer, and returns a writer for body.

func WriteTCPRequestIO

func WriteTCPRequestIO(request *protocol.RequestHeader, writer io.Writer) (io.Writer, error)

WriteTCPRequest writes Shadowsocks request into the given writer, and returns a writer for body.

func WriteTCPResponse

func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (buf.Writer, error)

Types

type AEADCipher

type AEADCipher struct {
	KeyBytes        int32
	IVBytes         int32
	AEADAuthCreator func(key []byte) cipher.AEAD
}

func (*AEADCipher) DecodePacket

func (c *AEADCipher) DecodePacket(key []byte, b *buf.Buffer) error

func (*AEADCipher) EncodePacket

func (c *AEADCipher) EncodePacket(key []byte, b *buf.Buffer) error

func (*AEADCipher) IVSize

func (c *AEADCipher) IVSize() int32

func (*AEADCipher) IsAEAD

func (*AEADCipher) IsAEAD() bool

func (*AEADCipher) KeySize

func (c *AEADCipher) KeySize() int32

func (*AEADCipher) NewDecryptionReader

func (c *AEADCipher) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)

func (*AEADCipher) NewDecryptionReaderIO

func (c *AEADCipher) NewDecryptionReaderIO(key []byte, iv []byte, reader io.Reader) (io.Reader, error)

func (*AEADCipher) NewEncryptionWriter

func (c *AEADCipher) NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)

func (*AEADCipher) NewEncryptionWriterIO

func (c *AEADCipher) NewEncryptionWriterIO(key []byte, iv []byte, writer io.Writer) (io.Writer, error)

type Cipher

type Cipher interface {
	KeySize() int32
	IVSize() int32
	NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)
	NewEncryptionWriterIO(key []byte, iv []byte, writer io.Writer) (io.Writer, error)
	NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)
	NewDecryptionReaderIO(key []byte, iv []byte, reader io.Reader) (io.Reader, error)
	IsAEAD() bool
	EncodePacket(key []byte, b *buf.Buffer) error
	DecodePacket(key []byte, b *buf.Buffer) error
}

Cipher is an interface for all Shadowsocks ciphers.

type CipherType

type CipherType int32
const (
	CipherType_AES_128_GCM       CipherType = 0
	CipherType_AES_256_GCM       CipherType = 1
	CipherType_CHACHA20_POLY1305 CipherType = 2
	CipherType_NONE              CipherType = 3
)

type Client

type Client struct {
	ClientSettings
}

Client is a inbound handler for Shadowsocks protocol

func NewClient

func NewClient(settings *ClientSettings) *Client

NewClient create a new Shadowsocks client.

func (*Client) HandleFlow

func (c *Client) HandleFlow(ctx context.Context, dst net.Destination, rw buf.ReaderWriter) error

func (*Client) HandlePacketConn

func (c *Client) HandlePacketConn(ctx context.Context, dst net.Destination, p udp.PacketReaderWriter) error

func (*Client) ListenPacket

func (c *Client) ListenPacket(ctx context.Context, dst net.Destination) (udp.UdpConn, error)

func (*Client) ProxyDial

func (c *Client) ProxyDial(ctx context.Context, dst net.Destination,
	initialData buf.MultiBuffer) (i.FlowConn, error)

type ClientSettings

type ClientSettings struct {
	Address    net.Address
	PortPicker i.PortSelector
	Account    *MemoryAccount
	Dialer     i.Dialer
}

type MemoryAccount

type MemoryAccount struct {
	Cipher           Cipher
	Key              []byte
	Uid              string
	ReplayFilter     antireplay.GeneralizedReplayFilter
	ReducedIVEntropy bool
}

MemoryAccount is an account type converted from Account.

func NewMemoryAccount

func NewMemoryAccount(uid string, cipher CipherType, password string,
	reducedIVEntropy, ivCheck bool) (*MemoryAccount, error)

func (*MemoryAccount) CheckIV

func (a *MemoryAccount) CheckIV(iv []byte) error

func (*MemoryAccount) Equals

func (a *MemoryAccount) Equals(another protocol.Account) bool

Equals implements protocol.Account.Equals().

type NoneCipher

type NoneCipher struct{}

func (NoneCipher) DecodePacket

func (NoneCipher) DecodePacket(key []byte, b *buf.Buffer) error

func (NoneCipher) EncodePacket

func (NoneCipher) EncodePacket(key []byte, b *buf.Buffer) error

func (NoneCipher) IVSize

func (NoneCipher) IVSize() int32

func (NoneCipher) IsAEAD

func (NoneCipher) IsAEAD() bool

func (NoneCipher) KeySize

func (NoneCipher) KeySize() int32

func (NoneCipher) NewDecryptionReader

func (NoneCipher) NewDecryptionReader(key []byte, iv []byte, reader io.Reader) (buf.Reader, error)

func (NoneCipher) NewDecryptionReaderIO

func (NoneCipher) NewDecryptionReaderIO(key []byte, iv []byte, reader io.Reader) (io.Reader, error)

func (NoneCipher) NewEncryptionWriter

func (NoneCipher) NewEncryptionWriter(key []byte, iv []byte, writer io.Writer) (buf.Writer, error)

func (NoneCipher) NewEncryptionWriterIO

func (NoneCipher) NewEncryptionWriterIO(key []byte, iv []byte, writer io.Writer) (io.Writer, error)

type UDPReader

type UDPReader struct {
	Reader io.Reader
	User   *MemoryAccount
}

func (*UDPReader) Read

func (v *UDPReader) Read(p []byte) (n int, err error)

func (*UDPReader) ReadMultiBuffer

func (v *UDPReader) ReadMultiBuffer() (buf.MultiBuffer, error)

func (*UDPReader) ReadPacket

func (v *UDPReader) ReadPacket() (*udp.Packet, error)

type UDPWriter

type UDPWriter struct {
	Writer  io.Writer
	Request *protocol.RequestHeader
}

func (*UDPWriter) Write

func (w *UDPWriter) Write(payload []byte) (int, error)

Write implements io.Writer.

func (*UDPWriter) WritePacket

func (w *UDPWriter) WritePacket(packet *udp.Packet) error

func (*UDPWriter) WriteTo

func (w *UDPWriter) WriteTo(payload []byte, addr net.Addr) (n int, err error)

Jump to

Keyboard shortcuts

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