Documentation ¶
Index ¶
- Constants
- Variables
- func AddSalt(b []byte)
- func CheckSalt(b []byte) bool
- func ListCipher() []string
- func NewConn(c net.Conn, ciph Cipher, u *User) net.Conn
- func NewPacketConn(c net.PacketConn, ciph Cipher, u *User) net.PacketConn
- func NewReader(r io.Reader, aead cipher.AEAD, u *User) io.Reader
- func NewWriter(w io.Writer, aead cipher.AEAD, u *User) io.Writer
- func Pack(dst, plaintext []byte, ciph Cipher) ([]byte, error)
- func PickCipher(name string, key []byte, password string, u *User) (*aeadCipher, error)
- func TestSalt(b []byte) bool
- func Unpack(dst, pkt []byte, ciph Cipher) ([]byte, error)
- type BloomRing
- type Cipher
- type KeySizeError
- type User
- func (u *User) AddToTime(MilliTime int64)
- func (u *User) AddToTraffic(traffic int64)
- func (u *User) AddToTrafficInt(traffic int)
- func (u *User) Get() (uint64, int64)
- func (u *User) GetTraffic() uint64
- func (u *User) GetUsedTime() int64
- func (u *User) NewServer(userSignal chan struct{}, cipher, addr, password string)
- func (u *User) Reset()
- func (u *User) ResetTime()
- func (u *User) ResetTraffic()
- func (u *User) Set(traffic uint64, usedtime int64)
- func (u *User) Shutdown()
Constants ¶
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
const EnvironmentPrefix = "SHADOWSOCKS_"
Variables ¶
var ErrCipherNotSupported = errors.New("cipher not supported")
ErrCipherNotSupported occurs when a cipher is not supported (likely because of security concerns).
var ErrRepeatedSalt = errors.New("repeated salt detected")
ErrRepeatedSalt means detected a reused salt
var ErrShortPacket = errors.New("short packet")
ErrShortPacket means that the packet is too short for a valid encrypted packet.
Functions ¶
func ListCipher ¶
func ListCipher() []string
ListCipher returns a list of available cipher names sorted alphabetically.
func NewPacketConn ¶
func NewPacketConn(c net.PacketConn, ciph Cipher, u *User) net.PacketConn
NewPacketConn wraps a net.PacketConn with cipher
func Pack ¶
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 ¶
PickCipher returns a Cipher of the given name. Derive key from password if given key is empty.
Types ¶
type BloomRing ¶
type BloomRing struct {
// contains filtered or unexported fields
}
func NewBloomRing ¶
type Cipher ¶
type Cipher interface { KeySize() int SaltSize() int Encrypter(salt []byte) (cipher.AEAD, error) Decrypter(salt []byte) (cipher.AEAD, error) }
func AESGCM ¶
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 ¶
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 (*User) AddToTrafficInt ¶
func (*User) GetTraffic ¶
func (*User) GetUsedTime ¶
func (*User) ResetTraffic ¶
func (u *User) ResetTraffic()