From 979f1a6e614ff64f6aafeb43d0147d6de4a1846c Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Tue, 27 Nov 2018 00:38:45 -0800 Subject: [PATCH] add more doc --- syncing/downloader/client.go | 10 +++++----- syncing/downloader/errors.go | 2 +- syncing/downloader/interface.go | 2 +- syncing/downloader/server.go | 6 +++--- syncing/downloader/server_test.go | 3 +++ syncing/syncing.go | 7 ++++--- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/syncing/downloader/client.go b/syncing/downloader/client.go index e972af6ad..d18e7ad06 100644 --- a/syncing/downloader/client.go +++ b/syncing/downloader/client.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() diff --git a/syncing/downloader/errors.go b/syncing/downloader/errors.go index b5aacc029..59ee5dc3f 100644 --- a/syncing/downloader/errors.go +++ b/syncing/downloader/errors.go @@ -2,7 +2,7 @@ package downloader import "errors" -// Errors ... +// Errors for downloader package. var ( ErrDownloaderWithNoNode = errors.New("no node attached") ) diff --git a/syncing/downloader/interface.go b/syncing/downloader/interface.go index 3acde71bf..d85374b5f 100644 --- a/syncing/downloader/interface.go +++ b/syncing/downloader/interface.go @@ -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. diff --git a/syncing/downloader/server.go b/syncing/downloader/server.go index 800ce151a..753e6572e 100644 --- a/syncing/downloader/server.go +++ b/syncing/downloader/server.go @@ -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 diff --git a/syncing/downloader/server_test.go b/syncing/downloader/server_test.go index dd812c738..27be81203 100644 --- a/syncing/downloader/server_test.go +++ b/syncing/downloader/server_test.go @@ -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() diff --git a/syncing/syncing.go b/syncing/syncing.go index 6cf3d60ac..6fdb2f709 100644 --- a/syncing/syncing.go +++ b/syncing/syncing.go @@ -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)