Documentation
¶
Index ¶
- func GetID(network, address string, seed int, logger zerolog.Logger) string
- func IsConnClosed(received int, err *gerr.GatewayDError) bool
- func IsConnTimedOut(err *gerr.GatewayDError) bool
- func LocalAddr(conn net.Conn) string
- func RemoteAddr(conn net.Conn) string
- func Resolve(network, address string, logger zerolog.Logger) (string, *gerr.GatewayDError)
- type Action
- type Client
- type Engine
- type Field
- type IClient
- type IProxy
- type Option
- type Proxy
- func (pr *Proxy) AvailableConnections() []string
- func (pr *Proxy) BusyConnections() []string
- func (pr *Proxy) Connect(conn net.Conn) *gerr.GatewayDError
- func (pr *Proxy) Disconnect(conn net.Conn) *gerr.GatewayDError
- func (pr *Proxy) IsExhausted() bool
- func (pr *Proxy) IsHealthy(client *Client) (*Client, *gerr.GatewayDError)
- func (pr *Proxy) PassThroughToClient(conn net.Conn, stack *Stack) *gerr.GatewayDError
- func (pr *Proxy) PassThroughToServer(conn net.Conn, stack *Stack) *gerr.GatewayDError
- func (pr *Proxy) Shutdown()
- type Request
- type Server
- func (s *Server) IsRunning() bool
- func (s *Server) OnBoot(engine Engine) Action
- func (s *Server) OnClose(conn net.Conn, err error) Action
- func (s *Server) OnOpen(conn net.Conn) ([]byte, Action)
- func (s *Server) OnShutdown()
- func (s *Server) OnTick() (time.Duration, Action)
- func (s *Server) OnTraffic(conn net.Conn, stopConnection chan struct{}) Action
- func (s *Server) Run() *gerr.GatewayDError
- func (s *Server) Shutdown()
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 RemoteAddr ¶ added in v0.6.9
RemoteAddr returns the remote address of the connection.
Types ¶
type Client ¶
type Client struct {
TCPKeepAlive bool
TCPKeepAlivePeriod time.Duration
ReceiveChunkSize int
ReceiveDeadline time.Duration
SendDeadline time.Duration
ReceiveTimeout time.Duration
ID string
Network string // tcp/udp/unix
Address string
// contains filtered or unexported fields
}
func (*Client) IsConnected ¶ added in v0.1.0
IsConnected checks if the client is still connected to the server.
func (*Client) LocalAddr ¶ added in v0.6.9
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
RemoteAddr returns the remote address of the client safely.
type Engine ¶ added in v0.8.3
type Engine struct {
// contains filtered or unexported fields
}
Engine is the network engine. TODO: Move this to the Server struct.
func (*Engine) CountConnections ¶ added in v0.8.3
CountConnections returns the current number of connections.
type IProxy ¶ added in v0.2.2
type IProxy interface {
Connect(conn net.Conn) *gerr.GatewayDError
Disconnect(conn net.Conn) *gerr.GatewayDError
PassThroughToServer(conn net.Conn, stack *Stack) *gerr.GatewayDError
PassThroughToClient(conn net.Conn, stack *Stack) *gerr.GatewayDError
IsHealthy(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
AvailableConnections returns a list of available connections.
func (*Proxy) BusyConnections ¶ added in v0.5.0
BusyConnections returns a list of busy connections.
func (*Proxy) Connect ¶
func (pr *Proxy) Connect(conn net.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(conn net.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
IsExhausted checks if the available connection pool is exhausted.
func (*Proxy) IsHealthy ¶ added in v0.8.3
func (pr *Proxy) IsHealthy(client *Client) (*Client, *gerr.GatewayDError)
IsHealthy checks if the pool is exhausted or the client is disconnected.
func (*Proxy) PassThroughToClient ¶ added in v0.8.3
PassThroughToClient sends the data from the server to the client.
func (*Proxy) PassThroughToServer ¶ added in v0.8.3
PassThroughToServer sends the data from the client to the server.
type Server ¶
type Server struct {
Network string // tcp/udp/unix
Address string
Options Option
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, tickInterval time.Duration, options Option, proxy IProxy, logger zerolog.Logger, pluginRegistry *plugin.Registry, pluginTimeout time.Duration, ) *Server
NewServer creates a new server.
func (*Server) OnBoot ¶
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 ¶
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 ¶
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()
OnShutdown is called when the server is shutting down. It calls the OnShutdown hooks.
func (*Server) OnTraffic ¶
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() *gerr.GatewayDError
Run starts the server and blocks until the server is stopped. It calls the OnRun hooks.
type Stack ¶ added in v0.8.3
type Stack struct {
// contains filtered or unexported fields
}