network

package
v2.1.0-mercury-20230522 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WsServerHandshakeAuthHeaderName      string = "Authorization"
	WsServerHandshakeChallengeHeaderName string = "Challenge"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionAcceptor

type ConnectionAcceptor interface {
	StartHandshake(authHeader []byte) (attemptId string, challenge []byte, err error)
	FinalizeHandshake(attemptId string, response []byte, conn *websocket.Conn) error
	AbortHandshake(attemptId string)
}

type ConnectionInitiator

type ConnectionInitiator interface {
	NewAuthHeader(url *url.URL) []byte
	ChallengeResponse(challenge []byte) ([]byte, error)
}

The handshake works as follows:

  Client (Initiator)                  Server (Acceptor)

 NewAuthHeader()
             -------auth header-------->
                                       StartHandshake()
             <-------challenge----------
ChallengeResponse()
             ---------response--------->
                                     FinalizeHandshake()

type HTTPRequestHandler

type HTTPRequestHandler interface {
	ProcessRequest(ctx context.Context, rawRequest []byte) (rawResponse []byte, httpStatusCode int)
}

type HTTPServerConfig

type HTTPServerConfig struct {
	Host                 string
	Port                 uint16
	TLSEnabled           bool
	TLSCertPath          string
	TLSKeyPath           string
	Path                 string
	ContentTypeHeader    string
	ReadTimeoutMillis    uint32
	WriteTimeoutMillis   uint32
	RequestTimeoutMillis uint32
}

type HttpServer

type HttpServer interface {
	job.ServiceCtx

	// Not thread-safe. Should be done once before calling Start().
	SetHTTPRequestHandler(handler HTTPRequestHandler)
}

func NewHttpServer

func NewHttpServer(config *HTTPServerConfig, lggr logger.Logger) HttpServer

type WebSocketClient

type WebSocketClient interface {
	Connect(ctx context.Context, url *url.URL) (*websocket.Conn, error)
}

func NewWebSocketClient

func NewWebSocketClient(config WebSocketClientConfig, initiator ConnectionInitiator, lggr logger.Logger) WebSocketClient

type WebSocketClientConfig

type WebSocketClientConfig struct {
	HandshakeTimeoutMillis uint32
}

type WebSocketServer

type WebSocketServer interface {
	job.ServiceCtx
}

func NewWebSocketServer

func NewWebSocketServer(config *WebSocketServerConfig, acceptor ConnectionAcceptor, lggr logger.Logger) WebSocketServer

type WebSocketServerConfig

type WebSocketServerConfig struct {
	HTTPServerConfig
	HandshakeTimeoutMillis uint32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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