|
|
@ -4,12 +4,11 @@ import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"encoding/binary" |
|
|
|
"encoding/binary" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
|
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"google.golang.org/grpc" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pb "github.com/harmony-one/harmony/api/services/syncing/downloader/proto" |
|
|
|
pb "github.com/harmony-one/harmony/api/services/syncing/downloader/proto" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
|
|
|
|
"google.golang.org/grpc" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Client is the client model for downloader package.
|
|
|
|
// Client is the client model for downloader package.
|
|
|
@ -26,7 +25,7 @@ func ClientSetup(ip, port string) *Client { |
|
|
|
var err error |
|
|
|
var err error |
|
|
|
client.conn, err = grpc.Dial(fmt.Sprintf("%s:%s", ip, port), client.opts...) |
|
|
|
client.conn, err = grpc.Dial(fmt.Sprintf("%s:%s", ip, port), client.opts...) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("client.go:ClientSetup fail to dial: %v", err) |
|
|
|
utils.GetLogInstance().Info("client.go:ClientSetup fail to dial: ", "error", err) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -38,7 +37,7 @@ func ClientSetup(ip, port string) *Client { |
|
|
|
func (client *Client) Close() { |
|
|
|
func (client *Client) Close() { |
|
|
|
err := client.conn.Close() |
|
|
|
err := client.conn.Close() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("unable to close connection %v with error %v ", client.conn, err) |
|
|
|
utils.GetLogInstance().Info("unable to close connection ") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -49,7 +48,7 @@ func (client *Client) GetBlockHashes(startHash []byte) *pb.DownloaderResponse { |
|
|
|
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER, BlockHash: startHash} |
|
|
|
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER, BlockHash: startHash} |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("[SYNC] GetBlockHashes query failed with error %v", err) |
|
|
|
utils.GetLogInstance().Info("[SYNC] GetBlockHashes query failed", "error", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return response |
|
|
|
return response |
|
|
|
} |
|
|
|
} |
|
|
@ -66,7 +65,7 @@ func (client *Client) GetBlocks(hashes [][]byte) *pb.DownloaderResponse { |
|
|
|
} |
|
|
|
} |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("[SYNC] downloader/client.go:GetBlocks query failed with error %v", err) |
|
|
|
utils.GetLogInstance().Info("[SYNC] downloader/client.go:GetBlocks query failed.", "error", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return response |
|
|
|
return response |
|
|
|
} |
|
|
|
} |
|
|
@ -81,7 +80,7 @@ func (client *Client) Register(hash []byte) *pb.DownloaderResponse { |
|
|
|
copy(request.PeerHash, hash) |
|
|
|
copy(request.PeerHash, hash) |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("[SYNC] client.go:Register failed with code %v", err) |
|
|
|
utils.GetLogInstance().Info("[SYNC] client.go:Register failed.", "error", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return response |
|
|
|
return response |
|
|
|
} |
|
|
|
} |
|
|
@ -105,7 +104,7 @@ func (client *Client) PushNewBlock(peerID uint32, blockHash []byte, timeout bool |
|
|
|
|
|
|
|
|
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
response, err := client.dlClient.Query(ctx, request) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("[SYNC] unable to send new block to unsync node with error: %v", err) |
|
|
|
utils.GetLogInstance().Info("[SYNC] unable to send new block to unsync node", "error", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return response |
|
|
|
return response |
|
|
|
} |
|
|
|
} |
|
|
|