server

package
v0.0.0-...-5cda5f8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnConnect

func OnConnect(wm *WebsocketManager) func(wsc *wsConnection)

func OnDisconnect

func OnDisconnect(onDisconnect func(remoteAddr, pubKey string)) func(*wsConnection)

OnDisconnect sets a callback which is used upon disconnect - not Goroutine-safe. Nop by default.

func PingPeriod

func PingPeriod(pingPeriod time.Duration) func(*wsConnection)

PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.

func ReadLimit

func ReadLimit(readLimit int64) func(*wsConnection)

ReadLimit sets the maximum size for reading message. It should only be used in the constructor - not Goroutine-safe.

func ReadWait

func ReadWait(readWait time.Duration) func(*wsConnection)

ReadWait sets the amount of time to wait before a websocket read times out. It should only be used in the constructor - not Goroutine-safe.

func WriteChanCapacity

func WriteChanCapacity(cap int) func(*wsConnection)

WriteChanCapacity sets the capacity of the websocket write channel. It should only be used in the constructor - not Goroutine-safe.

func WriteWait

func WriteWait(writeWait time.Duration) func(*wsConnection)

WriteWait sets the amount of time to wait before a websocket write times out. It should only be used in the constructor - not Goroutine-safe.

Types

type IWebsocketManager

type IWebsocketManager interface {
	AliveNodes() []string
	RegisterResChannel(id string, responseMsg chan ResponseMsg, stopChan chan struct{}) error
	SendMsg(request RequestMsg) error
}

type RequestMsg

type RequestMsg struct {
	RpcRequest tmtypes.RPCRequest
	TargetNode string
}

type ResponseMsg

type ResponseMsg struct {
	RpcResponse tmtypes.RPCResponse
	SourceNode  string
}

type WSServer

type WSServer struct {
	service.BaseService

	Config *rpcserver.Config
	Logger log.Logger

	Listener net.Listener
	Handler  http.Handler
	WM       *WebsocketManager
}

type WebsocketManager

type WebsocketManager struct {
	websocket.Upgrader
	// contains filtered or unexported fields
}

WebsocketManager provides a WS handler for incoming connections and passes a map of functions along with any additional params to new connections. NOTE: The websocket path is defined externally, e.g. in node/node.go

func NewWSServer

func NewWSServer(localAddr string, queryService types.TssQueryService) (*WebsocketManager, error)

func NewWebsocketManager

func NewWebsocketManager(l1chainQueryService itypes.TssQueryService,
	wsConnOptions ...func(*wsConnection),
) *WebsocketManager

NewWebsocketManager returns a new WebsocketManager that passes a map of functions, connection options and logger to new WS connections.

func (*WebsocketManager) AliveNodes

func (wm *WebsocketManager) AliveNodes() []string

func (*WebsocketManager) JudgeWssConnectPermission

func (wm *WebsocketManager) JudgeWssConnectPermission(activeTssMembers, inActiveTssMembers []string, nodePublicKey string) bool

func (*WebsocketManager) RegisterResChannel

func (wm *WebsocketManager) RegisterResChannel(requestId string, recvChan chan ResponseMsg, stopChan chan struct{}) error

func (*WebsocketManager) SendMsg

func (wm *WebsocketManager) SendMsg(msg RequestMsg) error

func (*WebsocketManager) SetLogger

func (wm *WebsocketManager) SetLogger(l log.Logger)

SetLogger sets the logger.

func (*WebsocketManager) SetWsConnOptions

func (wm *WebsocketManager) SetWsConnOptions(wsConnOptions ...func(*wsConnection))

func (*WebsocketManager) WebsocketHandler

func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Request)

WebsocketHandler upgrades the request/response (via http.Hijack) and starts the wsConnection.

Jump to

Keyboard shortcuts

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