server

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinPort                    = 1
	MaxPort                    = 65535
	MaxPortReservedDuration    = time.Duration(24) * time.Hour
	CleanReservedPortsInterval = time.Hour
)
View Source
const (
	ReserveDays = 7
)

Variables

View Source
var (
	ErrPortAlreadyUsed = errors.New("port already used")
	ErrPortNotAllowed  = errors.New("port not allowed")
	ErrPortUnAvailable = errors.New("port unavailable")
	ErrNoAvailablePort = errors.New("no available port")
)
View Source
var NatHoleTimeout int64 = 10

Timeout seconds.

Functions

func HandleUserTcpConnection

func HandleUserTcpConnection(pxy Proxy, userConn frpNet.Conn)

HandleUserTcpConnection is used for incoming tcp user connections. It can be used for tcp, http, https type.

func RunDashboardServer

func RunDashboardServer(addr string, port int) (err error)

func StatsAddTrafficIn

func StatsAddTrafficIn(name string, trafficIn int64)

func StatsAddTrafficOut

func StatsAddTrafficOut(name string, trafficOut int64)

func StatsClearUselessInfo added in v0.11.0

func StatsClearUselessInfo()

func StatsCloseClient

func StatsCloseClient()

func StatsCloseConnection

func StatsCloseConnection(name string)

func StatsCloseProxy

func StatsCloseProxy(proxyName string, proxyType string)

func StatsNewClient

func StatsNewClient()

func StatsNewProxy

func StatsNewProxy(name string, proxyType string)

func StatsOpenConnection

func StatsOpenConnection(name string)

Types

type BaseProxy

type BaseProxy struct {
	log.Logger
	// contains filtered or unexported fields
}

func (*BaseProxy) Close

func (pxy *BaseProxy) Close()

func (*BaseProxy) GetControl

func (pxy *BaseProxy) GetControl() *Control

func (*BaseProxy) GetName

func (pxy *BaseProxy) GetName() string

func (*BaseProxy) GetUsedPortsNum added in v0.16.0

func (pxy *BaseProxy) GetUsedPortsNum() int

func (*BaseProxy) GetWorkConnFromPool

func (pxy *BaseProxy) GetWorkConnFromPool() (workConn frpNet.Conn, err error)

type Control

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

func NewControl

func NewControl(svr *Service, ctlConn net.Conn, loginMsg *msg.Login) *Control

func (*Control) CloseProxy added in v0.12.0

func (ctl *Control) CloseProxy(closeMsg *msg.CloseProxy) (err error)

func (*Control) GetWorkConn

func (ctl *Control) GetWorkConn() (workConn net.Conn, err error)

When frps get one user connection, we get one work connection from the pool and return it. If no workConn available in the pool, send message to frpc to get one or more and wait until it is available. return an error if wait timeout

func (*Control) RegisterProxy

func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err error)

func (*Control) RegisterWorkConn

func (ctl *Control) RegisterWorkConn(conn net.Conn)

func (*Control) Replaced

func (ctl *Control) Replaced(newCtl *Control)

func (*Control) Start

func (ctl *Control) Start()

Start send a login success message to client and start working.

type ControlManager

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

func NewControlManager

func NewControlManager() *ControlManager

func (*ControlManager) Add

func (cm *ControlManager) Add(runId string, ctl *Control) (oldCtl *Control)

func (*ControlManager) GetById

func (cm *ControlManager) GetById(runId string) (ctl *Control, ok bool)

type GeneralResponse

type GeneralResponse struct {
	Code int64  `json:"code"`
	Msg  string `json:"msg"`
}

type GetProxyInfoResp

type GetProxyInfoResp struct {
	GeneralResponse
	Proxies []*ProxyStatsInfo `json:"proxies"`
}

type GetProxyStatsResp added in v0.17.0

type GetProxyStatsResp struct {
	GeneralResponse

	Name            string           `json:"name"`
	Conf            config.ProxyConf `json:"conf"`
	TodayTrafficIn  int64            `json:"today_traffic_in"`
	TodayTrafficOut int64            `json:"today_traffic_out"`
	CurConns        int64            `json:"cur_conns"`
	LastStartTime   string           `json:"last_start_time"`
	LastCloseTime   string           `json:"last_close_time"`
	Status          string           `json:"status"`
}

Get proxy info by name.

type GetProxyTrafficResp

type GetProxyTrafficResp struct {
	GeneralResponse

	Name       string  `json:"name"`
	TrafficIn  []int64 `json:"traffic_in"`
	TrafficOut []int64 `json:"traffic_out"`
}

api/proxy/traffic/:name

type HttpProxy

type HttpProxy struct {
	BaseProxy
	// contains filtered or unexported fields
}

func (*HttpProxy) Close

func (pxy *HttpProxy) Close()

func (*HttpProxy) GetConf

func (pxy *HttpProxy) GetConf() config.ProxyConf

func (*HttpProxy) GetRealConn added in v0.14.1

func (pxy *HttpProxy) GetRealConn() (workConn frpNet.Conn, err error)

func (*HttpProxy) Run

func (pxy *HttpProxy) Run() (remoteAddr string, err error)

type HttpsProxy

type HttpsProxy struct {
	BaseProxy
	// contains filtered or unexported fields
}

func (*HttpsProxy) Close

func (pxy *HttpsProxy) Close()

func (*HttpsProxy) GetConf

func (pxy *HttpsProxy) GetConf() config.ProxyConf

func (*HttpsProxy) Run

func (pxy *HttpsProxy) Run() (remoteAddr string, err error)

type NatHoleClientCfg added in v0.14.0

type NatHoleClientCfg struct {
	Name  string
	Sk    string
	SidCh chan string
}

type NatHoleController added in v0.14.0

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

func NewNatHoleController added in v0.14.0

func NewNatHoleController(udpBindAddr string) (nc *NatHoleController, err error)

func (*NatHoleController) CloseClient added in v0.14.0

func (nc *NatHoleController) CloseClient(name string)

func (*NatHoleController) GenNatHoleResponse added in v0.14.0

func (nc *NatHoleController) GenNatHoleResponse(raddr *net.UDPAddr, session *NatHoleSession) []byte

func (*NatHoleController) GenSid added in v0.14.0

func (nc *NatHoleController) GenSid() string

func (*NatHoleController) HandleClient added in v0.14.0

func (nc *NatHoleController) HandleClient(m *msg.NatHoleClient, raddr *net.UDPAddr)

func (*NatHoleController) HandleVisitor added in v0.14.0

func (nc *NatHoleController) HandleVisitor(m *msg.NatHoleVisitor, raddr *net.UDPAddr)

func (*NatHoleController) ListenClient added in v0.14.0

func (nc *NatHoleController) ListenClient(name string, sk string) (sidCh chan string)

func (*NatHoleController) Run added in v0.14.0

func (nc *NatHoleController) Run()

type NatHoleSession added in v0.14.0

type NatHoleSession struct {
	Sid         string
	VisitorAddr *net.UDPAddr
	ClientAddr  *net.UDPAddr

	NotifyCh chan struct{}
}

type PortCtx added in v0.15.0

type PortCtx struct {
	ProxyName  string
	Port       int
	Closed     bool
	UpdateTime time.Time
}

type PortManager added in v0.15.0

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

func NewPortManager added in v0.15.0

func NewPortManager(netType string, bindAddr string, allowPorts map[int]struct{}) *PortManager

func (*PortManager) Acquire added in v0.15.0

func (pm *PortManager) Acquire(name string, port int) (realPort int, err error)

func (*PortManager) Release added in v0.15.0

func (pm *PortManager) Release(port int)

type Proxy

type Proxy interface {
	Run() (remoteAddr string, err error)
	GetControl() *Control
	GetName() string
	GetConf() config.ProxyConf
	GetWorkConnFromPool() (workConn frpNet.Conn, err error)
	GetUsedPortsNum() int
	Close()
	log.Logger
}

func NewProxy

func NewProxy(ctl *Control, pxyConf config.ProxyConf) (pxy Proxy, err error)

type ProxyManager

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

func NewProxyManager

func NewProxyManager() *ProxyManager

func (*ProxyManager) Add

func (pm *ProxyManager) Add(name string, pxy Proxy) error

func (*ProxyManager) Del

func (pm *ProxyManager) Del(name string)

func (*ProxyManager) GetByName

func (pm *ProxyManager) GetByName(name string) (pxy Proxy, ok bool)

type ProxyStatistics

type ProxyStatistics struct {
	Name          string
	ProxyType     string
	TrafficIn     metric.DateCounter
	TrafficOut    metric.DateCounter
	CurConns      metric.Counter
	LastStartTime time.Time
	LastCloseTime time.Time
}

type ProxyStats

type ProxyStats struct {
	Name            string
	Type            string
	TodayTrafficIn  int64
	TodayTrafficOut int64
	LastStartTime   string
	LastCloseTime   string
	CurConns        int64
}

func StatsGetProxiesByType

func StatsGetProxiesByType(proxyType string) []*ProxyStats

func StatsGetProxiesByTypeAndName added in v0.17.0

func StatsGetProxiesByTypeAndName(proxyType string, proxyName string) (res *ProxyStats)

type ProxyStatsInfo

type ProxyStatsInfo struct {
	Name            string           `json:"name"`
	Conf            config.ProxyConf `json:"conf"`
	TodayTrafficIn  int64            `json:"today_traffic_in"`
	TodayTrafficOut int64            `json:"today_traffic_out"`
	CurConns        int64            `json:"cur_conns"`
	LastStartTime   string           `json:"last_start_time"`
	LastCloseTime   string           `json:"last_close_time"`
	Status          string           `json:"status"`
}

Get proxy info.

type ProxyTrafficInfo

type ProxyTrafficInfo struct {
	Name       string
	TrafficIn  []int64
	TrafficOut []int64
}

func StatsGetProxyTraffic

func StatsGetProxyTraffic(name string) (res *ProxyTrafficInfo)

type ServerInfoResp

type ServerInfoResp struct {
	GeneralResponse

	Version          string `json:"version"`
	VhostHttpPort    int    `json:"vhost_http_port"`
	VhostHttpsPort   int    `json:"vhost_https_port"`
	AuthTimeout      int64  `json:"auth_timeout"`
	SubdomainHost    string `json:"subdomain_host"`
	MaxPoolCount     int64  `json:"max_pool_count"`
	HeartBeatTimeout int64  `json:"heart_beat_timeout"`

	TotalTrafficIn  int64            `json:"total_traffic_in"`
	TotalTrafficOut int64            `json:"total_traffic_out"`
	CurConns        int64            `json:"cur_conns"`
	ClientCounts    int64            `json:"client_counts"`
	ProxyTypeCounts map[string]int64 `json:"proxy_type_count"`
}

api/serverinfo

type ServerStatistics

type ServerStatistics struct {
	TotalTrafficIn  metric.DateCounter
	TotalTrafficOut metric.DateCounter
	CurConns        metric.Counter

	// counter for clients
	ClientCounts metric.Counter

	// counter for proxy types
	ProxyTypeCounts map[string]metric.Counter

	// statistics for different proxies
	// key is proxy name
	ProxyStatistics map[string]*ProxyStatistics
	// contains filtered or unexported fields
}

type ServerStats

type ServerStats struct {
	TotalTrafficIn  int64
	TotalTrafficOut int64
	CurConns        int64
	ClientCounts    int64
	ProxyTypeCounts map[string]int64
}

Functions for getting server stats.

func StatsGetServer

func StatsGetServer() *ServerStats

type Service

type Service struct {

	// For https proxies, route requests to different clients by hostname and other infomation.
	VhostHttpsMuxer *vhost.HttpsMuxer
	// contains filtered or unexported fields
}

Server service.

var ServerService *Service

func NewService

func NewService() (svr *Service, err error)

func (*Service) DelProxy

func (svr *Service) DelProxy(name string)

func (*Service) HandleListener added in v0.12.0

func (svr *Service) HandleListener(l frpNet.Listener)

func (*Service) RegisterControl

func (svr *Service) RegisterControl(ctlConn frpNet.Conn, loginMsg *msg.Login) (err error)

func (*Service) RegisterProxy

func (svr *Service) RegisterProxy(name string, pxy Proxy) error

func (*Service) RegisterVisitorConn added in v0.14.0

func (svr *Service) RegisterVisitorConn(visitorConn frpNet.Conn, newMsg *msg.NewVisitorConn) error

func (*Service) RegisterWorkConn

func (svr *Service) RegisterWorkConn(workConn frpNet.Conn, newMsg *msg.NewWorkConn)

RegisterWorkConn register a new work connection to control and proxies need it.

func (*Service) Run

func (svr *Service) Run()

type StcpProxy added in v0.13.0

type StcpProxy struct {
	BaseProxy
	// contains filtered or unexported fields
}

func (*StcpProxy) Close added in v0.13.0

func (pxy *StcpProxy) Close()

func (*StcpProxy) GetConf added in v0.13.0

func (pxy *StcpProxy) GetConf() config.ProxyConf

func (*StcpProxy) Run added in v0.13.0

func (pxy *StcpProxy) Run() (remoteAddr string, err error)

type TcpProxy

type TcpProxy struct {
	BaseProxy
	// contains filtered or unexported fields
}

func (*TcpProxy) Close

func (pxy *TcpProxy) Close()

func (*TcpProxy) GetConf

func (pxy *TcpProxy) GetConf() config.ProxyConf

func (*TcpProxy) Run

func (pxy *TcpProxy) Run() (remoteAddr string, err error)

type UdpProxy

type UdpProxy struct {
	BaseProxy
	// contains filtered or unexported fields
}

func (*UdpProxy) Close

func (pxy *UdpProxy) Close()

func (*UdpProxy) GetConf

func (pxy *UdpProxy) GetConf() config.ProxyConf

func (*UdpProxy) Run

func (pxy *UdpProxy) Run() (remoteAddr string, err error)

type VisitorManager added in v0.14.0

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

Manager for visitor listeners.

func NewVisitorManager added in v0.14.0

func NewVisitorManager() *VisitorManager

func (*VisitorManager) CloseListener added in v0.14.0

func (vm *VisitorManager) CloseListener(name string)

func (*VisitorManager) Listen added in v0.14.0

func (vm *VisitorManager) Listen(name string, sk string) (l *frpNet.CustomListener, err error)

func (*VisitorManager) NewConn added in v0.14.0

func (vm *VisitorManager) NewConn(name string, conn frpNet.Conn, timestamp int64, signKey string,
	useEncryption bool, useCompression bool) (err error)

type XtcpProxy added in v0.14.0

type XtcpProxy struct {
	BaseProxy
	// contains filtered or unexported fields
}

func (*XtcpProxy) Close added in v0.14.0

func (pxy *XtcpProxy) Close()

func (*XtcpProxy) GetConf added in v0.14.0

func (pxy *XtcpProxy) GetConf() config.ProxyConf

func (*XtcpProxy) Run added in v0.14.0

func (pxy *XtcpProxy) Run() (remoteAddr string, err error)

Jump to

Keyboard shortcuts

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