Versions in this module Expand all Collapse all v1 v1.1.1 Nov 3, 2024 Changes in this version + const ATYPDomain + const ATYPIPv4 + const ATYPIPv6 + const CmdBind + const CmdConnect + const CmdUDP + const MethodGSSAPI + const MethodNone + const MethodUnsupportAll + const MethodUsernamePassword + const RepAddressNotSupported + const RepCommandNotSupported + const RepConnectionRefused + const RepHostUnreachable + const RepNetworkUnreachable + const RepNotAllowed + const RepServerFailure + const RepSuccess + const RepTTLExpired + const UserPassStatusFailure + const UserPassStatusSuccess + const UserPassVer + const Ver + var Debug bool + var DialTCP func(network string, laddr, raddr string) (net.Conn, error) = func(network string, laddr, raddr string) (net.Conn, error) + var DialUDP func(network string, laddr, raddr string) (net.Conn, error) = func(network string, laddr, raddr string) (net.Conn, error) + var ErrBadReply = errors.New("Bad Reply") + var ErrBadRequest = errors.New("Bad Request") + var ErrUnsupportCmd = errors.New("Unsupport Command") + var ErrUserPassAuth = errors.New("Invalid Username or Password for Auth") + var ErrUserPassVersion = errors.New("Invalid Version of Username Password Auth") + var ErrVersion = errors.New("Invalid Version") + var Resolve func(network string, addr string) (net.Addr, error) = func(network string, addr string) (net.Addr, error) + func Command2String(cmd uint8) string + func ParseAddress(address string) (a byte, addr []byte, port []byte, err error) + func ParseBytesAddress(b []byte) (a byte, addr []byte, port []byte, err error) + func Reply2String(code uint8) string + func ToAddress(a byte, addr []byte, port []byte) string + type BytesPool interface + Get func() []byte + Put func([]byte) + type Client struct + Dst string + Password string + RemoteAddress net.Addr + Server string + TCPConn net.Conn + TCPTimeout int + UDPConn net.Conn + UDPTimeout int + UserName string + func NewClient(addr, username, password string, tcpTimeout, udpTimeout int) (*Client, error) + func (c *Client) Close() error + func (c *Client) Dial(network, addr string) (net.Conn, error) + func (c *Client) DialWithLocalAddr(network, src, dst string, remoteAddr net.Addr) (net.Conn, error) + func (c *Client) LocalAddr() net.Addr + func (c *Client) Negotiate(laddr net.Addr) error + func (c *Client) Read(b []byte) (int, error) + func (c *Client) RemoteAddr() net.Addr + func (c *Client) Request(r *RequestC) (*Reply, error) + func (c *Client) SetDeadline(t time.Time) error + func (c *Client) SetReadDeadline(t time.Time) error + func (c *Client) SetWriteDeadline(t time.Time) error + func (c *Client) Write(b []byte) (int, error) + type DatagramC struct + Atyp byte + Data []byte + DstAddr []byte + DstPort []byte + Frag byte + Rsv []byte + func NewDatagramC(atyp byte, dstaddr []byte, dstport []byte, data []byte) *DatagramC + func NewDatagramFromBytes(bb []byte) (*DatagramC, error) + func (d *DatagramC) Address() string + func (d *DatagramC) Bytes() []byte + type Dialer struct + IsResolve bool + Password string + ProxyAddress string + ProxyDial func(ctx context.Context, network string, address string) (net.Conn, error) + ProxyNetwork string + ProxyPacketDial func(ctx context.Context, network string, address string) (net.PacketConn, error) + Resolver *net.Resolver + Timeout time.Duration + Username string + func NewDialer(addr string) (*Dialer, error) + func (d *Dialer) Dial(network, address string) (net.Conn, error) + func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) + func (d *Dialer) Listen(ctx context.Context, network, address string) (net.Listener, error) + type NegotiationReply struct + Method byte + Ver byte + func NewNegotiationReplyFrom(r io.Reader) (*NegotiationReply, error) + type NegotiationRequest struct + Methods []byte + NMethods byte + Ver byte + func NewNegotiationRequest(methods []byte) *NegotiationRequest + func (r *NegotiationRequest) WriteTo(w io.Writer) (int64, error) + type Reply struct + Atyp byte + BndAddr []byte + BndPort []byte + Rep byte + Rsv byte + Ver byte + func NewReplyFrom(r io.Reader) (*Reply, error) + func (r *Reply) Address() string + type RequestC struct + Atyp byte + Cmd byte + DstAddr []byte + DstPort []byte + Rsv byte + Ver byte + func NewRequest2(cmd byte, atyp byte, dstaddr []byte, dstport []byte) *RequestC + func (r *RequestC) Address() string + func (r *RequestC) WriteTo(w io.Writer) (int64, error) + type UDPConn struct + func NewUDPConn(raw net.PacketConn, proxyAddress net.Addr, defaultTarget net.Addr) (*UDPConn, error) + func (c *UDPConn) Read(b []byte) (int, error) + func (c *UDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) + func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) + func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error) + func (c *UDPConn) RemoteAddr() net.Addr + func (c *UDPConn) SetDeadline(t time.Time) error + func (c *UDPConn) SetReadBuffer(bytes int) error + func (c *UDPConn) SetReadDeadline(t time.Time) error + func (c *UDPConn) SetWriteBuffer(bytes int) error + func (c *UDPConn) SetWriteDeadline(t time.Time) error + func (c *UDPConn) Write(b []byte) (int, error) + func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error) + func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error) + func (c *UDPConn) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error) + type UserPassNegotiationReply struct + Status byte + Ver byte + func NewUserPassNegotiationReplyFrom(r io.Reader) (*UserPassNegotiationReply, error) + type UserPassNegotiationRequest struct + Passwd []byte + Plen byte + Ulen byte + Uname []byte + Ver byte + func NewUserPassNegotiationRequest(username []byte, password []byte) *UserPassNegotiationRequest + func (r *UserPassNegotiationRequest) WriteTo(w io.Writer) (int64, error) v1.1.0 Nov 2, 2024 Changes in this version + type BindCallBackFun func(bindAddr string) + var BindCallBack BindCallBackFun + type Datagram struct + ATyp byte + Data []byte + DstAddr []byte + DstPort []byte + Frag byte + Rsv []byte + func NewDatagram(ctx context.Context, memCreater MemAllocation, aTyp byte, ...) *Datagram + func NewDatagramFromByte(ctx context.Context, memCreater MemAllocation, bs []byte) (*Datagram, error) + func (d *Datagram) Address() string + type UdpAssociate struct + func NewUdpAssociate() *UdpAssociate + func (ua *UdpAssociate) CloseAll() + func (ua *UdpAssociate) Del(key string) + func (ua *UdpAssociate) Get(key string) (*UdpPeer, bool) + func (ua *UdpAssociate) Set(key string, u *UdpPeer) + type UdpPeer struct + type UdpServer struct + func UdpInstance() *UdpServer + func (us *UdpServer) Close() error + func (us *UdpServer) Listen(network, addr string) error + func (us *UdpServer) LocalAddr() net.Addr + func (us *UdpServer) ReadFromUdp(bs []byte) (int, *net.UDPAddr, error) + func (us *UdpServer) WriteToUDP(bs []byte, addr *net.UDPAddr) (int, error) v1.0.1 Nov 1, 2024 Changes in this version + const AssociateCommand + const BindCommand + const ConnectCommand + const NoAuth + const UserPassAuth + var NoSupportedAuth = fmt.Errorf("No supported authentication mechanism") + var UserAuthFailed = fmt.Errorf("User authentication failed") + type AddrSpec struct + FQDN string + IP net.IP + Port int + func (a *AddrSpec) String() string + func (a AddrSpec) Address() string + type AddressRewriter interface + Rewrite func(ctx context.Context, request *Request) (context.Context, *AddrSpec) + 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 Config struct + AuthMethods []Authenticator + BindIP net.IP + Credentials CredentialStore + Dial func(ctx context.Context, network, addr string) (net.Conn, error) + Logger *log.Logger + Mem MemMgr + Resolver NameResolver + Rewriter AddressRewriter + Rules RuleSet + type CredentialStore interface + Valid func(user, password string) bool + type DNSResolver struct + func (d DNSResolver) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) + type Mem struct + 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 NameResolver interface + Resolve func(ctx context.Context, name string) (context.Context, net.IP, error) + type NoAuthAuthenticator struct + func (a NoAuthAuthenticator) Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error) + func (a NoAuthAuthenticator) GetCode() uint8 + type PermitCommand struct + EnableAssociate bool + EnableBind bool + EnableConnect bool + func (p *PermitCommand) Allow(ctx context.Context, req *Request) (context.Context, bool) + type Request struct + AuthContext *AuthContext + Command uint8 + DestAddr *AddrSpec + RemoteAddr *AddrSpec + Version uint8 + func NewRequest(bufConn io.Reader) (*Request, error) + type RuleSet interface + Allow func(ctx context.Context, req *Request) (context.Context, bool) + func PermitAll() RuleSet + func PermitNone() RuleSet + type Server struct + func New(conf *Config) (*Server, error) + func (s *Server) ListenAndServe(network, addr string) error + func (s *Server) Serve(l net.Listener) error + func (s *Server) ServeConn(conn net.Conn) error + func (s *Server) SetIPAllowlist(allowedIPs []net.IP) + type StaticCredentials map[string]string + func (s StaticCredentials) Valid(user, password string) bool + type UserPassAuthenticator struct + Credentials CredentialStore + func (a UserPassAuthenticator) Authenticate(reader io.Reader, writer io.Writer) (*AuthContext, error) + func (a UserPassAuthenticator) GetCode() uint8