server

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxConcurrentConnection         = 20480
	OverloadConnectionThreshold     = MaxConcurrentConnection * 4 / 5 // 80%
	BlockAddrRefreshRate            = 20                              // 20 seconds
	BlockAddrExpireTime             = 90                              // 90 seconds
	PreCheckThreatCountBeforeBlock  = 5                               // block source address if packet precheck errors exceeds this count
	DefaultAgentConnectionTimeoutMs = 30 * 1000                       // 30 seconds to delete idle connection
	DefaultACConnectionTimeoutMs    = 300 * 1000                      // 300 seconds to delete idle connection
	PacketQueueSizePerConnection    = 64
)
View Source
const (
	DefaultIpOpenTime         = 120 // second, align with ipset default timeout
	ACOpenCompensationTime    = 5   // second
	TokenStoreRefreshInterval = 10  // second
)

knock

View Source
const (
	HttpTransactionTimeout = 3 // second
)

http APIs

Variables

View Source
var (
	ExeDirPath string
)

Functions

func CheckZtdoPower added in v0.4.1

func CheckZtdoPower(config common.DRGMsg, ppd *core.PacketParserData) common.DAGMsg

func LoadFilesRecursively

func LoadFilesRecursively(g *gin.Engine, dir string)

LoadFilesRecursively loads HTML and template files recursively from the specified directory and adds them to the given gin.Engine. It walks through the directory and its subdirectories, and for each file with a .html or .tmpl extension, it reads the file content, creates a new template with the file path as the template name, and parses the content into the template. The loaded templates are set as the HTML templates for the gin.Engine. The directory path should be a clean absolute path. If any error occurs during the file loading or template parsing, the function returns the error.

func ReadZdtoConfig added in v0.4.1

func ReadZdtoConfig(doId string) (common.DRGMsg, error)

read ztdo-config.json to DRGMsg Object

func SaveZdtoConfig added in v0.4.1

func SaveZdtoConfig(drgMsg *common.DRGMsg) error

Types

type ACConn

type ACConn struct {
	ConnData       *core.ConnectionData
	ACPeer         *core.UdpPeer
	ACCipherScheme int
	ACId           string
	ServiceId      string
	Apps           []string
}

type ACTokenEntry added in v0.4.1

type ACTokenEntry struct {
	User       *common.AgentUser
	ResourceId string
	ACTokens   map[string]string
	OpenTime   int
	ExpireTime time.Time
}

type BlockAddr

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

type Config

type Config struct {
	PrivateKeyBase64       string `json:"privateKey"`
	Hostname               string `json:"hostname"`
	ListenIp               string `json:"listenIp"`
	ListenPort             int    `json:"listenPort"`
	LogLevel               int    `json:"logLevel"`
	DefaultCipherScheme    int    `json:"defaultCipherScheme"`
	DisableAgentValidation bool   `json:"disableAgentValidation"`
}

type HttpConfig

type HttpConfig struct {
	EnableHttp   bool
	EnableTLS    bool
	HttpListenIp string
	TLSCertFile  string
	TLSKeyFile   string
}

type HttpServer

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

func (*HttpServer) FindPluginHandler

func (hs *HttpServer) FindPluginHandler(aspId string) plugins.PluginHandler

FindPluginHandler returns the plugin handler for the given ASP ID It delegates the task to the underlying UDP server's FindPluginHandler method.

func (*HttpServer) IsRunning

func (hs *HttpServer) IsRunning() bool

func (*HttpServer) NewHttpServerHelper

func (hs *HttpServer) NewHttpServerHelper() *plugins.HttpServerPluginHelper

func (*HttpServer) Start

func (hs *HttpServer) Start(us *UdpServer, hc *HttpConfig) error

Note HttpServer must be started after starting UdpServer, when log and config have been setup

func (*HttpServer) Stop

func (hs *HttpServer) Stop()

Stop stops the HttpServer by setting the running flag to false, closing the stop channel, shutting down the underlying http server, waiting for all goroutines to finish, and logging a message indicating that the HttpServer has been stopped.

type Peers

type Peers struct {
	ACs    []*core.UdpPeer
	Agents []*core.UdpPeer
	DEs    []*core.UdpPeer
}

type TokenStore added in v0.4.1

type TokenStore = map[string]TokenToACMap // upper layer of tokens, indexed by first two characters

type TokenToACMap added in v0.4.1

type TokenToACMap = map[string]*ACTokenEntry // server access token mapped into mutiple AC tokens

type UdpConn

type UdpConn struct {
	ConnData *core.ConnectionData
	// contains filtered or unexported fields
}

func (*UdpConn) Close

func (c *UdpConn) Close()

type UdpServer

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

func (*UdpServer) AddACPeer

func (s *UdpServer) AddACPeer(acPeer *core.UdpPeer)

func (*UdpServer) AddAddressAssociation

func (s *UdpServer) AddAddressAssociation(srcIp string, addrs []*common.NetAddress)

func (*UdpServer) AddAgentPeer

func (s *UdpServer) AddAgentPeer(agent *core.UdpPeer)

func (*UdpServer) AddAuthService

func (s *UdpServer) AddAuthService(aspData *common.AuthServiceProviderData) error

func (*UdpServer) AddBlockAddr

func (s *UdpServer) AddBlockAddr(addr *net.UDPAddr)

func (*UdpServer) AddDEPeer added in v0.4.1

func (s *UdpServer) AddDEPeer(device *core.UdpPeer)

DHP

func (*UdpServer) AddResource

func (s *UdpServer) AddResource(res *common.ResourceData) error

func (*UdpServer) BlockAddrRefreshRoutine

func (s *UdpServer) BlockAddrRefreshRoutine()

func (*UdpServer) ClosePlugins

func (s *UdpServer) ClosePlugins()

func (*UdpServer) FindAuthSvcProvider

func (s *UdpServer) FindAuthSvcProvider(aspId string) *common.AuthServiceProviderData

func (*UdpServer) FindPluginHandler

func (us *UdpServer) FindPluginHandler(aspId string) plugins.PluginHandler

func (*UdpServer) GenerateAccessToken added in v0.4.1

func (s *UdpServer) GenerateAccessToken(entry *ACTokenEntry) string

func (*UdpServer) HandleACOnline

func (s *UdpServer) HandleACOnline(ppd *core.PacketParserData) (err error)

func (*UdpServer) HandleDHPDARMessage added in v0.4.1

func (s *UdpServer) HandleDHPDARMessage(ppd *core.PacketParserData) (err error)

func (*UdpServer) HandleDHPDRGMessage added in v0.4.1

func (s *UdpServer) HandleDHPDRGMessage(ppd *core.PacketParserData) (err error)

HandleDHPDRGMessage

func (*UdpServer) HandleKnockRequest

func (s *UdpServer) HandleKnockRequest(ppd *core.PacketParserData) (err error)

HandleKnockRequest Server will respond with success or error with NHP_ACK message

func (*UdpServer) HandleListRequest

func (s *UdpServer) HandleListRequest(ppd *core.PacketParserData) (err error)

HandleListRequest Server will respond with success or error with NHP_LRT message

func (*UdpServer) HandleOTPRequest

func (s *UdpServer) HandleOTPRequest(ppd *core.PacketParserData) (err error)

HandleOTPRequest Server will not respond to agent's otp request

func (*UdpServer) HandleRegisterRequest

func (s *UdpServer) HandleRegisterRequest(ppd *core.PacketParserData) (err error)

HandleRegisterRequest Server will respond with success or error with NHP_RAK message

func (*UdpServer) IsBlockAddr

func (s *UdpServer) IsBlockAddr(addr *net.UDPAddr) bool

func (*UdpServer) IsRunning

func (s *UdpServer) IsRunning() bool

func (*UdpServer) LoadPlugin

func (s *UdpServer) LoadPlugin(pluginId string, h plugins.PluginHandler) error

func (*UdpServer) NewNhpServerHelper

func (us *UdpServer) NewNhpServerHelper(ppd *core.PacketParserData) *plugins.NhpServerPluginHelper

func (*UdpServer) RefreshBlockAddr

func (s *UdpServer) RefreshBlockAddr()

func (*UdpServer) RemoveAddressAssociation

func (s *UdpServer) RemoveAddressAssociation(srcIp string)

func (*UdpServer) SendPacket

func (s *UdpServer) SendPacket(pkt *core.Packet, conn *UdpConn) (n int, err error)

func (*UdpServer) Start

func (s *UdpServer) Start(dirPath string, logLevel int) (err error)

dirPath: the path of app or shared library entry point logLevel: 0: silent, 1: error, 2: info, 3: debug, 4: verbose

UDP server never actively sends first packet outwards. It only reacts to received packet then sends response.

func (*UdpServer) Stop

func (s *UdpServer) Stop()

func (*UdpServer) StopConfigWatch

func (s *UdpServer) StopConfigWatch()

func (*UdpServer) ValidatePlugin

func (s *UdpServer) ValidatePlugin(h plugins.PluginHandler) bool

func (*UdpServer) VerifyAccessToken added in v0.4.1

func (s *UdpServer) VerifyAccessToken(token string) *ACTokenEntry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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