server

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListenerConfig

type ListenerConfig struct {
	Address   string
	TLSConfig *tls.Config
}

ListenerConfig is the configuration for the listener. Address: the address to bind the listener to. It could be an address behind a reverse proxy. TLSConfig: the TLS configuration for the listener.

type Peer

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

Peer represents a peer connection

func NewPeer

func NewPeer(metrics *metrics.Metrics, id []byte, conn net.Conn, store *Store) *Peer

NewPeer creates a new Peer instance and prepare custom logging

func (*Peer) Close added in v0.29.3

func (p *Peer) Close()

func (*Peer) CloseGracefully

func (p *Peer) CloseGracefully(ctx context.Context)

CloseGracefully closes the connection with the peer gracefully. Send a close message to the client and close the connection.

func (*Peer) String

func (p *Peer) String() string

String returns the peer ID

func (*Peer) Work

func (p *Peer) Work()

Work reads data from the connection It manages the protocol (healthcheck, transport, close). Read the message and determine the message type and handle the message accordingly.

func (*Peer) Write

func (p *Peer) Write(b []byte) (int, error)

Write writes data to the connection

type Relay

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

Relay represents the relay server

func NewRelay

func NewRelay(meter metric.Meter, exposedAddress string, tlsSupport bool, validator auth.Validator) (*Relay, error)

NewRelay creates a new Relay instance

Parameters: meter: An instance of metric.Meter from the go.opentelemetry.io/otel/metric package. It is used to create and manage metrics for the relay server. exposedAddress: A string representing the address that the relay server is exposed on. The client will use this address as the relay server's instance URL. tlsSupport: A boolean indicating whether the relay server supports TLS (Transport Layer Security) or not. The instance URL depends on this value. validator: An instance of auth.Validator from the auth package. It is used to validate the authentication of the peers.

Returns: A pointer to a Relay instance and an error. If the Relay instance is successfully created, the error is nil. Otherwise, the error contains the details of what went wrong.

func (*Relay) Accept

func (r *Relay) Accept(conn net.Conn)

Accept start to handle a new peer connection

func (*Relay) InstanceURL

func (r *Relay) InstanceURL() string

InstanceURL returns the instance URL of the relay server

func (*Relay) Shutdown

func (r *Relay) Shutdown(ctx context.Context)

Shutdown closes the relay server It closes the connection with all peers in gracefully and stops accepting new connections.

type Server

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

Server is the main entry point for the relay server. It is the gate between the WebSocket listener and the Relay server logic. In a new HTTP connection, the server will accept the connection and pass it to the Relay server via the Accept method.

func NewServer

func NewServer(meter metric.Meter, exposedAddress string, tlsSupport bool, authValidator auth.Validator) (*Server, error)

NewServer creates a new relay server instance. meter: the OpenTelemetry meter exposedAddress: this address will be used as the instance URL. It should be a domain:port format. tlsSupport: if true, the server will support TLS authValidator: the auth validator to use for the server

func (*Server) InstanceURL

func (r *Server) InstanceURL() string

InstanceURL returns the instance URL of the relay server.

func (*Server) Listen

func (r *Server) Listen(cfg ListenerConfig) error

Listen starts the relay server.

func (*Server) Shutdown

func (r *Server) Shutdown(ctx context.Context) (err error)

Shutdown stops the relay server. If there are active connections, they will be closed gracefully. In case of a context, the connections will be forcefully closed.

type Store

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

Store is a thread-safe store of peers It is used to store the peers that are connected to the relay server

func NewStore

func NewStore() *Store

NewStore creates a new Store instance

func (*Store) AddPeer

func (s *Store) AddPeer(peer *Peer)

AddPeer adds a peer to the store

func (*Store) DeletePeer

func (s *Store) DeletePeer(peer *Peer)

DeletePeer deletes a peer from the store

func (*Store) Peer

func (s *Store) Peer(id string) (*Peer, bool)

Peer returns a peer by its ID

func (*Store) Peers

func (s *Store) Peers() []*Peer

Peers returns all the peers in the store

Directories

Path Synopsis
ws

Jump to

Keyboard shortcuts

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