server

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SchemeREL  = "rel"
	SchemeRELS = "rels"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.51.0

type Config struct {
	Meter          metric.Meter
	ExposedAddress string
	TLSSupport     bool
	AuthValidator  Validator
	// contains filtered or unexported fields
}

type Listener added in v0.68.0

type Listener interface {
	Bind() error
	Serve(func(conn listener.Conn)) error
	Shutdown(ctx context.Context) error
	Protocol() protocol.Protocol
}

type ListenerConfig

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

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. TrustedProxies: upstream proxy prefixes whose forwarding headers (X-Real-Ip/X-Real-Port) are trusted.

type Peer

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

Peer represents a peer connection

func NewPeer

func NewPeer(metrics *metrics.Metrics, id messages.PeerID, version messages.ProtocolVersion, conn listener.Conn, store *store.Store, notifier *store.PeerNotifier) *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) ID added in v0.51.0

func (p *Peer) ID() messages.PeerID

func (*Peer) String

func (p *Peer) String() string

String returns the peer ID

func (*Peer) Version added in v0.82.0

func (p *Peer) Version() messages.ProtocolVersion

Version returns the protocol version selected for this connection

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(ctx context.Context, 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(config Config) (*Relay, error)

NewRelay creates and returns a new Relay instance.

Parameters:

config: A Config struct that holds the configuration needed to initialize the relay server.
  - Meter: A metric.Meter used for emitting metrics. If not set, a default no-op meter will be used.
  - ExposedAddress: The external address clients use to reach this relay. Required.
  - TLSSupport: A boolean indicating if the relay uses TLS. Affects the generated instance URL.
  - AuthValidator: A Validator implementation used to authenticate peers. Required.

Returns:

A pointer to a Relay instance and an error. If initialization is successful, the error will be nil;
otherwise, it will contain the reason the relay could not be created (e.g., invalid configuration).

func (*Relay) Accept

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

Accept start to handle a new peer connection

func (*Relay) InstanceURL

func (r *Relay) InstanceURL() url.URL

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(config Config) (*Server, error)

NewServer creates and returns a new relay server instance.

Parameters:

config: A Config struct containing the necessary configuration:
  - Meter: An OpenTelemetry metric.Meter used for recording metrics. If nil, a default no-op meter is used.
  - InstanceURL: The public address (in domain:port format) used as the server's instance URL. Required.
  - TLSSupport: A boolean indicating whether TLS is enabled for the server.
  - AuthValidator: A Validator used to authenticate peers. Required.

Returns:

A pointer to a Server instance and an error. If the configuration is valid and initialization succeeds,
the returned error will be nil. Otherwise, the error will describe the problem.

func (*Server) InstanceURL

func (r *Server) InstanceURL() url.URL

func (*Server) Listen

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

Listen binds the relay listeners and serves them until Shutdown is called.

func (*Server) ListenerProtocols added in v0.54.2

func (r *Server) ListenerProtocols() []protocol.Protocol

func (*Server) RelayAccept added in v0.65.0

func (r *Server) RelayAccept() func(conn listener.Conn)

RelayAccept returns the relay's Accept function for handling incoming connections. This allows external HTTP handlers to route connections to the relay without starting the relay's own listeners.

func (*Server) Shutdown

func (r *Server) Shutdown(ctx context.Context) 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 Validator added in v0.51.0

type Validator interface {
	Validate(any) error
}

Directories

Path Synopsis
ws

Jump to

Keyboard shortcuts

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