Documentation
¶
Index ¶
- Constants
- type Config
- type Listener
- type ListenerConfig
- type Peer
- func (p *Peer) Authenticated() bool
- func (p *Peer) Close()
- func (p *Peer) CloseGracefully(ctx context.Context)
- func (p *Peer) ID() messages.PeerID
- func (p *Peer) String() string
- func (p *Peer) Version() messages.ProtocolVersion
- func (p *Peer) Work()
- func (p *Peer) Write(ctx context.Context, b []byte) (int, error)
- type PeerAuthConfig
- type Relay
- type Server
- type Validator
Constants ¶
const ( SchemeREL = "rel" SchemeRELS = "rels" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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) Authenticated ¶ added in v0.84.0
Authenticated reports whether the peer presented a valid token bound to its keys with a proof.
func (*Peer) CloseGracefully ¶
CloseGracefully closes the connection with the peer gracefully. Send a close message to the client and close the connection.
func (*Peer) Version ¶ added in v0.82.0
func (p *Peer) Version() messages.ProtocolVersion
Version returns the protocol version selected for this connection
type PeerAuthConfig ¶ added in v0.84.0
type PeerAuthConfig struct {
Keys peerauth.TokenKeys
// Hostnames, when set, are the only names accepted in proofs: the exposed address hostname
// and any global name the relays share behind a load balancer. Empty skips the name check.
Hostnames []string
// Required refuses peers presenting no bound token.
Required bool
// CheckTime bounds the proof timestamp to peerauth.DefaultSkew from this Relay's clock. Off, a
// proof is valid as long as its token, so peer clocks need not be in sync.
CheckTime bool
}
PeerAuthConfig configures the verification of the tokens bound to the peer keys. With no keys, a peer presenting such a token is refused.
type Relay ¶
type Relay struct {
// contains filtered or unexported fields
}
Relay represents the relay server
func NewRelay ¶
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 for legacy tokens. Required unless PeerAuth.Required is set.
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) InstanceURL ¶
InstanceURL returns the instance URL of the relay server
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 ¶
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 (*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 (*Server) RelayAccept ¶ added in v0.65.0
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.