-
Notifications
You must be signed in to change notification settings - Fork 14
/
rpc.go
32 lines (27 loc) · 858 Bytes
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package gorums
import (
"context"
"github.com/relab/gorums/ordering"
"google.golang.org/protobuf/reflect/protoreflect"
)
// CallData contains data needed to make a remote procedure call.
//
// This struct should be used by generated code only.
type CallData struct {
Message protoreflect.ProtoMessage
Method string
}
// RPCCall executes a remote procedure call on the node.
//
// This method should be used by generated code only.
func (n *RawNode) RPCCall(ctx context.Context, d CallData) (protoreflect.ProtoMessage, error) {
md := &ordering.Metadata{MessageID: n.mgr.getMsgID(), Method: d.Method}
replyChan := make(chan response, 1)
n.channel.enqueue(request{ctx: ctx, msg: &Message{Metadata: md, Message: d.Message}}, replyChan, false)
select {
case r := <-replyChan:
return r.msg, r.err
case <-ctx.Done():
return nil, ctx.Err()
}
}