network

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Running Status = "running"
	Stopped Status = "stopped"

	DefaultTickInterval = 5 * time.Second
	DefaultPoolSize     = 10
	DefaultBufferSize   = 4096
)
View Source
const (
	DefaultSeed = 1000
)

Variables

View Source
var (
	ErrClientNotFound      = errors.New("client not found")
	ErrNetworkNotSupported = errors.New("network is not supported")
	ErrClientNotConnected  = errors.New("client is not connected")
	ErrPoolExhausted       = errors.New("pool is exhausted")
)

Functions

func GetID

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

func GetRLimit

func GetRLimit(logger zerolog.Logger) syscall.Rlimit

func Resolve added in v0.0.2

func Resolve(network, address string, logger zerolog.Logger) (string, error)

Types

type Callback added in v0.0.6

type Callback func(key, value interface{}) bool

type Client

type Client struct {
	net.Conn

	ID                string
	ReceiveBufferSize int
	Network           string // tcp/udp/unix
	Address           string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(network, address string, receiveBufferSize int, logger zerolog.Logger) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Receive

func (c *Client) Receive() (int, []byte, error)

func (*Client) Send

func (c *Client) Send(data []byte) error

type HookConfig added in v0.0.6

type HookConfig struct {
	Logger       zerolog.Logger
	Verification Policy
	// contains filtered or unexported fields
}

func NewHookConfig added in v0.0.6

func NewHookConfig() *HookConfig

func (*HookConfig) Add added in v0.0.7

func (h *HookConfig) Add(hookType HookType, prio Prio, hook HookDef)

func (*HookConfig) Get added in v0.0.7

func (h *HookConfig) Get(hookType HookType) map[Prio]HookDef

func (*HookConfig) Run added in v0.0.7

func (h *HookConfig) Run(
	hookType HookType, args Signature, verification Policy,
) Signature

type HookDef added in v0.0.6

type HookDef func(Signature) Signature

type HookType added in v0.0.6

type HookType string
const (
	// Run command hooks (cmd/run.go).
	OnConfigLoaded HookType = "onConfigLoaded"
	OnNewLogger    HookType = "onNewLogger"
	OnNewPool      HookType = "onNewPool"
	OnNewProxy     HookType = "onNewProxy"
	OnNewServer    HookType = "onNewServer"
	OnSignal       HookType = "onSignal"
	// Server hooks (network/server.go).
	OnRun            HookType = "onRun"
	OnBooting        HookType = "onBooting"
	OnBooted         HookType = "onBooted"
	OnOpening        HookType = "onOpening"
	OnOpened         HookType = "onOpened"
	OnClosing        HookType = "onClosing"
	OnClosed         HookType = "onClosed"
	OnTraffic        HookType = "onTraffic"
	OnIngressTraffic HookType = "onIngressTraffic"
	OnEgressTraffic  HookType = "onEgressTraffic"
	OnShutdown       HookType = "onShutdown"
	OnTick           HookType = "onTick"
	// Pool hooks (network/pool.go).
	OnNewClient HookType = "onNewClient"
)

type Policy added in v0.0.7

type Policy int
const (
	// Non-strict (permissive) mode.
	PassDown Policy = iota // Pass down the extra keys/values in result to the next plugins
	// Strict mode.
	Ignore // Ignore errors and continue
	Abort  // Abort on first error and return results
	Remove // Remove the hook from the list on error and continue
)

type Pool

type Pool interface {
	ForEach(Callback)
	Pool() *sync.Map
	Put(key, value interface{})
	Get(key interface{}) interface{}
	Pop(key interface{}) interface{}
	Size() int
	Clear()
}

func NewEmptyPool added in v0.0.6

func NewEmptyPool(logger zerolog.Logger) Pool

type PoolImpl

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

func NewPool

func NewPool(
	logger zerolog.Logger,
	poolSize int,
	clientConfig *Client,
	hookConfig *HookConfig,
) *PoolImpl

func (*PoolImpl) Clear added in v0.0.6

func (p *PoolImpl) Clear()

func (*PoolImpl) ForEach

func (p *PoolImpl) ForEach(cb Callback)

func (*PoolImpl) Get added in v0.0.7

func (p *PoolImpl) Get(key interface{}) interface{}

func (*PoolImpl) Pool

func (p *PoolImpl) Pool() *sync.Map

func (*PoolImpl) Pop

func (p *PoolImpl) Pop(key interface{}) interface{}

func (*PoolImpl) Put

func (p *PoolImpl) Put(key, value interface{})

func (*PoolImpl) Size

func (p *PoolImpl) Size() int

type Prio added in v0.0.6

type Prio uint

Prio is the priority of a hook. Smaller values are executed first (higher priority).

type Proxy

type Proxy interface {
	Connect(gconn gnet.Conn) error
	Disconnect(gconn gnet.Conn) error
	PassThrough(gconn gnet.Conn) error
	Reconnect(cl *Client) *Client
	Shutdown()
}

type ProxyImpl

type ProxyImpl struct {
	Elastic             bool
	ReuseElasticClients bool

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

func NewProxy

func NewProxy(
	pool Pool, hookConfig *HookConfig, elastic, reuseElasticClients bool, clientConfig *Client, logger zerolog.Logger,
) *ProxyImpl

func (*ProxyImpl) Connect

func (pr *ProxyImpl) Connect(gconn gnet.Conn) error

func (*ProxyImpl) Disconnect

func (pr *ProxyImpl) Disconnect(gconn gnet.Conn) error

func (*ProxyImpl) PassThrough

func (pr *ProxyImpl) PassThrough(gconn gnet.Conn) error

func (*ProxyImpl) Reconnect

func (pr *ProxyImpl) Reconnect(cl *Client) *Client

func (*ProxyImpl) Shutdown

func (pr *ProxyImpl) Shutdown()

type Server

type Server struct {
	gnet.BuiltinEventEngine

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

func NewServer added in v0.0.2

func NewServer(
	network, address string,
	softLimit, hardLimit uint64,
	tickInterval time.Duration,
	options []gnet.Option,
	proxy Proxy,
	logger zerolog.Logger,
	hooksConfig *HookConfig,
) *Server

func (*Server) IsRunning added in v0.0.2

func (s *Server) IsRunning() bool

func (*Server) OnBoot

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

func (*Server) OnClose

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

func (*Server) OnOpen

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

func (*Server) OnShutdown

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

func (*Server) OnTick

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

func (*Server) OnTraffic

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

func (*Server) Run

func (s *Server) Run() error

func (*Server) Shutdown

func (s *Server) Shutdown()

type Signature added in v0.0.7

type Signature map[string]interface{}

type Status added in v0.0.2

type Status string

Jump to

Keyboard shortcuts

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