network

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetID

func GetID(network, address string, seed int, logger zerolog.Logger) string

GetID returns a unique ID (hash) for a network connection.

func IsConnClosed added in v0.1.4

func IsConnClosed(received int, err *gerr.GatewayDError) bool

IsConnClosed returns true if the connection is closed.

func IsConnTimedOut added in v0.1.4

func IsConnTimedOut(err *gerr.GatewayDError) bool

IsConnTimedOut returns true if the error is a timeout error.

func LocalAddr added in v0.6.9

func LocalAddr(gconn gnet.Conn) string

LocalAddr returns the local address of the connection.

func RemoteAddr added in v0.6.9

func RemoteAddr(gconn gnet.Conn) string

RemoteAddr returns the remote address of the connection.

func Resolve added in v0.0.2

func Resolve(network, address string, logger zerolog.Logger) (string, *gerr.GatewayDError)

Resolve resolves a network address.

Types

type Client

type Client struct {
	net.Conn

	TCPKeepAlive       bool
	TCPKeepAlivePeriod time.Duration
	ReceiveChunkSize   int
	ReceiveDeadline    time.Duration
	SendDeadline       time.Duration
	ID                 string
	Network            string // tcp/udp/unix
	Address            string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, clientConfig *config.Client, logger zerolog.Logger) *Client

NewClient creates a new client.

func (*Client) Close

func (c *Client) Close()

Close closes the connection to the server.

func (*Client) IsConnected added in v0.1.0

func (c *Client) IsConnected() bool

IsConnected checks if the client is still connected to the server.

func (*Client) LocalAddr added in v0.6.9

func (c *Client) LocalAddr() string

LocalAddr returns the local address of the client safely.

func (*Client) Receive

func (c *Client) Receive() (int, []byte, *gerr.GatewayDError)

Receive receives data from the server.

func (*Client) RemoteAddr added in v0.6.9

func (c *Client) RemoteAddr() string

RemoteAddr returns the remote address of the client safely.

func (*Client) Send

func (c *Client) Send(data []byte) (int, *gerr.GatewayDError)

Send sends data to the server.

type Field added in v0.2.3

type Field struct {
	Name  string
	Value []byte
}

type IClient added in v0.2.2

type IClient interface {
	Send(data []byte) (int, *gerr.GatewayDError)
	Receive() (int, []byte, *gerr.GatewayDError)
	Close()
	IsConnected() bool
	RemoteAddr() string
	LocalAddr() string
}

type IProxy added in v0.2.2

type IProxy interface {
	Connect(gconn gnet.Conn) *gerr.GatewayDError
	Disconnect(gconn gnet.Conn) *gerr.GatewayDError
	PassThrough(gconn gnet.Conn) *gerr.GatewayDError
	IsHealty(cl *Client) (*Client, *gerr.GatewayDError)
	IsExhausted() bool
	Shutdown()
	AvailableConnections() []string
	BusyConnections() []string
}

type Proxy

type Proxy struct {
	Elastic             bool
	ReuseElasticClients bool
	HealthCheckPeriod   time.Duration

	// ClientConfig is used for elastic proxy and reconnection
	ClientConfig *config.Client
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy(
	ctx context.Context,
	connPool pool.IPool, pluginRegistry *plugin.Registry,
	elastic, reuseElasticClients bool,
	healthCheckPeriod time.Duration,
	clientConfig *config.Client, logger zerolog.Logger,
	pluginTimeout time.Duration,
) *Proxy

NewProxy creates a new proxy.

func (*Proxy) AvailableConnections added in v0.5.0

func (pr *Proxy) AvailableConnections() []string

AvailableConnections returns a list of available connections.

func (*Proxy) BusyConnections added in v0.5.0

func (pr *Proxy) BusyConnections() []string

BusyConnections returns a list of busy connections.

func (*Proxy) Connect

func (pr *Proxy) Connect(gconn gnet.Conn) *gerr.GatewayDError

Connect maps a server connection from the available connection pool to a incoming connection. It returns an error if the pool is exhausted. If the pool is elastic, it creates a new client and maps it to the incoming connection.

func (*Proxy) Disconnect

func (pr *Proxy) Disconnect(gconn gnet.Conn) *gerr.GatewayDError

Disconnect removes the client from the busy connection pool and tries to recycle the server connection.

func (*Proxy) IsExhausted added in v0.1.0

func (pr *Proxy) IsExhausted() bool

IsExhausted checks if the available connection pool is exhausted.

func (*Proxy) IsHealty added in v0.1.3

func (pr *Proxy) IsHealty(client *Client) (*Client, *gerr.GatewayDError)

IsHealty checks if the pool is exhausted or the client is disconnected.

func (*Proxy) PassThrough

func (pr *Proxy) PassThrough(gconn gnet.Conn) *gerr.GatewayDError

PassThrough sends the data from the client to the server and vice versa.

func (*Proxy) Shutdown

func (pr *Proxy) Shutdown()

Shutdown closes all connections and clears the connection pools.

type Server

type Server struct {
	gnet.BuiltinEventEngine

	Network      string // tcp/udp/unix
	Address      string
	Options      []gnet.Option
	SoftLimit    uint64
	HardLimit    uint64
	Status       config.Status
	TickInterval time.Duration
	// contains filtered or unexported fields
}

func NewServer added in v0.0.2

func NewServer(
	ctx context.Context,
	network, address string,
	softLimit, hardLimit uint64,
	tickInterval time.Duration,
	options []gnet.Option,
	proxy IProxy,
	logger zerolog.Logger,
	pluginRegistry *plugin.Registry,
	pluginTimeout time.Duration,
) *Server

NewServer creates a new server.

func (*Server) IsRunning added in v0.0.2

func (s *Server) IsRunning() bool

IsRunning returns true if the server is running.

func (*Server) OnBoot

func (s *Server) OnBoot(engine gnet.Engine) gnet.Action

OnBoot is called when the server is booted. It calls the OnBooting and OnBooted hooks. It also sets the status to running, which is used to determine if the server should be running or shutdown.

func (*Server) OnClose

func (s *Server) OnClose(gconn gnet.Conn, err error) gnet.Action

OnClose is called when a connection is closed. It calls the OnClosing and OnClosed hooks. It also recycles the connection back to the available connection pool, unless the pool is elastic and reuse is disabled.

func (*Server) OnOpen

func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action)

OnOpen is called when a new connection is opened. It calls the OnOpening and OnOpened hooks. It also checks if the server is at the soft or hard limit and closes the connection if it is.

func (*Server) OnShutdown

func (s *Server) OnShutdown(gnet.Engine)

OnShutdown is called when the server is shutting down. It calls the OnShutdown hooks.

func (*Server) OnTick

func (s *Server) OnTick() (time.Duration, gnet.Action)

OnTick is called every TickInterval. It calls the OnTick hooks.

func (*Server) OnTraffic

func (s *Server) OnTraffic(gconn gnet.Conn) gnet.Action

OnTraffic is called when data is received from the client. It calls the OnTraffic hooks. It then passes the traffic to the proxied connection.

func (*Server) Run

func (s *Server) Run() error

Run starts the server and blocks until the server is stopped. It calls the OnRun hooks.

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown stops the server.

Jump to

Keyboard shortcuts

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