gost

package module
v2.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2017 License: MIT Imports: 31 Imported by: 0

README

forked from ginuerzh/gost

Documentation

Index

Constants

View Source
const (
	LFATAL = iota
	LERROR
	LWARNING
	LINFO
	LDEBUG
)

Log level for glog

View Source
const (
	MethodTLS     uint8 = 0x80 // extended method for tls
	MethodTLSAuth uint8 = 0x82 // extended method for tls+auth
)
View Source
const (
	CmdUdpTun uint8 = 0xF3 // extended method for udp over tcp
)
View Source
const (
	DefaultKCPConfigFile = "kcp.json"
)
View Source
const (
	SO_ORIGINAL_DST = 80
)
View Source
const (
	Version = "2.4-dev"
)

Variables

View Source
var (
	KeepAliveTime = 180 * time.Second
	DialTimeout   = 30 * time.Second
	ReadTimeout   = 90 * time.Second
	WriteTimeout  = 90 * time.Second

	DefaultTTL = 60 // default udp node TTL in second for udp port forwarding
)
View Source
var (
	SmallBufferSize  = 1 * 1024  // 1KB small buffer
	MediumBufferSize = 8 * 1024  // 8KB medium buffer
	LargeBufferSize  = 32 * 1024 // 32KB large buffer
)
View Source
var (
	DefaultCertFile = "cert.pem"
	DefaultKeyFile  = "key.pem"
)
View Source
var (
	DefaultKCPConfig = &KCPConfig{
		Key:          "it's a secrect",
		Crypt:        "aes",
		Mode:         "fast",
		MTU:          1350,
		SndWnd:       1024,
		RcvWnd:       1024,
		DataShard:    10,
		ParityShard:  3,
		DSCP:         0,
		NoComp:       false,
		AckNodelay:   false,
		NoDelay:      0,
		Interval:     40,
		Resend:       0,
		NoCongestion: 0,
		SockBuf:      4194304,
		KeepAlive:    10,
	}
)
View Source
var (
	ErrEmptyChain = errors.New("empty chain")
)
View Source
var (
	SALT = "kcp-go"
)

Functions

func LoadCertificate

func LoadCertificate(certFile, keyFile string) (tls.Certificate, error)

Load the certificate from cert and key files, will use the default certificate if the provided info are invalid.

func SetDefaultCertificate

func SetDefaultCertificate(rawCert, rawKey []byte)

Replace the default certificate by your own

func ToSocksAddr

func ToSocksAddr(addr net.Addr) *gosocks5.Addr

Types

type Http2Server

type Http2Server struct {
	Base      *ProxyServer
	Handler   http.Handler
	TLSConfig *tls.Config
}

func NewHttp2Server

func NewHttp2Server(base *ProxyServer) *Http2Server

func (*Http2Server) HandleRequest

func (s *Http2Server) HandleRequest(w http.ResponseWriter, req *http.Request)

Default HTTP2 server handler

func (*Http2Server) ListenAndServeTLS

func (s *Http2Server) ListenAndServeTLS(config *tls.Config) error

func (*Http2Server) Upgrade

func (s *Http2Server) Upgrade(w http.ResponseWriter, r *http.Request) (net.Conn, error)

Upgrade upgrade an HTTP2 request to a bidirectional connection that preparing for tunneling other protocol, just like a websocket connection.

type HttpServer

type HttpServer struct {
	Base *ProxyServer
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(conn net.Conn, base *ProxyServer) *HttpServer

func (*HttpServer) HandleRequest

func (s *HttpServer) HandleRequest(req *http.Request)

Default HTTP server handler

type KCPConfig

type KCPConfig struct {
	Key          string `json:"key"`
	Crypt        string `json:"crypt"`
	Mode         string `json:"mode"`
	MTU          int    `json:"mtu"`
	SndWnd       int    `json:"sndwnd"`
	RcvWnd       int    `json:"rcvwnd"`
	DataShard    int    `json:"datashard"`
	ParityShard  int    `json:"parityshard"`
	DSCP         int    `json:"dscp"`
	NoComp       bool   `json:"nocomp"`
	AckNodelay   bool   `json:"acknodelay"`
	NoDelay      int    `json:"nodelay"`
	Interval     int    `json:"interval"`
	Resend       int    `json:"resend"`
	NoCongestion int    `json:"nc"`
	SockBuf      int    `json:"sockbuf"`
	KeepAlive    int    `json:"keepalive"`
}

func ParseKCPConfig

func ParseKCPConfig(configFile string) (*KCPConfig, error)

func (*KCPConfig) Init

func (c *KCPConfig) Init()

type KCPConn

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

func NewKCPConn

func NewKCPConn(conn net.Conn, stream *smux.Stream) *KCPConn

func (*KCPConn) Close

func (c *KCPConn) Close() error

func (*KCPConn) LocalAddr

func (c *KCPConn) LocalAddr() net.Addr

func (*KCPConn) Read

func (c *KCPConn) Read(b []byte) (n int, err error)

func (*KCPConn) RemoteAddr

func (c *KCPConn) RemoteAddr() net.Addr

func (*KCPConn) SetDeadline

func (c *KCPConn) SetDeadline(t time.Time) error

func (*KCPConn) SetReadDeadline

func (c *KCPConn) SetReadDeadline(t time.Time) error

func (*KCPConn) SetWriteDeadline

func (c *KCPConn) SetWriteDeadline(t time.Time) error

func (*KCPConn) Write

func (c *KCPConn) Write(b []byte) (n int, err error)

type KCPServer

type KCPServer struct {
	Base   *ProxyServer
	Config *KCPConfig
}

func NewKCPServer

func NewKCPServer(base *ProxyServer, config *KCPConfig) *KCPServer

func (*KCPServer) ListenAndServe

func (s *KCPServer) ListenAndServe() (err error)

type KCPSession

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

func DialKCP

func DialKCP(addr string, config *KCPConfig) (*KCPSession, error)

func (*KCPSession) Close

func (session *KCPSession) Close() error

func (*KCPSession) GetConn

func (session *KCPSession) GetConn() (*KCPConn, error)

func (*KCPSession) IsClosed

func (session *KCPSession) IsClosed() bool

func (*KCPSession) NumStreams

func (session *KCPSession) NumStreams() int

type ProxyChain

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

Proxy chain holds a list of proxy nodes

func NewProxyChain

func NewProxyChain(nodes ...ProxyNode) *ProxyChain

func (*ProxyChain) AddProxyNode

func (c *ProxyChain) AddProxyNode(node ...ProxyNode)

func (*ProxyChain) AddProxyNodeString

func (c *ProxyChain) AddProxyNodeString(snode ...string) error

func (*ProxyChain) Dial

func (c *ProxyChain) Dial(addr string) (net.Conn, error)

Connect to addr through proxy chain

func (*ProxyChain) GetConn

func (c *ProxyChain) GetConn() (net.Conn, error)

GetConn initializes a proxy chain connection, if no proxy nodes on this chain, it will return error

func (*ProxyChain) GetNode

func (c *ProxyChain) GetNode(index int) *ProxyNode

func (*ProxyChain) Http2Enabled

func (c *ProxyChain) Http2Enabled() bool

func (*ProxyChain) Init

func (c *ProxyChain) Init()

Init initialize the proxy chain. KCP will be enabled if the first proxy node is KCP proxy (transport == kcp). HTTP2 will be enabled when at least one HTTP2 proxy node (scheme == http2) is present.

NOTE: Should be called immediately when proxy nodes are ready.

func (*ProxyChain) KCPEnabled

func (c *ProxyChain) KCPEnabled() bool

func (*ProxyChain) Nodes

func (c *ProxyChain) Nodes() []ProxyNode

func (*ProxyChain) SetNode

func (c *ProxyChain) SetNode(index int, node ProxyNode)

type ProxyConn

type ProxyConn struct {
	Node ProxyNode
	// contains filtered or unexported fields
}

func NewProxyConn

func NewProxyConn(conn net.Conn, node ProxyNode) *ProxyConn

func (*ProxyConn) Close

func (c *ProxyConn) Close() error

func (*ProxyConn) Connect

func (c *ProxyConn) Connect(addr string) error

Connect connect to addr through this proxy node

func (*ProxyConn) Handshake

func (c *ProxyConn) Handshake() error

Handshake handshake with this proxy node based on the proxy node info: transport, protocol, authentication, etc.

NOTE: any HTTP2 scheme will be treated as http (for protocol) or tls (for transport).

func (*ProxyConn) LocalAddr

func (c *ProxyConn) LocalAddr() net.Addr

func (*ProxyConn) Read

func (c *ProxyConn) Read(b []byte) (n int, err error)

func (*ProxyConn) RemoteAddr

func (c *ProxyConn) RemoteAddr() net.Addr

func (*ProxyConn) SetDeadline

func (c *ProxyConn) SetDeadline(t time.Time) error

func (*ProxyConn) SetReadDeadline

func (c *ProxyConn) SetReadDeadline(t time.Time) error

func (*ProxyConn) SetWriteDeadline

func (c *ProxyConn) SetWriteDeadline(t time.Time) error

func (*ProxyConn) Write

func (c *ProxyConn) Write(b []byte) (n int, err error)

type ProxyNode

type ProxyNode struct {
	Addr      string          // [host]:port
	Protocol  string          // protocol: http/socks5/ss
	Transport string          // transport: ws/wss/tls/http2/tcp/udp/rtcp/rudp
	Remote    string          // remote address, used by tcp/udp port forwarding
	Users     []*url.Userinfo // authentication for proxy
	// contains filtered or unexported fields
}

Proxy node represent a proxy

func ParseProxyNode

func ParseProxyNode(s string) (node ProxyNode, err error)

The proxy node string pattern is [scheme://][user:pass@host]:port.

Scheme can be devided into two parts by character '+', such as: http+tls.

func (*ProxyNode) Get

func (node *ProxyNode) Get(key string) string

Get get node parameter by key

func (*ProxyNode) Set

func (node *ProxyNode) Set(key, value string)

func (ProxyNode) String

func (node ProxyNode) String() string

type ProxyServer

type ProxyServer struct {
	Node      ProxyNode
	Chain     *ProxyChain
	TLSConfig *tls.Config
	Selector  *serverSelector
	// contains filtered or unexported fields
}

func NewProxyServer

func NewProxyServer(node ProxyNode, chain *ProxyChain, config *tls.Config) *ProxyServer

func (*ProxyServer) Serve

func (s *ProxyServer) Serve() error

type QuicServer

type QuicServer struct {
	Base      *ProxyServer
	Handler   http.Handler
	TLSConfig *tls.Config
}

func NewQuicServer

func NewQuicServer(base *ProxyServer) *QuicServer

func (*QuicServer) HandleRequest

func (s *QuicServer) HandleRequest(w http.ResponseWriter, req *http.Request)

func (*QuicServer) ListenAndServeTLS

func (s *QuicServer) ListenAndServeTLS(config *tls.Config) error

type RTcpForwardServer

type RTcpForwardServer struct {
	Base *ProxyServer
}

func NewRTcpForwardServer

func NewRTcpForwardServer(base *ProxyServer) *RTcpForwardServer

func (*RTcpForwardServer) Serve

func (s *RTcpForwardServer) Serve() error

type RUdpForwardServer

type RUdpForwardServer struct {
	Base *ProxyServer
}

func NewRUdpForwardServer

func NewRUdpForwardServer(base *ProxyServer) *RUdpForwardServer

func (*RUdpForwardServer) Serve

func (s *RUdpForwardServer) Serve() error

type RedsocksTCPServer

type RedsocksTCPServer struct {
	Base *ProxyServer
}

func NewRedsocksTCPServer

func NewRedsocksTCPServer(base *ProxyServer) *RedsocksTCPServer

func (*RedsocksTCPServer) ListenAndServe

func (s *RedsocksTCPServer) ListenAndServe() error

type ShadowServer

type ShadowServer struct {
	Base *ProxyServer
	OTA  bool // one time auth
	// contains filtered or unexported fields
}

func NewShadowServer

func NewShadowServer(conn *ss.Conn, base *ProxyServer) *ShadowServer

func (*ShadowServer) Serve

func (s *ShadowServer) Serve()

type ShadowUdpServer

type ShadowUdpServer struct {
	Base *ProxyServer
	TTL  int
}

func NewShadowUdpServer

func NewShadowUdpServer(base *ProxyServer, ttl int) *ShadowUdpServer

func (*ShadowUdpServer) ListenAndServe

func (s *ShadowUdpServer) ListenAndServe() error

type Socks5Server

type Socks5Server struct {
	Base *ProxyServer
	// contains filtered or unexported fields
}

func NewSocks5Server

func NewSocks5Server(conn net.Conn, base *ProxyServer) *Socks5Server

func (*Socks5Server) HandleRequest

func (s *Socks5Server) HandleRequest(req *gosocks5.Request)

type TcpForwardServer

type TcpForwardServer struct {
	Base    *ProxyServer
	Handler func(conn net.Conn, raddr net.Addr)
}

func NewTcpForwardServer

func NewTcpForwardServer(base *ProxyServer) *TcpForwardServer

func (*TcpForwardServer) ListenAndServe

func (s *TcpForwardServer) ListenAndServe() error

type UdpForwardServer

type UdpForwardServer struct {
	Base *ProxyServer
	TTL  int
}

func NewUdpForwardServer

func NewUdpForwardServer(base *ProxyServer, ttl int) *UdpForwardServer

func (*UdpForwardServer) ListenAndServe

func (s *UdpForwardServer) ListenAndServe() error

type WebsocketConn

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

func WebsocketClientConn

func WebsocketClientConn(url string, conn net.Conn, config *tls.Config) (*WebsocketConn, error)

func WebsocketServerConn

func WebsocketServerConn(conn *websocket.Conn) *WebsocketConn

func (*WebsocketConn) Close

func (c *WebsocketConn) Close() error

func (*WebsocketConn) LocalAddr

func (c *WebsocketConn) LocalAddr() net.Addr

func (*WebsocketConn) Read

func (c *WebsocketConn) Read(b []byte) (n int, err error)

func (*WebsocketConn) RemoteAddr

func (c *WebsocketConn) RemoteAddr() net.Addr

func (*WebsocketConn) SetDeadline

func (conn *WebsocketConn) SetDeadline(t time.Time) error

func (*WebsocketConn) SetReadDeadline

func (c *WebsocketConn) SetReadDeadline(t time.Time) error

func (*WebsocketConn) SetWriteDeadline

func (c *WebsocketConn) SetWriteDeadline(t time.Time) error

func (*WebsocketConn) Write

func (c *WebsocketConn) Write(b []byte) (n int, err error)

type WebsocketServer

type WebsocketServer struct {
	Addr    string
	Base    *ProxyServer
	Handler http.Handler
	// contains filtered or unexported fields
}

func NewWebsocketServer

func NewWebsocketServer(base *ProxyServer) *WebsocketServer

func (*WebsocketServer) HandleRequest

func (s *WebsocketServer) HandleRequest(w http.ResponseWriter, r *http.Request)

Default websocket server handler

func (*WebsocketServer) ListenAndServe

func (s *WebsocketServer) ListenAndServe() error

func (*WebsocketServer) ListenAndServeTLS

func (s *WebsocketServer) ListenAndServeTLS(config *tls.Config) error

Directories

Path Synopsis
vendors
github.com/shadowsocks/shadowsocks-go/shadowsocks
* * Created with IntelliJ IDEA.
* * Created with IntelliJ IDEA.

Jump to

Keyboard shortcuts

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