Versions in this module Expand all Collapse all v1 v1.0.3 Dec 21, 2023 Changes in this version + const AcceptCmd + const AuthFailure + const AuthSuccess + const BindCmd + const BindStatusCmd + const ConnectCmd + const CryptoCmd + const DEBUG + const ERROR + const FATAL + const HeartBeatCmd + const INFO + const MemPoolNodeSize + const MtrCmd + const NoAcceptable + const NoAuth + const NotUseAddr + const NtcpHeaderLen + const NtcpHeaderSize + const NtcpVersion + const PacketBufSize + const PingCmd + const ProIcmp + const ProTcp + const ProUdp + const RecvFromCmd + const SendToCmd + const ServerAddrCmd + const TcpReadBufferSize + const TcpWriteBufferSize + const TdpHeaderLen + const TdpVersion + const TimeoutSecond + const UdpListenerReadBufferSize + const UdpListenerWriteBufferSize + const UdpReadBufferSize + const UdpWriteBufferSize + const UpdateCryptoTime + const UserAuthVersion + const UserPassAuth + const WARN + var BitValue01 = byte(0x01) + var MaxConnCount = uint32(102400) + var NoSupportedAuth = fmt.Errorf("No Supported Authentication") + var UserAuthFailed = fmt.Errorf("User Authentication Failed") + func Addr2Byte(addrSpec *AddrSpec) (uint8, []byte, error) + func GetATyp(aTyp uint8) string + func GetCmd(cmd uint8) string + func GetProtocol(pro uint8) string + func LegalProxyMode(cmd uint8) bool + type AES128Context struct + Keys [keyArrayLen][]byte + Method crypto.CryptoType + Version uint8 + func NewAES128Context(cryptoCode crypto.CryptoType) *AES128Context + func (aes128 *AES128Context) GenerateKey() + func (aes128 *AES128Context) GetCode() crypto.CryptoType + func (aes128 *AES128Context) GetKey(version uint8) ([][]byte, bool) + func (aes128 *AES128Context) GetVersion() uint8 + func (aes128 *AES128Context) SetKey(version uint8, key [][]byte) bool + type AddrSpec struct + FQDN string + IP net.IP + Port int + func Addr2AddrSpec(addr string) (*AddrSpec, error) + func (a *AddrSpec) String() string + func (a AddrSpec) Address() string + type AuthContext struct + Method uint8 + Payload map[string]string + type Authenticator interface + Authenticate func(reader io.Reader, writer io.Writer) (*AuthContext, error) + GetCode func() uint8 + type BindConn interface + Close func() error + LocalAddr func() net.Addr + ProxyBindAddr func() (string, error) + Read func(b []byte) (n int, err error) + ReadFrom func(b []byte) (int, net.Addr, error) + RemoteAddr func() net.Addr + SetDeadline func(t time.Time) error + SetReadDeadline func(t time.Time) error + SetWriteDeadline func(t time.Time) error + Write func(b []byte) (n int, err error) + WriteTo func(b []byte, addr net.Addr) (int, error) + type BindDatagram struct + Data []byte + func NewBindDatagram(ctx context.Context, cmd, aTyp byte, host, port, data []byte) *BindDatagram + func NewBindDatagramFromByte(ctx context.Context, bs []byte) (*BindDatagram, error) + func NewBindDatagramFromIO(ctx context.Context, bufIO io.Reader) (*BindDatagram, error) + func (d *BindDatagram) Address() string + func (d *BindDatagram) Cmd() byte + func (d *BindDatagram) Host() string + func (d *BindDatagram) Port() int + type ChaCha20Context struct + Keys [keyArrayLen]*ChaCha20Key + Method crypto.CryptoType + Version uint8 + func NewChaCha20Context(cryptoCode crypto.CryptoType) *ChaCha20Context + func (chacha *ChaCha20Context) GenerateKey() + func (chacha *ChaCha20Context) GetCode() crypto.CryptoType + func (chacha *ChaCha20Context) GetKey(version uint8) ([][]byte, bool) + func (chacha *ChaCha20Context) GetVersion() uint8 + func (chacha *ChaCha20Context) SetKey(version uint8, key [][]byte) bool + type ChaCha20Key struct + Key []byte + Nonce []byte + type CredentialStore interface + Get func() (string, string, bool) + Valid func(user, password string) bool + type CryptoStore interface + GetMethods func() []crypto.CryptoType + SetMethod func(method crypto.CryptoType) + Valid func(method crypto.CryptoType) bool + type CryptoSupport map[crypto.CryptoType]struct + func (c CryptoSupport) GetMethods() []crypto.CryptoType + func (c CryptoSupport) SetMethod(method crypto.CryptoType) + func (c CryptoSupport) Valid(method crypto.CryptoType) bool + type CryptorContext interface + GenerateKey func() + GetCode func() crypto.CryptoType + GetKey func(version uint8) ([][]byte, bool) + GetVersion func() uint8 + SetKey func(version uint8, key [][]byte) bool + func GetCryptoContext(cryptoCode crypto.CryptoType) CryptorContext + type Datagram struct + Data []byte + func NewDatagram(ctx context.Context, cryptoVer, cmd, protocol, aTyp, area byte, connId uint16, ...) *Datagram + func NewDatagramFromByte(ctx context.Context, bs []byte) (*Datagram, error) + func ReadDatagramHeaderFromIO(ctx context.Context, bufIO io.Reader) (*Datagram, error) + func (d *Datagram) Address() string + func (d *Datagram) Area() byte + func (d *Datagram) Cmd() byte + func (d *Datagram) ConnectionId() uint16 + func (d *Datagram) Host() string + func (d *Datagram) Port() int + func (d *Datagram) Protocol() byte + func (d *Datagram) Uid() uint32 + type DatagramS struct + Data []byte + func NewDatagramS(ctx context.Context, cryptoVer byte, data []byte) *DatagramS + func NewDatagramSFromByte(ctx context.Context, bs []byte) (*DatagramS, error) + func NewDatagramSFromIO(ctx context.Context, bufIO io.Reader) (*DatagramS, error) + type Logger interface + PrintLog func(level string, format string, v ...any) + type Mem struct + func CreateMemMgr() *Mem + func (m *Mem) Alloc(ctx context.Context, size int) []byte + func (m *Mem) Free(ctx context.Context, bs []byte) + type MemAllocation interface + Alloc func(ctx context.Context, size int) []byte + Free func(ctx context.Context, bs []byte) + type MemMgr interface + Create func(ctx context.Context) MemAllocation + type NoAuthenticator struct + func (a NoAuthenticator) Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error) + func (a NoAuthenticator) GetCode() uint8 + type NoneContext struct + Keys [keyArrayLen][]byte + Method crypto.CryptoType + Version uint8 + func NewNoneContext(cryptoCode crypto.CryptoType) *NoneContext + func (none *NoneContext) GenerateKey() + func (none *NoneContext) GetCode() crypto.CryptoType + func (none *NoneContext) GetKey(version uint8) ([][]byte, bool) + func (none *NoneContext) GetVersion() uint8 + func (none *NoneContext) SetKey(version uint8, key [][]byte) bool + type NtcpDial func(ctx context.Context, network, addr string) (net.Conn, error) + type NtcpListen func(network, address string) (net.Listener, error) + type NtcpLogger struct + func (nl *NtcpLogger) PrintLog(level string, format string, v ...any) + type NtcpNewConn func(session Session, proxyHeader ProxyHeader) (net.Conn, error) + type NtcpNewPeer func(src, dst net.Conn) error + type NtcpSession struct + func NewSession(conf *SessionConfig, cb NtcpSessionDead) *NtcpSession + func (ns *NtcpSession) Bind(network string, area uint8) (BindConn, error) + func (ns *NtcpSession) Close() error + func (ns *NtcpSession) Connect(network, dstAddr string, area uint8) (net.Conn, error) + func (ns *NtcpSession) ConnectWithBind(network, dstAddr string, area uint8) (net.Conn, error) + func (ns *NtcpSession) CryptoSyncVersion() uint8 + func (ns *NtcpSession) Cryptoer() CryptorContext + func (ns *NtcpSession) Dial(ctx context.Context, addr string) error + func (ns *NtcpSession) GetBindHost() string + func (ns *NtcpSession) IsDead() bool + func (ns *NtcpSession) Logger() Logger + func (ns *NtcpSession) SessionUid() uint32 + type NtcpSessionDead func(session *NtcpSession) + type NtcpTcp struct + func NewNtcpTcp(session Session, area uint8) *NtcpTcp + func NewNtcpTcpWithConn(session Session, conn net.Conn) *NtcpTcp + func (nc *NtcpTcp) Close() error + func (nc *NtcpTcp) Dial(ctx context.Context, proxyAddr *AddrSpec, dstAddr *AddrSpec, ntcpDial NtcpDial) error + func (nc *NtcpTcp) LocalAddr() net.Addr + func (nc *NtcpTcp) Read(b []byte) (n int, err error) + func (nc *NtcpTcp) RemoteAddr() net.Addr + func (nc *NtcpTcp) SetDeadline(t time.Time) error + func (nc *NtcpTcp) SetReadDeadline(t time.Time) error + func (nc *NtcpTcp) SetWriteDeadline(t time.Time) error + func (nc *NtcpTcp) Write(b []byte) (n int, err error) + type NtcpTdp struct + func NewNtcpTdp(session Session) *NtcpTdp + func NewNtcpTdpWithConn(session Session, conn net.Conn) *NtcpTdp + func (nc *NtcpTdp) Close() error + func (nc *NtcpTdp) Dial(ctx context.Context, proxyAddr *AddrSpec, ntcpDial NtcpDial) error + func (nc *NtcpTdp) LocalAddr() net.Addr + func (nc *NtcpTdp) Read(b []byte) (n int, err error) + func (nc *NtcpTdp) RemoteAddr() net.Addr + func (nc *NtcpTdp) SetDeadline(t time.Time) error + func (nc *NtcpTdp) SetReadDeadline(t time.Time) error + func (nc *NtcpTdp) SetWriteDeadline(t time.Time) error + func (nc *NtcpTdp) Write(b []byte) (n int, err error) + type NtcpUdp struct + func NewNtcpUdp(session Session, dstAddr *AddrSpec, area uint8) *NtcpUdp + func NewNtcpUdpOverTdp(session Session, mem MemAllocation, dstAddr *AddrSpec, area uint8) (*NtcpUdp, error) + func NewNtcpUdpOverTdpWithBind(session Session, tdpConn *NtcpTdp, mem MemAllocation, area uint8) (*NtcpUdp, error) + func NewNtcpUdpWithBind(session Session, dstAddr *AddrSpec, area uint8) *NtcpUdp + func NewNtcpUdpWithConn(session Session, closeCB closeOneFn, conn *net.UDPConn, from *net.UDPAddr, ...) *NtcpUdp + func NewNtcpUdpWithTdpConn(session Session, tdpConn *NtcpTdp, mem MemAllocation, dstAddr *AddrSpec, ...) (*NtcpUdp, error) + func (nc *NtcpUdp) Close() error + func (nc *NtcpUdp) Dial(ctx context.Context, proxyAddr *AddrSpec, ntcpDial NtcpDial) error + func (nc *NtcpUdp) DialTdp(ctx context.Context, proxyAddr *AddrSpec) error + func (nc *NtcpUdp) LocalAddr() net.Addr + func (nc *NtcpUdp) Read(b []byte) (n int, err error) + func (nc *NtcpUdp) RemoteAddr() net.Addr + func (nc *NtcpUdp) SetDeadline(t time.Time) error + func (nc *NtcpUdp) SetReadDeadline(t time.Time) error + func (nc *NtcpUdp) SetWriteDeadline(t time.Time) error + func (nc *NtcpUdp) Write(b []byte) (n int, err error) + type NtcpUdpBind struct + func NewNtcpUdpBind(session Session, area uint8) *NtcpUdpBind + func NewNtcpUdpBindOverTdp(session Session, mem MemAllocation, area uint8) (*NtcpUdpBind, error) + func NewNtcpUdpBindWithConn(session Session, mem MemAllocation, connId uint16, area uint8) (*NtcpUdpBind, error) + func (nc *NtcpUdpBind) Close() error + func (nc *NtcpUdpBind) Dial(ctx context.Context, proxyAddr *AddrSpec, ntcpDial NtcpDial) error + func (nc *NtcpUdpBind) DialTdp(ctx context.Context, proxyAddr *AddrSpec) error + func (nc *NtcpUdpBind) LocalAddr() net.Addr + func (nc *NtcpUdpBind) ProxyBindAddr() (string, error) + func (nc *NtcpUdpBind) Read(b []byte) (n int, err error) + func (nc *NtcpUdpBind) ReadFrom(b []byte) (int, net.Addr, error) + func (nc *NtcpUdpBind) RemoteAddr() net.Addr + func (nc *NtcpUdpBind) SetDeadline(t time.Time) error + func (nc *NtcpUdpBind) SetReadDeadline(t time.Time) error + func (nc *NtcpUdpBind) SetWriteDeadline(t time.Time) error + func (nc *NtcpUdpBind) Write(b []byte) (n int, err error) + func (nc *NtcpUdpBind) WriteTo(b []byte, addr net.Addr) (int, error) + type ProxyHeader interface + Address func() string + Area func() byte + Cmd func() byte + ConnectionId func() uint16 + Protocol func() byte + Uid func() uint32 + type ProxyServer struct + func (p *ProxyServer) Close() error + type ProxyUdp struct + type Request struct + AuthContext *AuthContext + ClientCryptoVersion uint8 + Config *ServerConfig + Conn net.Conn + CryptorContext CryptorContext + Log Logger + Uid uint32 + Version uint8 + func NewRequest(s *Server, conn net.Conn) (*Request, error) + func (r *Request) CryptoSyncVersion() uint8 + func (r *Request) Cryptoer() CryptorContext + func (r *Request) GetBindHost() string + func (r *Request) IsDead() bool + func (r *Request) Logger() Logger + func (r *Request) SessionUid() uint32 + func (r *Request) UpdateSyncVersion(v uint8) + type Server struct + func NewServer(conf *ServerConfig, ntcpNewConn NtcpNewConn, ntcpNewPeer NtcpNewPeer) (*Server, error) + func (s *Server) ListenAndServe(addr string, tcpProxyAddr, udpProxyAddr, tdpProxyAddr string) error + type ServerConfig struct + AuthMethods []Authenticator + BindHost string + Credentials CredentialStore + CryptoStores CryptoStore + Dial NtcpDial + Disten NtcpListen + Log Logger + MemMgr MemMgr + func (s *ServerConfig) GetBindHost() string + type Session interface + CryptoSyncVersion func() uint8 + Cryptoer func() CryptorContext + GetBindHost func() string + IsDead func() bool + Logger func() Logger + SessionUid func() uint32 + type SessionConfig struct + Credentials CredentialStore + CryptoMethod crypto.CryptoType + Dial NtcpDial + Log Logger + type StaticCredentials map[string]string + func (s StaticCredentials) Get() (string, string, bool) + func (s StaticCredentials) Valid(user, password string) bool + type TdpData struct + Data []byte + type TeaContext struct + Keys [keyArrayLen]*TeaKey + Method crypto.CryptoType + Version uint8 + func NewTeaContext(cryptoCode crypto.CryptoType) *TeaContext + func (tea *TeaContext) GenerateKey() + func (tea *TeaContext) GetCode() crypto.CryptoType + func (tea *TeaContext) GetKey(version uint8) ([][]byte, bool) + func (tea *TeaContext) GetVersion() uint8 + func (tea *TeaContext) SetKey(version uint8, key [][]byte) bool + type TeaKey struct + ByteKey []byte + Key []byte + type UserPassAuthenticator struct + Credentials CredentialStore + func (a UserPassAuthenticator) Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error) + func (a UserPassAuthenticator) GetCode() uint8