gate

package
v2.6.7 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 36 Imported by: 7

Documentation

Overview

Package gate implements the gate server component.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gate

type Gate struct {
	component.Base
	// contains filtered or unexported fields
}

Gate is the gate server component.

func NewGate

func NewGate(opts ...Option) *Gate

NewGate returns a new gate server component configured by the given options.

func (*Gate) Close added in v2.2.3

func (g *Gate) Close()

Close closes the gate.

It switches the state to Hang and refreshes the service instance state, then waits for all online client sessions to exit naturally (graceful shutdown semantics).

func (*Gate) Destroy

func (g *Gate) Destroy()

Destroy destroys the component.

It deregisters the service instance, stops the network server and the link server in turn, closes the clients to the business nodes, and cancels the component context.

func (*Gate) Init

func (g *Gate) Init()

Init initializes the component.

It validates whether the instance ID and the required components (server, locator and registry) have been injected.

func (*Gate) Name

func (g *Gate) Name() string

Name returns the component name.

func (*Gate) Start

func (g *Gate) Start()

Start starts the component.

It starts the network server and the internal link server in turn, registers the service instance, watches user locations and cluster instances, and prints the component information.

type Option

type Option func(o *options)

Option is a gate option.

func WithAddr added in v2.3.0

func WithAddr(addr string) Option

WithAddr sets the listen address.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context.

func WithDispatch added in v2.3.0

func WithDispatch(dispatch cluster.Dispatch) Option

WithDispatch sets the dispatch strategy of stateless route messages.

func WithExpose added in v2.3.0

func WithExpose(expose bool) Option

WithExpose sets whether the internal communication address is exposed to the public network.

func WithGuardAcceptRate added in v2.6.7

func WithGuardAcceptRate(quota float64, period time.Duration) Option

WithGuardAcceptRate sets the connection admission rate per IP. A zero quota disables the limit.

func WithGuardMaxBanDuration added in v2.6.7

func WithGuardMaxBanDuration(duration time.Duration) Option

WithGuardMaxBanDuration sets the maximum ban duration. A non-positive duration is ignored.

func WithGuardMaxConns added in v2.6.7

func WithGuardMaxConns(maxConns int) Option

WithGuardMaxConns sets the maximum number of concurrent connections allowed per IP. A zero value disables the limit.

func WithGuardMaxEntries added in v2.6.7

func WithGuardMaxEntries(maxEntries int) Option

WithGuardMaxEntries sets the maximum number of IP entries retained by the guard. A non-positive value is ignored.

func WithGuardMinBanDuration added in v2.6.7

func WithGuardMinBanDuration(duration time.Duration) Option

WithGuardMinBanDuration sets the first ban duration. A non-positive duration is ignored.

func WithGuardStrikeThreshold added in v2.6.7

func WithGuardStrikeThreshold(threshold int) Option

WithGuardStrikeThreshold sets the number of violations within the strike window that triggers a ban. Violations include connection admission rejections and, when the connection limiter is enabled, close signals emitted by the message rate limiter. A zero threshold disables automatic bans.

func WithGuardStrikeWindow added in v2.6.7

func WithGuardStrikeWindow(window time.Duration) Option

WithGuardStrikeWindow sets the strike window.

func WithGuardWhitelist added in v2.6.7

func WithGuardWhitelist(whitelist []string) Option

WithGuardWhitelist sets the IP whitelist.

func WithID

func WithID(id string) Option

WithID sets the instance ID.

func WithLimiterBurst added in v2.6.7

func WithLimiterBurst(burst int) Option

WithLimiterBurst sets the rate limit burst.

func WithLimiterCloseThreshold added in v2.6.7

func WithLimiterCloseThreshold(threshold int) Option

WithLimiterCloseThreshold sets the number of consecutive limited messages that closes the connection. A zero threshold disables closing.

func WithLimiterPeriod added in v2.6.7

func WithLimiterPeriod(period time.Duration) Option

WithLimiterPeriod sets the rate limit period.

func WithLimiterQuota added in v2.6.7

func WithLimiterQuota(quota float64) Option

WithLimiterQuota sets the rate limit quota. A zero quota disables rate limiting and overrides a quota configured through etc.

The limit applies to business frames only. Heartbeat frames are handled before the receive handler. When session security is enabled, handshake frames are routed to the security manager and also bypass the limit.

func WithLinkerCallTimeout added in v2.6.0

func WithLinkerCallTimeout(callTimeout time.Duration) Option

WithLinkerCallTimeout sets the RPC call timeout.

func WithLinkerCommandQueueSize added in v2.6.0

func WithLinkerCommandQueueSize(commandQueueSize int32) Option

WithLinkerCommandQueueSize sets the message queue size.

func WithLinkerCommandWriteTimeout added in v2.6.0

func WithLinkerCommandWriteTimeout(commandWriteTimeout time.Duration) Option

WithLinkerCommandWriteTimeout sets the write timeout.

func WithLinkerConnNum added in v2.6.0

func WithLinkerConnNum(connNum int) Option

WithLinkerConnNum sets the number of connections.

func WithLinkerDialRetryTimes added in v2.6.0

func WithLinkerDialRetryTimes(dialRetryTimes int) Option

WithLinkerDialRetryTimes sets the number of internal RPC dial retries.

func WithLinkerDialTimeout added in v2.6.0

func WithLinkerDialTimeout(dialTimeout time.Duration) Option

WithLinkerDialTimeout sets the internal RPC dial timeout.

func WithLinkerFaultRecoveryTime added in v2.6.0

func WithLinkerFaultRecoveryTime(faultRecoveryTime time.Duration) Option

WithLinkerFaultRecoveryTime sets the internal RPC fault recovery time.

func WithLocator

func WithLocator(locator locate.Locator) Option

WithLocator sets the user locator.

func WithMetadata added in v2.3.0

func WithMetadata(metadata map[string]string) Option

WithMetadata sets the metadata.

func WithName

func WithName(name string) Option

WithName sets the instance name.

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry sets the service registry.

func WithServer

func WithServer(server network.Server) Option

WithServer sets the server.

func WithSessionSecurity added in v2.6.3

func WithSessionSecurity(signer crypto.Signer, suites ...aead.Suite) Option

WithSessionSecurity enables the session security between the client and the gate.

signer signs the ServerHello so that the client can verify the gate with the pinned public key. When no suite is given, the handshake defaults are used. When enabled, the payload of client messages is decrypted by the gate and re-encrypted for the downlink, so the node-side static encryptor must stay unconfigured.

func WithSessionSecurityHandshakeTimeout added in v2.6.3

func WithSessionSecurityHandshakeTimeout(timeout time.Duration) Option

WithSessionSecurityHandshakeTimeout sets how long the gate waits for a client to complete the session security handshake. A zero duration disables the timeout.

Jump to

Keyboard shortcuts

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