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

Method Call

internal/nodehub/call.go:24–36  ·  view source on GitHub ↗

Call 向指定 node 发起一次请求-响应调用。 reqBody 会用 encoding/json 编码(nil 表示空 body)。 返回值是 node 的 NodeMessage.Body(json 原文)。 当 ctx 取消时,hub 会 best-effort 向 node 发送 cancel_id 帧, 然后返回 ctx.Err()。

(ctx context.Context, nodeID, method string, reqBody any)

Source from the content-addressed store, hash-verified

22// 当 ctx 取消时,hub 会 best-effort 向 node 发送 cancel_id 帧,
23// 然后返回 ctx.Err()。
24func (h *Hub) Call(ctx context.Context, nodeID, method string, reqBody any) (json.RawMessage, error) {
25 h.metrics.callsTotal.Add(1)
26 start := time.Now()
27 raw, err := h.doCall(ctx, nodeID, method, reqBody)
28 h.metrics.recordCallLatency(time.Since(start))
29 if err != nil {
30 h.metrics.callsErrTotal.Add(1)
31 if errors.Is(err, ErrNodeOffline) {
32 h.metrics.callsOfflineTotal.Add(1)
33 }
34 }
35 return raw, err
36}
37
38func (h *Hub) doCall(ctx context.Context, nodeID, method string, reqBody any) (json.RawMessage, error) {
39 h.mu.RLock()

Callers

nothing calls this directly

Calls 3

doCallMethod · 0.95
AddMethod · 0.80
recordCallLatencyMethod · 0.80

Tested by

no test coverage detected