MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / CallNodeWithContext

Method CallNodeWithContext

rpc/caller.go:84–116  ·  view source on GitHub ↗

CallNodeWithContext calls node method with context.

(
	ctx context.Context, node proto.NodeID, method string, args, reply interface{})

Source from the content-addressed store, hash-verified

82
83// CallNodeWithContext calls node method with context.
84func (c *Caller) CallNodeWithContext(
85 ctx context.Context, node proto.NodeID, method string, args, reply interface{}) (err error,
86) {
87 startTime := time.Now()
88 defer func() {
89 recordRPCCost(startTime, method, err)
90 }()
91
92 client, err := DialToNodeWithPool(c.pool, node, method == route.DHTPing.String())
93 if err != nil {
94 err = errors.Wrapf(err, "dial to node %s failed", node)
95 return
96 }
97 defer func() { _ = client.Close() }()
98
99 // TODO(xq262144): golang net/rpc does not support cancel in progress calls
100 ch := client.Go(method, args, reply, make(chan *rpc.Call, 1))
101
102 select {
103 case <-ctx.Done():
104 err = ctx.Err()
105 case call := <-ch.Done:
106 err = call.Error
107 // Set error state so that the associated will not reuse this client
108 if err != nil { // TODO(leventeliu): check recoverable errors
109 if setter, ok := client.(LastErrSetter); ok {
110 setter.SetLastErr(err)
111 }
112 }
113 }
114
115 return
116}
117
118// CallNode calls node method.
119func (c *Caller) CallNode(node proto.NodeID, method string, args, reply interface{}) (err error) {

Callers 8

CallNodeMethod · 0.95
TestCaller_CallNodeFunction · 0.95
blockingFetchBlockMethod · 0.80
produceBlockMethod · 0.80
syncHeadMethod · 0.80
nonBlockingSyncMethod · 0.80

Implementers 6

fakeTrackerCallerkayak/tracker_test.go
fakeCallerkayak/runtime_test.go
pooledClientrpc/pool.go
PersistentCallerrpc/pcaller.go
RawCallerrpc/mux/rawcaller.go
fakeServicerpc/mux/wrapper_test.go

Calls 6

recordRPCCostFunction · 0.85
DialToNodeWithPoolFunction · 0.85
GoMethod · 0.80
CloseMethod · 0.65
SetLastErrMethod · 0.65
StringMethod · 0.45

Tested by 1

TestCaller_CallNodeFunction · 0.76