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

Function DefaultHelloProvider

internal/nodeagent/agent.go:96–112  ·  view source on GitHub ↗

DefaultHelloProvider 构造一个常见的 hello 帧 provider: 返回 JSON {"node_id":..., "config_hash":..., "version":...}。 configHasher 由调用方注入,常见做法是返回 xray 配置 hash。

(nodeID string, configHasher func() string)

Source from the content-addressed store, hash-verified

94// 返回 JSON {"node_id":..., "config_hash":..., "version":...}。
95// configHasher 由调用方注入,常见做法是返回 xray 配置 hash。
96func DefaultHelloProvider(nodeID string, configHasher func() string) func() (json.RawMessage, error) {
97 if configHasher == nil {
98 configHasher = func() string { return "" }
99 }
100 return func() (json.RawMessage, error) {
101 payload := struct {
102 NodeID string `json:"node_id"`
103 ConfigHash string `json:"config_hash"`
104 Version string `json:"version"`
105 }{
106 NodeID: nodeID,
107 ConfigHash: configHasher(),
108 Version: buildinfo.Version,
109 }
110 return json.Marshal(payload)
111 }
112}
113
114// Run 阻塞运行 agent,直到 ctx 取消。期间任何错误(连接失败、stream 出错、
115// Recv EOF 等)都会触发指数退避重连。

Callers 12

TestE2E_EnrollAndConnectFunction · 0.92
TestE2E_DispatchRPCFunction · 0.92
TestE2E_StreamLogsCancelFunction · 0.92
TestE2E_UsagePushAckFunction · 0.92
TestE2E_ReconnectBackoffFunction · 0.92
TestE2E_MultiNodeFunction · 0.92
TestLoad_ConcurrentNodesFunction · 0.92
RunFunction · 0.92
TestDefaultHelloProviderFunction · 0.85

Calls

no outgoing calls

Tested by 11

TestE2E_EnrollAndConnectFunction · 0.74
TestE2E_DispatchRPCFunction · 0.74
TestE2E_StreamLogsCancelFunction · 0.74
TestE2E_UsagePushAckFunction · 0.74
TestE2E_ReconnectBackoffFunction · 0.74
TestE2E_MultiNodeFunction · 0.74
TestLoad_ConcurrentNodesFunction · 0.74
TestDefaultHelloProviderFunction · 0.68