services

package
v0.0.0-...-fda3609 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2018 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_TCP             = "tcp"
	TYPE_UDP             = "udp"
	TYPE_HTTP            = "http"
	TYPE_TLS             = "tls"
	TYPE_KCP             = "kcp"
	CONN_CLIENT_CONTROL  = uint8(1)
	CONN_CLIENT_HEARBEAT = uint8(2)
	CONN_SERVER_HEARBEAT = uint8(3)
	CONN_SERVER          = uint8(4)
	CONN_CLIENT          = uint8(5)
	CONN_SERVER_MUX      = uint8(6)
	CONN_CLIENT_MUX      = uint8(7)
)

Variables

This section is empty.

Functions

func Regist

func Regist(name string, s Service, args interface{})

Types

type HTTP

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

func (*HTTP) CheckArgs

func (s *HTTP) CheckArgs()

func (*HTTP) Clean

func (s *HTTP) Clean()

func (*HTTP) ConnectSSH

func (s *HTTP) ConnectSSH() (err error)

func (*HTTP) InitBasicAuth

func (s *HTTP) InitBasicAuth() (err error)

func (*HTTP) InitOutConnPool

func (s *HTTP) InitOutConnPool()

func (*HTTP) InitService

func (s *HTTP) InitService()

func (*HTTP) IsBasicAuth

func (s *HTTP) IsBasicAuth() bool

func (*HTTP) IsDeadLoop

func (s *HTTP) IsDeadLoop(inLocalAddr string, host string) bool

func (*HTTP) OutToTCP

func (s *HTTP) OutToTCP(useProxy bool, address string, inConn *net.Conn, req *utils.HTTPRequest) (err interface{})

func (*HTTP) Start

func (s *HTTP) Start(args interface{}) (err error)

func (*HTTP) StopService

func (s *HTTP) StopService()

type HTTPArgs

type HTTPArgs struct {
	Parent              *string
	CertFile            *string
	KeyFile             *string
	CertBytes           []byte
	KeyBytes            []byte
	Local               *string
	Always              *bool
	HTTPTimeout         *int
	Interval            *int
	Blocked             *string
	Direct              *string
	AuthFile            *string
	Auth                *[]string
	AuthURL             *string
	AuthURLOkCode       *int
	AuthURLTimeout      *int
	AuthURLRetry        *int
	ParentType          *string
	LocalType           *string
	Timeout             *int
	PoolSize            *int
	CheckParentInterval *int
	SSHKeyFile          *string
	SSHKeyFileSalt      *string
	SSHPassword         *string
	SSHUser             *string
	SSHKeyBytes         []byte
	SSHAuthMethod       ssh.AuthMethod
	KCPMethod           *string
	KCPKey              *string
	LocalIPS            *[]string
}

type MuxBridge

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

func (*MuxBridge) CheckArgs

func (s *MuxBridge) CheckArgs()

func (*MuxBridge) Clean

func (s *MuxBridge) Clean()

func (*MuxBridge) InitService

func (s *MuxBridge) InitService()

func (*MuxBridge) Start

func (s *MuxBridge) Start(args interface{}) (err error)

func (*MuxBridge) StopService

func (s *MuxBridge) StopService()

type MuxBridgeArgs

type MuxBridgeArgs struct {
	Parent     *string
	CertFile   *string
	KeyFile    *string
	CertBytes  []byte
	KeyBytes   []byte
	Local      *string
	Timeout    *int
	IsCompress *bool
}

type MuxClient

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

func (*MuxClient) CheckArgs

func (s *MuxClient) CheckArgs()

func (*MuxClient) Clean

func (s *MuxClient) Clean()

func (*MuxClient) InitService

func (s *MuxClient) InitService()

func (*MuxClient) ServeConn

func (s *MuxClient) ServeConn(inConn *smux.Stream, localAddr, ID string)

func (*MuxClient) ServeUDP

func (s *MuxClient) ServeUDP(inConn *smux.Stream, localAddr, ID string)

func (*MuxClient) Start

func (s *MuxClient) Start(args interface{}) (err error)

func (*MuxClient) StopService

func (s *MuxClient) StopService()

type MuxClientArgs

type MuxClientArgs struct {
	Parent     *string
	CertFile   *string
	KeyFile    *string
	CertBytes  []byte
	KeyBytes   []byte
	Key        *string
	Timeout    *int
	IsCompress *bool
}

type MuxServer

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

func (*MuxServer) CheckArgs

func (s *MuxServer) CheckArgs()

func (*MuxServer) Clean

func (s *MuxServer) Clean()

func (*MuxServer) GetConn

func (s *MuxServer) GetConn() (conn net.Conn, err error)

func (*MuxServer) GetOutConn

func (s *MuxServer) GetOutConn() (outConn net.Conn, ID string, err error)

func (*MuxServer) InitService

func (s *MuxServer) InitService()

func (*MuxServer) Start

func (s *MuxServer) Start(args interface{}) (err error)

func (*MuxServer) UDPConnDeamon

func (s *MuxServer) UDPConnDeamon()

type MuxServerArgs

type MuxServerArgs struct {
	Parent     *string
	CertFile   *string
	KeyFile    *string
	CertBytes  []byte
	KeyBytes   []byte
	Local      *string
	IsUDP      *bool
	Key        *string
	Remote     *string
	Timeout    *int
	Route      *[]string
	Mgr        *MuxServerManager
	IsCompress *bool
}

type MuxServerManager

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

func (*MuxServerManager) CheckArgs

func (s *MuxServerManager) CheckArgs()

func (*MuxServerManager) Clean

func (s *MuxServerManager) Clean()

func (*MuxServerManager) InitService

func (s *MuxServerManager) InitService()

func (*MuxServerManager) Start

func (s *MuxServerManager) Start(args interface{}) (err error)

func (*MuxServerManager) StopService

func (s *MuxServerManager) StopService()

type MuxUDPItem

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

type ServerConn

type ServerConn struct {
	//ClientLocalAddr string //tcp:2.2.22:333@ID
	Conn *net.Conn
}

type Service

type Service interface {
	Start(args interface{}) (err error)
	Clean()
}

func NewHTTP

func NewHTTP() Service

func NewMuxBridge

func NewMuxBridge() Service

func NewMuxClient

func NewMuxClient() Service

func NewMuxServer

func NewMuxServer() Service

func NewMuxServerManager

func NewMuxServerManager() Service

func NewSocks

func NewSocks() Service

func NewTCP

func NewTCP() Service

func NewTunnelBridge

func NewTunnelBridge() Service

func NewTunnelClient

func NewTunnelClient() Service

func NewTunnelServer

func NewTunnelServer() Service

func NewTunnelServerManager

func NewTunnelServerManager() Service

func NewUDP

func NewUDP() Service

type ServiceItem

type ServiceItem struct {
	S    Service
	Args interface{}
	Name string
}

func Run

func Run(name string, args ...interface{}) (service *ServiceItem, err error)

type Socks

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

func (*Socks) CheckArgs

func (s *Socks) CheckArgs()

func (*Socks) Clean

func (s *Socks) Clean()

func (*Socks) ConnectSSH

func (s *Socks) ConnectSSH() (err error)

func (*Socks) InitBasicAuth

func (s *Socks) InitBasicAuth() (err error)

func (*Socks) InitService

func (s *Socks) InitService()

func (*Socks) IsBasicAuth

func (s *Socks) IsBasicAuth() bool

func (*Socks) IsDeadLoop

func (s *Socks) IsDeadLoop(inLocalAddr string, host string) bool

func (*Socks) Start

func (s *Socks) Start(args interface{}) (err error)

func (*Socks) StopService

func (s *Socks) StopService()

func (*Socks) UDPKey

func (s *Socks) UDPKey() []byte

type SocksArgs

type SocksArgs struct {
	Parent         *string
	ParentType     *string
	Local          *string
	LocalType      *string
	CertFile       *string
	KeyFile        *string
	CertBytes      []byte
	KeyBytes       []byte
	SSHKeyFile     *string
	SSHKeyFileSalt *string
	SSHPassword    *string
	SSHUser        *string
	SSHKeyBytes    []byte
	SSHAuthMethod  ssh.AuthMethod
	Timeout        *int
	Always         *bool
	Interval       *int
	Blocked        *string
	Direct         *string
	AuthFile       *string
	Auth           *[]string
	AuthURL        *string
	AuthURLOkCode  *int
	AuthURLTimeout *int
	AuthURLRetry   *int
	KCPMethod      *string
	KCPKey         *string
	UDPParent      *string
	UDPLocal       *string
	LocalIPS       *[]string
}

type TCP

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

func (*TCP) CheckArgs

func (s *TCP) CheckArgs()

func (*TCP) Clean

func (s *TCP) Clean()

func (*TCP) InitOutConnPool

func (s *TCP) InitOutConnPool()

func (*TCP) InitService

func (s *TCP) InitService()

func (*TCP) OutToTCP

func (s *TCP) OutToTCP(inConn *net.Conn) (err error)

func (*TCP) OutToUDP

func (s *TCP) OutToUDP(inConn *net.Conn) (err error)

func (*TCP) Start

func (s *TCP) Start(args interface{}) (err error)

func (*TCP) StopService

func (s *TCP) StopService()

type TCPArgs

type TCPArgs struct {
	Parent              *string
	CertFile            *string
	KeyFile             *string
	CertBytes           []byte
	KeyBytes            []byte
	Local               *string
	ParentType          *string
	LocalType           *string
	Timeout             *int
	PoolSize            *int
	CheckParentInterval *int
	KCPMethod           *string
	KCPKey              *string
}

func (*TCPArgs) Protocol

func (a *TCPArgs) Protocol() string

type TunnelBridge

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

func (*TunnelBridge) CheckArgs

func (s *TunnelBridge) CheckArgs()

func (*TunnelBridge) Clean

func (s *TunnelBridge) Clean()

func (*TunnelBridge) InitService

func (s *TunnelBridge) InitService()

func (*TunnelBridge) Start

func (s *TunnelBridge) Start(args interface{}) (err error)

func (*TunnelBridge) StopService

func (s *TunnelBridge) StopService()

type TunnelBridgeArgs

type TunnelBridgeArgs struct {
	Parent    *string
	CertFile  *string
	KeyFile   *string
	CertBytes []byte
	KeyBytes  []byte
	Local     *string
	Timeout   *int
	Mux       *bool
}

type TunnelClient

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

func (*TunnelClient) CheckArgs

func (s *TunnelClient) CheckArgs()
			//close all connection
			s.cm.RemoveAll()
			if s.ctrlConn != nil {
				s.ctrlConn.Close()
			}
			utils.CloseConn(&heartbeatConn)
			heartbeatConn, err := s.GetInConn(CONN_CLIENT_HEARBEAT, ID)
			if err != nil {
				log.Printf("heartbeat connection err: %s, retrying...", err)
				time.Sleep(time.Second * 3)
				utils.CloseConn(&heartbeatConn)
				continue
			}
			log.Printf("heartbeat connection created,id:%s", ID)
			writeDie := make(chan bool)
			readDie := make(chan bool)
			go func() {
				for {
					heartbeatConn.SetWriteDeadline(time.Now().Add(time.Second * 3))
					_, err = heartbeatConn.Write([]byte{0x00})
					heartbeatConn.SetWriteDeadline(time.Time{})
					if err != nil {
						log.Printf("heartbeat connection write err %s", err)
						break
					}
					time.Sleep(time.Second * 3)
				}
				close(writeDie)
			}()
			go func() {
				for {
					signal := make([]byte, 1)
					heartbeatConn.SetReadDeadline(time.Now().Add(time.Second * 6))
					_, err := heartbeatConn.Read(signal)
					heartbeatConn.SetReadDeadline(time.Time{})
					if err != nil {
						log.Printf("heartbeat connection read err: %s", err)
						break
					} else {
						//log.Printf("heartbeat from bridge")
					}
				}
				close(readDie)
			}()
			select {
			case <-readDie:
			case <-writeDie:
			}
		}
	}()
}

func (*TunnelClient) Clean

func (s *TunnelClient) Clean()

func (*TunnelClient) GetConn

func (s *TunnelClient) GetConn() (conn net.Conn, err error)

func (*TunnelClient) GetInConn

func (s *TunnelClient) GetInConn(typ uint8, data ...string) (outConn net.Conn, err error)

func (*TunnelClient) InitService

func (s *TunnelClient) InitService()

func (*TunnelClient) ServeConn

func (s *TunnelClient) ServeConn(localAddr, ID, serverID string)

func (*TunnelClient) ServeUDP

func (s *TunnelClient) ServeUDP(localAddr, ID, serverID string)

func (*TunnelClient) Start

func (s *TunnelClient) Start(args interface{}) (err error)

func (*TunnelClient) StopService

func (s *TunnelClient) StopService()

type TunnelClientArgs

type TunnelClientArgs struct {
	Parent    *string
	CertFile  *string
	KeyFile   *string
	CertBytes []byte
	KeyBytes  []byte
	Key       *string
	Timeout   *int
	Mux       *bool
}

type TunnelServer

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

func (*TunnelServer) CheckArgs

func (s *TunnelServer) CheckArgs()

func (*TunnelServer) Clean

func (s *TunnelServer) Clean()

func (*TunnelServer) GetConn

func (s *TunnelServer) GetConn() (conn net.Conn, err error)

func (*TunnelServer) GetOutConn

func (s *TunnelServer) GetOutConn(typ uint8) (outConn net.Conn, ID string, err error)

func (*TunnelServer) InitService

func (s *TunnelServer) InitService()

func (*TunnelServer) Start

func (s *TunnelServer) Start(args interface{}) (err error)

func (*TunnelServer) UDPConnDeamon

func (s *TunnelServer) UDPConnDeamon()

type TunnelServerArgs

type TunnelServerArgs struct {
	Parent    *string
	CertFile  *string
	KeyFile   *string
	CertBytes []byte
	KeyBytes  []byte
	Local     *string
	IsUDP     *bool
	Key       *string
	Remote    *string
	Timeout   *int
	Route     *[]string
	Mgr       *TunnelServerManager
	Mux       *bool
}

type TunnelServerManager

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

func (*TunnelServerManager) CheckArgs

func (s *TunnelServerManager) CheckArgs()

func (*TunnelServerManager) Clean

func (s *TunnelServerManager) Clean()

func (*TunnelServerManager) GetConn

func (s *TunnelServerManager) GetConn() (conn net.Conn, err error)

func (*TunnelServerManager) GetOutConn

func (s *TunnelServerManager) GetOutConn(typ uint8) (outConn net.Conn, ID string, err error)
func (s *TunnelServerManager) InitHeartbeatDeamon() {
	log.Printf("heartbeat started")
	go func() {
		var heartbeatConn net.Conn
		var ID string
		for {
			//close all connection
			s.cm.Remove(ID)
			utils.CloseConn(&heartbeatConn)
			heartbeatConn, ID, err := s.GetOutConn(CONN_SERVER_HEARBEAT)
			if err != nil {
				log.Printf("heartbeat connection err: %s, retrying...", err)
				time.Sleep(time.Second * 3)
				utils.CloseConn(&heartbeatConn)
				continue
			}
			log.Printf("heartbeat connection created,id:%s", ID)
			writeDie := make(chan bool)
			readDie := make(chan bool)
			go func() {
				for {
					heartbeatConn.SetWriteDeadline(time.Now().Add(time.Second * 3))
					_, err = heartbeatConn.Write([]byte{0x00})
					heartbeatConn.SetWriteDeadline(time.Time{})
					if err != nil {
						log.Printf("heartbeat connection write err %s", err)
						break
					}
					time.Sleep(time.Second * 3)
				}
				close(writeDie)
			}()
			go func() {
				for {
					signal := make([]byte, 1)
					heartbeatConn.SetReadDeadline(time.Now().Add(time.Second * 6))
					_, err := heartbeatConn.Read(signal)
					heartbeatConn.SetReadDeadline(time.Time{})
					if err != nil {
						log.Printf("heartbeat connection read err: %s", err)
						break
					} else {
						// log.Printf("heartbeat from bridge")
					}
				}
				close(readDie)
			}()
			select {
			case <-readDie:
			case <-writeDie:
			}
		}
	}()
}

func (*TunnelServerManager) InitService

func (s *TunnelServerManager) InitService()

func (*TunnelServerManager) Start

func (s *TunnelServerManager) Start(args interface{}) (err error)

func (*TunnelServerManager) StopService

func (s *TunnelServerManager) StopService()

type UDP

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

func (*UDP) CheckArgs

func (s *UDP) CheckArgs()

func (*UDP) Clean

func (s *UDP) Clean()

func (*UDP) GetConn

func (s *UDP) GetConn(connKey string) (conn net.Conn, isNew bool, err error)

func (*UDP) InitOutConnPool

func (s *UDP) InitOutConnPool()

func (*UDP) InitService

func (s *UDP) InitService()

func (*UDP) OutToTCP

func (s *UDP) OutToTCP(packet []byte, localAddr, srcAddr *net.UDPAddr) (err error)

func (*UDP) OutToUDP

func (s *UDP) OutToUDP(packet []byte, localAddr, srcAddr *net.UDPAddr) (err error)

func (*UDP) Start

func (s *UDP) Start(args interface{}) (err error)

func (*UDP) StopService

func (s *UDP) StopService()

type UDPArgs

type UDPArgs struct {
	Parent              *string
	CertFile            *string
	KeyFile             *string
	CertBytes           []byte
	KeyBytes            []byte
	Local               *string
	ParentType          *string
	Timeout             *int
	PoolSize            *int
	CheckParentInterval *int
}

type UDPItem

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

Jump to

Keyboard shortcuts

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