-
Notifications
You must be signed in to change notification settings - Fork 5
/
check_pier.go
83 lines (72 loc) · 1.92 KB
/
check_pier.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package rpcx
import (
"context"
"fmt"
"github.com/meshplus/bitxhub-model/pb"
)
func (cli *ChainClient) CheckMasterPier(address string) (*pb.Response, error) {
ctx, cancel := context.WithTimeout(context.Background(), CheckPierTimeout)
defer cancel()
ctx, err := cli.SetCtxMetadata(ctx)
if err != nil {
return nil, fmt.Errorf("set ctx metadata err: %v", err)
}
grpcClient, err := cli.pool.getClient()
if err != nil {
return nil, err
}
defer func() {
if err := grpcClient.conn.Close(); err != nil {
cli.logger.Errorf("close conn err: %s", err)
}
}()
request := &pb.Address{
Address: address,
}
return grpcClient.broker.CheckMasterPier(ctx, request)
}
func (cli *ChainClient) SetMasterPier(address string, index string, timeout int64) (*pb.Response, error) {
ctx, cancel := context.WithTimeout(context.Background(), CheckPierTimeout)
defer cancel()
ctx, err := cli.SetCtxMetadata(ctx)
if err != nil {
return nil, fmt.Errorf("set ctx metadata err: %v", err)
}
grpcClient, err := cli.pool.getClient()
if err != nil {
return nil, err
}
defer func() {
if err := grpcClient.conn.Close(); err != nil {
cli.logger.Errorf("close conn err: %s", err)
}
}()
request := &pb.PierInfo{
Address: address,
Index: index,
Timeout: timeout,
}
return grpcClient.broker.SetMasterPier(ctx, request)
}
func (cli *ChainClient) HeartBeat(address string, index string) (*pb.Response, error) {
ctx, cancel := context.WithTimeout(context.Background(), CheckPierTimeout)
defer cancel()
ctx, err := cli.SetCtxMetadata(ctx)
if err != nil {
return nil, fmt.Errorf("set ctx metadata err: %v", err)
}
grpcClient, err := cli.pool.getClient()
if err != nil {
return nil, err
}
defer func() {
if err := grpcClient.conn.Close(); err != nil {
cli.logger.Errorf("close conn err: %s", err)
}
}()
request := &pb.PierInfo{
Address: address,
Index: index,
}
return grpcClient.broker.HeartBeat(ctx, request)
}