network

package
v0.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

	DefaultTickInterval = 5
	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 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 Pool

type Pool interface {
	ForEach(callback func(client *Client) error)
	Pool() *sync.Map
	ClientIDs() []string
	Put(client *Client) error
	Pop(ID string) *Client
	Size() int
	Close() error
	Shutdown()
}

type PoolImpl

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

func NewPool

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

func (*PoolImpl) ClientIDs

func (p *PoolImpl) ClientIDs() []string

func (*PoolImpl) Close

func (p *PoolImpl) Close() error

func (*PoolImpl) ForEach

func (p *PoolImpl) ForEach(callback func(client *Client) error)

func (*PoolImpl) Pool

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

func (*PoolImpl) Pop

func (p *PoolImpl) Pop(id string) *Client

func (*PoolImpl) Put

func (p *PoolImpl) Put(client *Client) error

func (*PoolImpl) Shutdown

func (p *PoolImpl) Shutdown()

func (*PoolImpl) Size

func (p *PoolImpl) Size() int

type Proxy

type Proxy interface {
	Connect(gconn gnet.Conn) error
	Disconnect(gconn gnet.Conn) error
	PassThrough(gconn gnet.Conn, onIncomingTraffic, onOutgoingTraffic Traffic) error
	Reconnect(cl *Client) *Client
	Shutdown()
	Size() int
}

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, 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, onIncomingTraffic, onOutgoingTraffic Traffic) error

func (*ProxyImpl) Reconnect

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

func (*ProxyImpl) Shutdown

func (pr *ProxyImpl) Shutdown()

func (*ProxyImpl) Size

func (pr *ProxyImpl) Size() int

type Server

type Server struct {
	gnet.BuiltinEventEngine

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

func NewServer added in v0.0.2

func NewServer(
	network, address string,
	softLimit, hardLimit uint64,
	tickInterval int,
	options []gnet.Option,
	onIncomingTraffic, onOutgoingTraffic Traffic,
	proxy Proxy,
	logger zerolog.Logger,
) *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 Status added in v0.0.2

type Status string

type Traffic added in v0.0.2

type Traffic func(gconn gnet.Conn, cl *Client, buf []byte, err error) error

Jump to

Keyboard shortcuts

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