MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / New

Function New

internal/nodehub/hub.go:120–151  ·  view source on GitHub ↗

New 构造 Hub。

(opts Options)

Source from the content-addressed store, hash-verified

118
119// New 构造 Hub。
120func New(opts Options) *Hub {
121 logger := opts.Logger
122 if logger == nil {
123 logger = slog.Default()
124 }
125 ph := opts.PushHandler
126 if ph == nil {
127 ph = NoopPushHandler{}
128 }
129 pe := opts.PeerExtractor
130 if pe == nil {
131 pe = mtlsPeerExtractor
132 }
133 dct := opts.DeadConnectionTimeout
134 if dct <= 0 {
135 dct = 60 * time.Second
136 }
137 ri := opts.ReaperInterval
138 if ri <= 0 {
139 ri = 10 * time.Second
140 }
141 return &Hub{
142 logger: logger,
143 pushHandler: ph,
144 peerExtractor: pe,
145 onNodeConnected: opts.OnNodeConnected,
146 deadConnTimeout: dct,
147 reaperInterval: ri,
148 conns: make(map[string]*conn),
149 metrics: newMetrics(),
150 }
151}
152
153// RunReaper 阻塞运行死连接清理:每 ReaperInterval 扫描一次注册表,
154// 关闭超过 DeadConnectionTimeout 没收到任何帧的连接。ctx 取消时返回。

Callers 15

startBufHubFunction · 0.92
startTCPHubFunction · 0.92
startMTLSHubFunction · 0.92
startHubFunction · 0.92
TestLoad_ConcurrentNodesFunction · 0.92
startNodeHubFunction · 0.92
TestSnapshot_BasicCountsFunction · 0.70

Calls 1

newMetricsFunction · 0.85

Tested by 15

startBufHubFunction · 0.74
startTCPHubFunction · 0.74
startMTLSHubFunction · 0.74
startHubFunction · 0.74
TestLoad_ConcurrentNodesFunction · 0.74
TestSnapshot_BasicCountsFunction · 0.56