From c43378352dc28cbebf18a1cc728efed3caffa4dd Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Sun, 25 Nov 2018 11:18:06 -0800 Subject: [PATCH] add server api for downloader --- syncing/downloader/server.go | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 syncing/downloader/server.go diff --git a/syncing/downloader/server.go b/syncing/downloader/server.go new file mode 100644 index 000000000..532371a99 --- /dev/null +++ b/syncing/downloader/server.go @@ -0,0 +1,48 @@ +package downloader + +import ( + "context" + "fmt" + "net" + + "github.com/harmony-one/harmony/node" + pb "github.com/harmony-one/harmony/syncing/downloader/proto" + "google.golang.org/grpc" +) + +// Server ... +type Server struct { + node *node.Node +} + +// Query returns the feature at the given point. +func (s *Server) Query(ctx context.Context, request *pb.DownloaderRequest) (*pb.DownloaderResponse, error) { + res := &pb.DownloaderResponse{} + if request.Type == pb.DownloaderRequest_HEADER { + } else { + res.Payload = append(res.Payload, []byte{1}) + } + return res, nil +} + +// Start ... +func (s *Server) Start(port string) error { + if s.node == nil { + return ErrDownloaderWithNoNode + } + lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%s", port)) + if err != nil { + + } + var opts []grpc.ServerOption + grpcServer := grpc.NewServer(opts...) + pb.RegisterDownloaderServer(grpcServer, s) + grpcServer.Serve(lis) + return nil +} + +// NewServer ... +func NewServer(node *node.Node) *Server { + s := &Server{node: node} + return s +}