gosocks

package module
v0.0.0-...-06f41c5 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: BSD-2-Clause Imports: 13 Imported by: 9

README

gosocks

A Golang implementation of socks5 proxy

Documentation

Index

Constants

View Source
const (
	SocksVersion = 0x05

	SocksReserved = 0x00

	SocksNoAuthentication    = 0x00
	SocksAuthUserPassword    = 0x02
	SocksNoAcceptableMethods = 0xFF

	SocksIPv4Host   = 0x01
	SocksIPv6Host   = 0x04
	SocksDomainHost = 0x03

	SocksCmdConnect      = 0x01
	SocksCmdBind         = 0x02
	SocksCmdUDPAssociate = 0x03

	SocksSucceeded      = 0x00
	SocksGeneralFailure = 0x01

	SocksNoFragment = 0x00
)
View Source
const (
	DefaultPort = 1080
)

Variables

This section is empty.

Functions

func ClientAuthAnonymous

func ClientAuthAnonymous(conn *SocksConn) (err error)

func ConnMonitor

func ConnMonitor(c net.Conn, quit chan bool)

func CopyLoopTimeout

func CopyLoopTimeout(c1 net.Conn, c2 net.Conn, timeout time.Duration)

func Htons

func Htons(data uint16) (ret [2]byte)

func LegalClientAddr

func LegalClientAddr(clientAssociate *net.UDPAddr, addr *net.UDPAddr) bool

func NetAddrToSocksAddr

func NetAddrToSocksAddr(addr interface{}) (hostType byte, host string, port uint16)

func Ntohs

func Ntohs(data [2]byte) uint16

func PackUDPRequest

func PackUDPRequest(udpReq *UDPRequest) []byte

func ParseHost

func ParseHost(host string) (byte, string)

func ReplyGeneralFailure

func ReplyGeneralFailure(w io.Writer, req *SocksRequest) (n int, err error)

func SockAddrString

func SockAddrString(host string, port uint16) string

func SocksAddrToNetAddr

func SocksAddrToNetAddr(nw, host string, port uint16) net.Addr

func UDPReader

func UDPReader(u *net.UDPConn, ch chan<- *UDPPacket, quit chan bool)

func WriteSocksReply

func WriteSocksReply(w io.Writer, reply *SocksReply) (n int, err error)

func WriteSocksRequest

func WriteSocksRequest(w io.Writer, req *SocksRequest) (n int, err error)

Types

type AnonymousClientAuthenticator

type AnonymousClientAuthenticator struct{}

func (*AnonymousClientAuthenticator) ClientAuthenticate

func (a *AnonymousClientAuthenticator) ClientAuthenticate(conn *SocksConn) (err error)

type AnonymousServerAuthenticator

type AnonymousServerAuthenticator struct{}

func (*AnonymousServerAuthenticator) ServerAuthenticate

func (a *AnonymousServerAuthenticator) ServerAuthenticate(conn *SocksConn) (err error)

type BasicSocksHandler

type BasicSocksHandler struct{}

func (*BasicSocksHandler) HandleCmdConnect

func (h *BasicSocksHandler) HandleCmdConnect(req *SocksRequest, conn *SocksConn)

func (*BasicSocksHandler) HandleCmdUDPAssociate

func (h *BasicSocksHandler) HandleCmdUDPAssociate(req *SocksRequest, conn *SocksConn)

func (*BasicSocksHandler) Quit

func (h *BasicSocksHandler) Quit()

func (*BasicSocksHandler) ServeSocks

func (h *BasicSocksHandler) ServeSocks(conn *SocksConn)

func (*BasicSocksHandler) UDPAssociateFirstPacket

func (h *BasicSocksHandler) UDPAssociateFirstPacket(req *SocksRequest, conn *SocksConn) (*net.UDPConn, *net.UDPAddr, *UDPRequest, *net.UDPAddr, error)

func (*BasicSocksHandler) UDPAssociateForwarding

func (h *BasicSocksHandler) UDPAssociateForwarding(conn *SocksConn, clientBind *net.UDPConn, clientAssociate *net.UDPAddr, firstPkt *UDPRequest, clientAddr *net.UDPAddr)

type ClientAuthenticator

type ClientAuthenticator interface {
	ClientAuthenticate(conn *SocksConn) error
}

type Handler

type Handler interface {
	ServeSocks(conn *SocksConn)
	Quit()
}

type Server

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

func NewBasicServer

func NewBasicServer(addr string, to time.Duration) *Server

func NewServer

func NewServer(addr string, to time.Duration, handler Handler, auth ServerAuthenticator) *Server

func (*Server) ChangeAuth

func (svr *Server) ChangeAuth(auth ServerAuthenticator)

ChangeAuth safely changes authenticator when server is running

func (*Server) ChangeHandler

func (svr *Server) ChangeHandler(handler Handler)

func (*Server) GetTimeout

func (svr *Server) GetTimeout() time.Duration

func (*Server) ListenAndServe

func (svr *Server) ListenAndServe() error

func (*Server) Serve

func (svr *Server) Serve(ln net.Listener) error

type ServerAuthenticator

type ServerAuthenticator interface {
	ServerAuthenticate(conn *SocksConn) error
}

type SocksConn

type SocksConn struct {
	net.Conn
	Timeout time.Duration
}

type SocksDialer

type SocksDialer struct {
	Timeout    time.Duration
	Auth       ClientAuthenticator
	ControlFun func(fd uintptr)
}

func (*SocksDialer) Dial

func (d *SocksDialer) Dial(rawURL string) (conn *SocksConn, err error)

type SocksReply

type SocksReply struct {
	Rep      byte
	HostType byte
	BndHost  string
	BndPort  uint16
}

func ClientRequest

func ClientRequest(conn *SocksConn, req *SocksRequest) (reply *SocksReply, err error)

func ReadSocksReply

func ReadSocksReply(r io.Reader) (reply *SocksReply, err error)

type SocksRequest

type SocksRequest struct {
	Cmd      byte
	HostType byte
	DstHost  string
	DstPort  uint16
}

func ReadSocksRequest

func ReadSocksRequest(r io.Reader) (req *SocksRequest, err error)

type UDPPacket

type UDPPacket struct {
	Addr *net.UDPAddr
	Data []byte
}

type UDPRequest

type UDPRequest struct {
	Frag     byte
	HostType byte
	DstHost  string
	DstPort  uint16
	Data     []byte
}

func ParseUDPRequest

func ParseUDPRequest(data []byte) (udpReq *UDPRequest, err error)

type UserPasswordClientAuthenticator

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

func (*UserPasswordClientAuthenticator) ClientAuthenticate

func (a *UserPasswordClientAuthenticator) ClientAuthenticate(conn *SocksConn) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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