add more doc

pull/102/head
Minh Doan 6 years ago committed by Minh Doan
parent 3b1bd7fdf3
commit 979f1a6e61
  1. 10
      syncing/downloader/client.go
  2. 2
      syncing/downloader/errors.go
  3. 2
      syncing/downloader/interface.go
  4. 6
      syncing/downloader/server.go
  5. 3
      syncing/downloader/server_test.go
  6. 7
      syncing/syncing.go

@ -10,14 +10,14 @@ import (
"google.golang.org/grpc"
)
// Client ...
// Client is the client model for downloader package.
type Client struct {
dlClient pb.DownloaderClient
opts []grpc.DialOption
conn *grpc.ClientConn
}
// ClientSetup ...
// ClientSetup setups a Client given ip and port.
func ClientSetup(ip, port string) *Client {
client := Client{}
client.opts = append(client.opts, grpc.WithInsecure())
@ -32,12 +32,12 @@ func ClientSetup(ip, port string) *Client {
return &client
}
// Close ...
// Close closes the Client.
func (client *Client) Close() {
client.conn.Close()
}
// GetBlockHashes ...
// GetBlockHashes gets block hashes from all the peers by calling grpc request.
func (client *Client) GetBlockHashes() *pb.DownloaderResponse {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
@ -49,7 +49,7 @@ func (client *Client) GetBlockHashes() *pb.DownloaderResponse {
return response
}
// GetBlocks ...
// GetBlocks gets blocks in serialization byte array by calling a grpc request.
func (client *Client) GetBlocks(hashes [][]byte) *pb.DownloaderResponse {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

@ -2,7 +2,7 @@ package downloader
import "errors"
// Errors ...
// Errors for downloader package.
var (
ErrDownloaderWithNoNode = errors.New("no node attached")
)

@ -4,7 +4,7 @@ import (
pb "github.com/harmony-one/harmony/syncing/downloader/proto"
)
// DownloadInterface ...
// DownloadInterface is the interface for downloader package.
type DownloadInterface interface {
// Syncing blockchain from other peers.
// The returned channel is the signal of syncing finish.

@ -11,7 +11,7 @@ import (
pb "github.com/harmony-one/harmony/syncing/downloader/proto"
)
// Server ...
// Server is the Server struct for downloader package.
type Server struct {
downloadInterface DownloadInterface
}
@ -25,7 +25,7 @@ func (s *Server) Query(ctx context.Context, request *pb.DownloaderRequest) (*pb.
return response, nil
}
// Start ...
// Start starts the Server on given ip and port.
func (s *Server) Start(ip, port string) (*grpc.Server, error) {
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%s", ip, port))
if err != nil {
@ -38,7 +38,7 @@ func (s *Server) Start(ip, port string) (*grpc.Server, error) {
return grpcServer, nil
}
// NewServer ...
// NewServer creates new Server which implements DownloadInterface.
func NewServer(dlInterface DownloadInterface) *Server {
s := &Server{downloadInterface: dlInterface}
return s

@ -52,6 +52,7 @@ func (node *FakeNode) Init() {
node.bc = bc.CreateBlockchainWithMoreBlocks(addresses, ShardID)
}
// CalculateResponse is the implementation for DownloadInterface.
func (node *FakeNode) CalculateResponse(request *pb.DownloaderRequest) (*pb.DownloaderResponse, error) {
response := &pb.DownloaderResponse{}
if request.Type == pb.DownloaderRequest_HEADER {
@ -67,6 +68,7 @@ func (node *FakeNode) CalculateResponse(request *pb.DownloaderRequest) (*pb.Down
return response, nil
}
// TestGetBlockHashes tests GetBlockHashes function.
func TestGetBlockHashes(t *testing.T) {
fakeNode := &FakeNode{}
fakeNode.Init()
@ -85,6 +87,7 @@ func TestGetBlockHashes(t *testing.T) {
}
}
// TestGetBlocks tests GetBlocks function.
func TestGetBlocks(t *testing.T) {
fakeNode := &FakeNode{}
fakeNode.Init()

@ -44,7 +44,7 @@ type StateSync struct {
stateSyncTaskQueue *queue.Queue
}
// GetBlockHashes ...
// GetBlockHashes gets block hashes by calling grpc request to the corresponding peer.
func (peerConfig *SyncPeerConfig) GetBlockHashes() error {
if peerConfig.client == nil {
return ErrSyncPeerConfigClientNotReady
@ -58,7 +58,7 @@ func (peerConfig *SyncPeerConfig) GetBlockHashes() error {
return nil
}
// GetBlocks ...
// GetBlocks gets blocks by calling grpc request to the corresponding peer.
func (peerConfig *SyncPeerConfig) GetBlocks(hashes [][]byte) ([][]byte, error) {
if peerConfig.client == nil {
return nil, ErrSyncPeerConfigClientNotReady
@ -78,7 +78,7 @@ func (ss *StateSync) ProcessStateSyncFromPeers(peers []p2p.Peer, bc *blockchain.
return done, nil
}
// CreateSyncConfig ...
// CreateSyncConfig creates SyncConfig for StateSync object.
func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer) {
ss.peerNumber = len(peers)
ss.syncConfig = &SyncConfig{
@ -92,6 +92,7 @@ func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer) {
}
}
// makeConnectionToPeers makes grpc connection to all peers.
func (ss *StateSync) makeConnectionToPeers() {
var wg sync.WaitGroup
wg.Add(ss.peerNumber)

Loading…
Cancel
Save