acceptor

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ConnStatusStart int32
	ConnStatusClosed
)
View Source
const (
	StatusWorking int32
	StatusClosed
)

Variables

View Source
var (
	ACCEPTOR_TYPE_WS     = "websockets"
	ACCEPTOR_TYPE_WEBRTC = "webrtc"

	ErrMessageRateLimit = errors.New("message rate limit")
)

Functions

func ReadUserIP

func ReadUserIP(r *http.Request) *net.TCPAddr

Types

type Acceptor

type Acceptor interface {
	GetConfig() *AcceptorConfig     // get the config
	ListenAndServe()                // listen and serve
	Stop()                          // stop the acceptor
	GetConnChan() chan AcceptorConn // get the conn channel
	GetAddr() string                // get the addr
	GetName() string                // get the name
	GetType() string                // get the type
}

Acceptor type interface

type AcceptorConfig added in v0.2.1

type AcceptorConfig struct {
	Name     string                 // the name of the acceptor
	Groups   []*AcceptorGroupConfig // the groups of the acceptor
	Type     string                 // the type of the acceptor
	HttpPort int
	UdpPort  int
}

type AcceptorConn

type AcceptorConn interface {
	GetNextMessage() (b []byte, err error) // get the next message
	GetInfo() *ConnInfo                    // get the conn info
	SetCloseHandler(func())                // set the close callback
	IsClosed() bool                        // is conn closed
	net.Conn                               // Conn
}

AcceptorConn interface

type AcceptorGroupConfig

type AcceptorGroupConfig struct {
	GroupName          string        // the name of the group
	BucketFillInterval time.Duration // the interval of the bucket fill
	BucketCapacity     int64         // the capacity of the bucket
	Ordered            bool          // whether the message is ordered, only for webrtc
	MiddlewareFunc     []MiddlewareFunc
}

type ConnInfo

type ConnInfo struct {
	AcceptorType       string        // the type of the acceptor
	AcceptorName       string        // the name of the acceptor
	AcceptorGroup      string        // the group of the acceptor
	Ordered            bool          // whether the message is ordered, only for webrtc
	BucketFillInterval time.Duration // the interval of the bucket fill
	BucketCapacity     int64         // the capacity of the bucket
}

type MiddlewareFunc added in v0.2.5

type MiddlewareFunc func(http.Handler) http.Handler

type WSAcceptor

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

func NewWSAcceptor added in v0.2.1

func NewWSAcceptor(config *AcceptorConfig) *WSAcceptor

func (*WSAcceptor) GetAddr

func (w *WSAcceptor) GetAddr() string

func (*WSAcceptor) GetConfig added in v0.1.2

func (w *WSAcceptor) GetConfig() *AcceptorConfig

func (*WSAcceptor) GetConnChan

func (w *WSAcceptor) GetConnChan() chan AcceptorConn

func (*WSAcceptor) GetName

func (w *WSAcceptor) GetName() string

func (*WSAcceptor) GetType

func (w *WSAcceptor) GetType() string

func (*WSAcceptor) ListenAndServe

func (w *WSAcceptor) ListenAndServe()

func (*WSAcceptor) Stop

func (w *WSAcceptor) Stop()

type WSConn

type WSConn struct {
	MaxMessagesInSecond uint
	// contains filtered or unexported fields
}

func NewWSConn

func NewWSConn(conn *websocket.Conn, info *ConnInfo) *WSConn

func (*WSConn) Close

func (c *WSConn) Close() error

func (*WSConn) GetInfo

func (c *WSConn) GetInfo() *ConnInfo

func (*WSConn) GetNextMessage

func (c *WSConn) GetNextMessage() (b []byte, err error)

GetNextMessage reads the next message available in the stream

func (*WSConn) IsClosed

func (c *WSConn) IsClosed() bool

func (*WSConn) LocalAddr

func (c *WSConn) LocalAddr() net.Addr

func (*WSConn) Read

func (c *WSConn) Read(b []byte) (int, error)

func (*WSConn) RemoteAddr

func (c *WSConn) RemoteAddr() net.Addr

func (*WSConn) SetCloseHandler

func (c *WSConn) SetCloseHandler(f func())

func (*WSConn) SetDeadline

func (c *WSConn) SetDeadline(t time.Time) error

func (*WSConn) SetReadDeadline

func (c *WSConn) SetReadDeadline(t time.Time) error

func (*WSConn) SetWriteDeadline

func (c *WSConn) SetWriteDeadline(t time.Time) error

func (*WSConn) Write

func (c *WSConn) Write(b []byte) (int, error)

type WebRTCAcceptor

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

WebRTCAcceptor accept the webrtc data channel connection

func NewWebRTCAcceptor

func NewWebRTCAcceptor(config *AcceptorConfig) *WebRTCAcceptor

func (*WebRTCAcceptor) GetAddr

func (w *WebRTCAcceptor) GetAddr() string

func (*WebRTCAcceptor) GetConfig added in v0.1.2

func (w *WebRTCAcceptor) GetConfig() *AcceptorConfig

func (*WebRTCAcceptor) GetConnChan

func (w *WebRTCAcceptor) GetConnChan() chan AcceptorConn

func (*WebRTCAcceptor) GetName

func (w *WebRTCAcceptor) GetName() string

func (*WebRTCAcceptor) GetType

func (w *WebRTCAcceptor) GetType() string

func (*WebRTCAcceptor) ListenAndServe

func (w *WebRTCAcceptor) ListenAndServe()

func (*WebRTCAcceptor) Stop

func (w *WebRTCAcceptor) Stop()

type WebRTCConn

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

func NewWebRTCConn

func NewWebRTCConn(conn *webrtc.PeerConnection,
	dataChannel *webrtc.DataChannel,
	rw datachannel.ReadWriteCloser,
	info *ConnInfo) *WebRTCConn

func (*WebRTCConn) Close

func (c *WebRTCConn) Close() error

func (*WebRTCConn) GetInfo

func (c *WebRTCConn) GetInfo() *ConnInfo

func (*WebRTCConn) GetNextMessage

func (c *WebRTCConn) GetNextMessage() (b []byte, err error)

func (*WebRTCConn) IsClosed

func (c *WebRTCConn) IsClosed() bool

func (*WebRTCConn) LocalAddr

func (c *WebRTCConn) LocalAddr() net.Addr

func (*WebRTCConn) Read

func (c *WebRTCConn) Read(b []byte) (int, error)

func (*WebRTCConn) RemoteAddr

func (c *WebRTCConn) RemoteAddr() net.Addr

func (*WebRTCConn) SetCloseHandler

func (c *WebRTCConn) SetCloseHandler(f func())

func (*WebRTCConn) SetDeadline

func (c *WebRTCConn) SetDeadline(t time.Time) error

func (*WebRTCConn) SetReadDeadline

func (c *WebRTCConn) SetReadDeadline(t time.Time) error

func (*WebRTCConn) SetWriteDeadline

func (c *WebRTCConn) SetWriteDeadline(t time.Time) error

func (*WebRTCConn) Write

func (c *WebRTCConn) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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