snell

package module
v0.0.0-...-a3b2677 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: GPL-2.0 Imports: 21 Imported by: 0

README

sing-snell

This fork uses github.com/metacubex/sing buffers, addresses and network interfaces. Import it as github.com/Ember-Moth/sing-snell. Request completion callbacks and optional vectorised/batch writer discovery are owned by this package; they do not require SagerNet/sing.

Surge snell implemented in Go.

Features

  • All complete features except the v5 QUIC proxy.
  • Behavior as consistent with the official implementation as possible.
  • Performance at least on par with the official implementation.

Why

Surge believes that being closed-source and not proliferated can keep this protocol covert, but this is already impossible in 2026. Considering that snell still has advantages that other random-traffic protocols do not possess, such as multiplexing support with complete TCP semantics and traffic-characteristic diversity, we made this instead of reinventing the wheel.

Documentation

Index

Constants

View Source
const (
	// Surge 6.4.4 (10661): -[SNObfsHelperHTTP initWithPolicy:] and -[SGObfsHelperTLS initWithPolicy:]
	// substitute these constants when the policy carries no obfs-host / obfs-uri.
	DefaultObfsHost    = "bing.com"
	DefaultObfsURI     = "/"
	DefaultTLSObfsHost = "cloudfront.net"
)
View Source
const (
	HeaderVersion   = 0x04
	HeaderPlainLen  = 7
	AEADTagLen      = 16
	HeaderCipherLen = HeaderPlainLen + AEADTagLen
	SaltLen         = 16
	NonceLen        = 12
	MaxPayloadLen   = 0x3fff
)
View Source
const (
	CommandPing      = 0x00
	CommandConnect   = 0x01
	CommandConnectV2 = 0x05
	CommandUDP       = 0x06
)
View Source
const (
	ReplyTunnel = 0x00
	ReplyPong   = 0x01
	ReplyError  = 0x02
)
View Source
const (
	UDPCommandForward = 0x01
	AddressTypeIPv4   = 0x04
	AddressTypeIPv6   = 0x06
)
View Source
const RequestVersion = 0x01

Variables

View Source
var (
	ErrBadVersion         = E.New("snell: bad header version")
	ErrReservedNonZero    = E.New("snell: reserved header octet is non-zero")
	ErrPayloadTooLarge    = E.New("snell: payload length exceeds maximum")
	ErrUnsupportedCommand = E.New("snell: unsupported command")
	ErrUnexpectedReply    = E.New("snell: unexpected reply opcode")
	ErrMissingPSK         = E.New("snell: missing pre-shared key")
	ErrNoUsers            = E.New("snell: no users")
	ErrBadUserKey         = E.New("snell: bad user key")
	ErrDuplicateUserKey   = E.New("snell: duplicate user key")
)

Functions

func ContextWithKeepSession

func ContextWithKeepSession(ctx context.Context) context.Context

func CreateVectorisedWriter

func CreateVectorisedWriter(writer any) (N.VectorisedWriter, bool)

CreateVectorisedWriter preserves Snell's lazy record writer while using MetaCubeX/sing for buffers and the underlying scatter/gather implementation.

func DeriveKey

func DeriveKey(psk []byte, salt []byte) []byte

Surge 6.7.0 (11520): FUN_1000123d0: AEAD keys are derived with these Argon2id parameters.

func IncreaseNonce

func IncreaseNonce(nonce []byte)

Surge 6.7.0 (11520): FUN_100012944: nonce is u64le(counter) || 0x00000000.

func KeepSessionFromContext

func KeepSessionFromContext(ctx context.Context) bool

func NewAEAD

func NewAEAD(key []byte) (cipher.AEAD, error)

func ReadConnectAddress

func ReadConnectAddress(reader io.Reader) (M.Socksaddr, error)

func ReadServerError

func ReadServerError(record *buf.Buffer) error

func ReadUDPRequestAddress

func ReadUDPRequestAddress(buffer *buf.Buffer) (M.Socksaddr, error)

func ReadUDPResponseAddress

func ReadUDPResponseAddress(buffer *buf.Buffer) (M.Socksaddr, error)

func WriteConnectAddress

func WriteConnectAddress(buffer *buf.Buffer, destination M.Socksaddr) error

Surge 6.7.0 (11520): SNConnectorV4::targetHandshakeData: CONNECT targets are host strings even for literal IPs.

func WriteUDPRequestAddress

func WriteUDPRequestAddress(buffer *buf.Buffer, destination M.Socksaddr) error

func WriteUDPResponseAddress

func WriteUDPResponseAddress(buffer *buf.Buffer, source M.Socksaddr) error

snell-server v6.0.0b4: FUN_001431c0: UDP response sources are emitted as literal IPs only.

Types

type CloseHandlerFunc

type CloseHandlerFunc = func(error)

CloseHandlerFunc completes a logical request, which may share a reusable transport. Closing the transport is not a substitute for this callback.

type Handler

type Handler interface {
	NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose CloseHandlerFunc)
	NewPacketConnectionEx(ctx context.Context, conn N.PacketConn, source M.Socksaddr, destination M.Socksaddr, onClose CloseHandlerFunc)
}

type Method

type Method interface {
	DialConn(conn net.Conn, destination M.Socksaddr) (net.Conn, error)
	DialEarlyConn(conn net.Conn, destination M.Socksaddr) net.Conn
	DialPacketConn(conn net.Conn) (N.NetPacketConn, error)
}

type ObfsConfig

type ObfsConfig struct {
	Mode ObfsMode
	Host string
	URI  string
}

func (ObfsConfig) ClientConn

func (c ObfsConfig) ClientConn(conn net.Conn) net.Conn

func (ObfsConfig) ServerConn

func (c ObfsConfig) ServerConn(conn net.Conn) net.Conn

type ObfsMode

type ObfsMode int
const (
	ObfsModeNone ObfsMode = iota
	ObfsModeHTTP
	ObfsModeTLS
)

func ParseObfsMode

func ParseObfsMode(name string) (ObfsMode, error)

func (ObfsMode) String

func (m ObfsMode) String() string

type PacketBatchWriteCreator

type PacketBatchWriteCreator interface {
	CreatePacketBatchWriter() (PacketBatchWriter, bool)
}

type PacketBatchWriter

type PacketBatchWriter interface {
	WritePacketBatch(buffers []*buf.Buffer, destinations []M.Socksaddr) error
}

func CreatePacketBatchWriter

func CreatePacketBatchWriter(writer N.PacketWriter) (PacketBatchWriter, bool)

type Request

type Request struct {
	Command     byte
	ClientID    []byte
	Destination M.Socksaddr
}

func ReadRequest

func ReadRequest(reader io.Reader) (Request, error)

func (Request) Len

func (r Request) Len() int

func (Request) Write

func (r Request) Write(buffer *buf.Buffer) error

type ServerError

type ServerError struct {
	net.Conn
	Source M.Socksaddr
	Cause  error
}

snell-server v6.0.0b4: FUN_00141bc0: malformed handshakes are torn down abruptly.

func (*ServerError) Error

func (e *ServerError) Error() string

func (*ServerError) Unwrap

func (e *ServerError) Unwrap() error

type Service

type Service interface {
	NewConnection(ctx context.Context, conn net.Conn, source M.Socksaddr, onClose CloseHandlerFunc) error
}

type VectorisedWriteCreator

type VectorisedWriteCreator interface {
	CreateVectorisedWriter() (N.VectorisedWriter, bool)
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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