relayserver

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 17 Imported by: 0 modules, 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

Overview

Package relayserver 是 relay 的 Go 自建版(路线图 M16):只做转发,看不到明文。协议见 docs/design/remote-access.md 的「relay」。

主机连 /v1/host/<hostId>:质询、签名(签进本 relay 的 origin)、READY,之后按流转发外层帧; 客户端连 /v1/client/<hostId>:每条二进制消息是一条 Noise 消息,装进 DATA 转给主机。 限额:每主机并发流、每主机每天转发量、每 IP 每分钟新建连接;超额以 4429 关闭,暂停服务时一律 4503。 运维:GET /ready(排空、满了、暂停服务时 503)、GET /metrics(Prometheus 文本)、同时连接数上限(满了升级前回 503); Drain 以后不接新连接,Close 时主机与客户端都以 1012 关(参考 getpaseo/paseo-relay 的做法)。

Index

Constants

View Source
const (
	DefaultMaxStreamsPerHost  = 16
	DefaultMaxConnPerIPPerMin = 30
	DefaultMaxConnections     = 10000
)

默认限额(与托管版一致,每天转发量自建版默认不限)。

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PublicURL 是 relay 对外的地址(例如 wss://relay.example.com):主机按它签名,这里按它的 origin 校验
	PublicURL string
	// MaxStreamsPerHost 是每台主机同时打开的客户端流上限;0 时用默认值 16
	MaxStreamsPerHost int
	// DailyBytesPerHost 是每台主机每天(00:00 UTC 重置)转发的字节上限,两个方向合计;0 = 不限
	DailyBytesPerHost int64
	// MaxConnPerIPPerMin 是每个 IP 每分钟新建连接的上限(主机与客户端合计);0 时用默认值 30,负数 = 不限
	MaxConnPerIPPerMin int
	// Disabled 为真时所有连接以 4503 关闭
	Disabled bool
	// MaxConnections 是同时连着的 WebSocket 上限(主机,含还在认证的,加客户端);0 时用默认值 10000,负数 = 不限。
	// 满了的时候新连接在升级前回 HTTP 503,已有的连接不受影响
	MaxConnections int
	// NoMetrics 为真时不提供 /metrics
	NoMetrics bool
	// ClientIPHeader 不为空时从这个请求头取客户端 IP(放在反向代理之后时,例如 X-Real-IP 或 CF-Connecting-IP);
	// 头里有多个地址(X-Forwarded-For)时取最后一个,即代理追加的那个。只有确定请求都经过代理时才设,否则这个头可以随意伪造
	ClientIPHeader string
	Version        string
	Logger         *zap.SugaredLogger
	Now            func() time.Time
}

Config 是 relay 的设置。

type Server

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

Server 是 relay。

func New

func New(cfg Config) (*Server, error)

New 校验设置并建 relay。

func (*Server) Close

func (s *Server) Close()

Close 不再接新连接,主机(包括还在认证的)与客户端都以 1012(relay 重启)关掉,等关闭握手(最多 closeWait), 最后取消所有读写。顺序不能反:coder/websocket 的读在 ctx 取消时直接断开连接,关闭帧就发不出去了。

func (*Server) Drain

func (s *Server) Drain()

Drain 让 relay 不再接新连接(/ready 回 503,新连接在升级前回 503),已有的连接不动。用于先从负载均衡上摘下来再停。

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler 是 relay 的路由:/v1/host/{id}、/v1/client/{id}、/healthz、/ready、/metrics。

Jump to

Keyboard shortcuts

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