server

package
v0.0.0-...-c01f1ba Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSFCapacity = 1e6
	// FalsePositiveRate
	DefaultSFFPR  = 1e-6
	DefaultSFSlot = 10
)

Those suggest value are all set according to https://github.com/shadowsocks/shadowsocks-org/issues/44#issuecomment-281021054 Due to this package contains various internal implementation so const named with DefaultBR prefix

View Source
const EnvironmentPrefix = "SHADOWSOCKS_"

Variables

View Source
var ErrCipherNotSupported = errors.New("cipher not supported")

ErrCipherNotSupported occurs when a cipher is not supported (likely because of security concerns).

View Source
var ErrRepeatedSalt = errors.New("repeated salt detected")

ErrRepeatedSalt means detected a reused salt

View Source
var ErrShortPacket = errors.New("short packet")

ErrShortPacket means that the packet is too short for a valid encrypted packet.

Functions

func AddSalt

func AddSalt(b []byte)

AddSalt salt to filter

func CheckSalt

func CheckSalt(b []byte) bool

func ListCipher

func ListCipher() []string

ListCipher returns a list of available cipher names sorted alphabetically.

func NewConn

func NewConn(c net.Conn, ciph Cipher, u *User) net.Conn

NewConn wraps a stream-oriented net.Conn with cipher.

func NewPacketConn

func NewPacketConn(c net.PacketConn, ciph Cipher, u *User) net.PacketConn

NewPacketConn wraps a net.PacketConn with cipher

func NewReader

func NewReader(r io.Reader, aead cipher.AEAD, u *User) io.Reader

NewReader wraps an io.Reader with AEAD decryption.

func NewWriter

func NewWriter(w io.Writer, aead cipher.AEAD, u *User) io.Writer

NewWriter wraps an io.Writer with AEAD encryption.

func Pack

func Pack(dst, plaintext []byte, ciph Cipher) ([]byte, error)

Pack encrypts plaintext using Cipher with a randomly generated salt and returns a slice of dst containing the encrypted packet and any error occurred. Ensure len(dst) >= ciph.SaltSize() + len(plaintext) + aead.Overhead().

func PickCipher

func PickCipher(name string, key []byte, password string, u *User) (*aeadCipher, error)

PickCipher returns a Cipher of the given name. Derive key from password if given key is empty.

func TestSalt

func TestSalt(b []byte) bool

TestSalt returns true if salt is repeated

func Unpack

func Unpack(dst, pkt []byte, ciph Cipher) ([]byte, error)

Unpack decrypts pkt using Cipher and returns a slice of dst containing the decrypted payload and any error occurred. Ensure len(dst) >= len(pkt) - aead.SaltSize() - aead.Overhead().

Types

type BloomRing

type BloomRing struct {
	// contains filtered or unexported fields
}

func NewBloomRing

func NewBloomRing(slot, capacity int, falsePositiveRate float64) *BloomRing

func (*BloomRing) Add

func (r *BloomRing) Add(b []byte)

func (*BloomRing) Check

func (r *BloomRing) Check(b []byte) bool

func (*BloomRing) Test

func (r *BloomRing) Test(b []byte) bool

type Cipher

type Cipher interface {
	KeySize() int
	SaltSize() int
	Encrypter(salt []byte) (cipher.AEAD, error)
	Decrypter(salt []byte) (cipher.AEAD, error)
}

func AESGCM

func AESGCM(psk []byte) (Cipher, error)

AESGCM creates a new Cipher with a pre-shared key. len(psk) must be one of 16, 24, or 32 to select AES-128/196/256-GCM.

func Chacha20Poly1305

func Chacha20Poly1305(psk []byte) (Cipher, error)

Chacha20Poly1305 creates a new Cipher with a pre-shared key. len(psk) must be 32.

type KeySizeError

type KeySizeError int

func (KeySizeError) Error

func (e KeySizeError) Error() string

type User

type User struct {
	Traffic       uint64
	UsedMilliTime int64
	Signal        chan struct{}
	// contains filtered or unexported fields
}

func New

func New(cipher, addr, password string) (*User, error)

func (*User) AddToTime

func (u *User) AddToTime(MilliTime int64)

func (*User) AddToTraffic

func (u *User) AddToTraffic(traffic int64)

just keep it for futher uses

func (*User) AddToTrafficInt

func (u *User) AddToTrafficInt(traffic int)

func (*User) Get

func (u *User) Get() (uint64, int64)

func (*User) GetTraffic

func (u *User) GetTraffic() uint64

func (*User) GetUsedTime

func (u *User) GetUsedTime() int64

func (*User) NewServer

func (u *User) NewServer(userSignal chan struct{}, cipher, addr, password string)

func (*User) Reset

func (u *User) Reset()

These methods are THREAD-SAFE. Nevermind using them.

func (*User) ResetTime

func (u *User) ResetTime()

func (*User) ResetTraffic

func (u *User) ResetTraffic()

func (*User) Set

func (u *User) Set(traffic uint64, usedtime int64)

func (*User) Shutdown

func (u *User) Shutdown()

Jump to

Keyboard shortcuts

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