Documentation ¶
Index ¶
- Constants
- Variables
- func BytesSizeForMetadata(firstTwoByte []byte) (int, error)
- func CalcPaddingLen(masterKey []byte, bodyWithoutAddr []byte, req bool) (length int)
- func DecryptUDP(key Key, shadowBytes []byte) (plainText []byte, err error)
- func EVPBytesToKey(password string, keyLen int) (key []byte)
- func EncryptUDPFromPool(key Key, b []byte) (shadowBytes []byte, err error)
- func EncryptedPayloadLen(plainTextLen int, tagLen int) int
- func IPToBin(ip net.IP) string
- func LocalizePassages(passages []server.Passage) (psgs []Passage, manager *Passage)
- func MD5Sum(d []byte) []byte
- func New(sweetLisaHost config.Lisa, arg server.Argument) (server.Server, error)
- func NewGcm(key []byte) (cipher.AEAD, error)
- type CipherConf
- type IPMTUTrie
- type Key
- type Metadata
- type MetadataCmd
- type MetadataType
- type Passage
- type SSConn
- type Server
- func (s *Server) AddPassages(passages []server.Passage) (err error)
- func (s *Server) Close() error
- func (s *Server) GetOrBuildUCPConn(lAddr net.Addr, data []byte) (rc *net.UDPConn, passage *Passage, plainText []byte, err error)
- func (s *Server) GetUserContextOrInsert(userIP string) *UserContext
- func (s *Server) Listen(addr string) (err error)
- func (s *Server) ListenTCP(addr string) (err error)
- func (s *Server) ListenUDP(addr string) (err error)
- func (s *Server) Passages() (passages []server.Passage)
- func (s *Server) RemovePassages(passages []server.Passage, alsoManager bool) (err error)
- func (s *Server) SyncPassages(passages []server.Passage) (err error)
- type UDPConn
- type UDPConnMapping
- type UserContext
- type UserContextPool
Constants ¶
View Source
const ( MaxNonceSize = 12 ATypeIPv4 = 1 ATypeDomain = 3 ATypeIpv6 = 4 )
View Source
const ( // BasicLen is the basic auth length of [salt][encrypted payload length][length tag][encrypted payload][payload tag] BasicLen = 32 + 2 + 16 TCPBufferSize = 32 * 1024 )
View Source
const ( DefaultNatTimeout = 3 * time.Minute DnsQueryTimeout = 17 * time.Second // RFC 5452 )
View Source
const (
MTU = 65535
)
View Source
const (
TCPChunkMaxLen = (1 << (16 - 2)) - 1
)
Variables ¶
View Source
var ( CiphersConf = map[string]CipherConf{ "chacha20-ietf-poly1305": {KeyLen: 32, SaltLen: 32, NonceLen: 12, TagLen: 16, NewCipher: chacha20poly1305.New}, "chacha20-poly1305": {KeyLen: 32, SaltLen: 32, NonceLen: 12, TagLen: 16, NewCipher: chacha20poly1305.New}, "aes-256-gcm": {KeyLen: 32, SaltLen: 32, NonceLen: 12, TagLen: 16, NewCipher: NewGcm}, "aes-128-gcm": {KeyLen: 16, SaltLen: 16, NonceLen: 12, TagLen: 16, NewCipher: NewGcm}, } ZeroNonce [MaxNonceSize]byte ReusedInfo = []byte("ss-subkey") )
View Source
var ( ErrFailAuth = fmt.Errorf("fail to authenticate") ErrFailInitCihper = fmt.Errorf("fail to initiate cipher") )
View Source
var (
ErrInvalidMetadata = errors.Errorf("invalid metadata")
)
View Source
var ErrPassageAbuse = fmt.Errorf("passage abuse")
Functions ¶
func BytesSizeForMetadata ¶
func CalcPaddingLen ¶
func DecryptUDP ¶
DecryptUDP will decrypt the data in place
func EVPBytesToKey ¶
func EncryptUDPFromPool ¶
EncryptUDPFromPool returns shadowBytes from pool. the shadowBytes MUST be put back.
func EncryptedPayloadLen ¶
func LocalizePassages ¶
Types ¶
type CipherConf ¶
type IPMTUTrie ¶
type IPMTUTrie struct {
// contains filtered or unexported fields
}
var MTUTrie *IPMTUTrie
type Key ¶
type Key struct { CipherConf CipherConf MasterKey []byte }
type Metadata ¶
type Metadata struct { Type MetadataType Hostname string Port uint16 Cmd MetadataCmd LenMsgBody uint32 }
func NewMetadata ¶
func (*Metadata) BytesFromPool ¶
type MetadataCmd ¶
type MetadataCmd uint8
const ( MetadataCmdPing MetadataCmd = iota MetadataCmdSyncPassages MetadataCmdResponse )
type MetadataType ¶
type MetadataType int
const ( MetadataTypeReserved0 MetadataType = iota MetadataTypeIPv4 MetadataTypeReserved2 MetadataTypeDomain MetadataTypeIPv6 // MetadataTypeMsg indicates it's a message from SweetLisa. // [MetadataType(1)][MetadataCmd(1)] MetadataTypeMsg )
type SSConn ¶
func (*SSConn) ReadMetadata ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) GetOrBuildUCPConn ¶
func (s *Server) GetOrBuildUCPConn(lAddr net.Addr, data []byte) (rc *net.UDPConn, passage *Passage, plainText []byte, err error)
GetOrBuildUCPConn get a UDP conn from the mapping. plainText is from pool. Please MUST put it back.
func (*Server) GetUserContextOrInsert ¶
func (s *Server) GetUserContextOrInsert(userIP string) *UserContext
func (*Server) RemovePassages ¶
type UDPConn ¶
type UDPConn struct { Establishing chan struct{} *net.UDPConn // contains filtered or unexported fields }
func NewUDPConn ¶
type UDPConnMapping ¶
func NewUDPConnMapping ¶
func NewUDPConnMapping() *UDPConnMapping
func (*UDPConnMapping) Insert ¶
func (m *UDPConnMapping) Insert(key string, val *net.UDPConn) *UDPConn
pass val=nil for stating it is establishing
func (*UDPConnMapping) Remove ¶
func (m *UDPConnMapping) Remove(key string)
type UserContext ¶
UserContext is the context of a user which indicates the preferred servers
func NewUserContext ¶
func NewUserContext(passages []Passage) *UserContext
func (*UserContext) Close ¶
func (ctx *UserContext) Close() error
func (*UserContext) Infra ¶
func (ctx *UserContext) Infra() *lrulist.LruList
type UserContextPool ¶
UserContextPool is a pool which saves the UserContext and eliminates unused UserContext over time
func (*UserContextPool) Infra ¶
func (pool *UserContextPool) Infra() *lru.LRU
Click to show internal directories.
Click to hide internal directories.