Adding gRPC server/clients for overlay (#14)
* overlay proto * grpc server and client * fix import to storj * tests * change imports * imports cleanup/comments * PR comments addressed from @jtolds
This commit is contained in:
parent
af30d8ffa1
commit
ecbd5f08c3
@ -1,22 +1,25 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coyle/storj/protos/overlay"
|
||||
proto "storj.io/storj/protos/overlay" // naming proto to avoid confusion with this package
|
||||
)
|
||||
|
||||
// Overlay implements our overlay RPC service
|
||||
type Overlay struct{}
|
||||
|
||||
// Lookup finds the address of a node in our overlay network
|
||||
func (o *Overlay) Lookup(ctx context.Context, req *overlay.LookupRequest) (*overlay.LookupResponse, error) {
|
||||
func (o *Overlay) Lookup(ctx context.Context, req *proto.LookupRequest) (*proto.LookupResponse, error) {
|
||||
// TODO: fill this in with logic to communicate with kademlia
|
||||
return nil, nil
|
||||
return &proto.LookupResponse{}, nil
|
||||
}
|
||||
|
||||
// FindStorageNodes searches the overlay network for nodes that meet the provided requirements
|
||||
func (o *Overlay) FindStorageNodes(ctx context.Context, req *overlay.FindStorageNodesRequest) (*overlay.FindStorageNodesResponse, error) {
|
||||
func (o *Overlay) FindStorageNodes(ctx context.Context, req *proto.FindStorageNodesRequest) (*proto.FindStorageNodesResponse, error) {
|
||||
// TODO: fill this in with logic to communicate with kademlia
|
||||
return nil, nil
|
||||
return &proto.FindStorageNodesResponse{}, nil
|
||||
}
|
||||
|
@ -1,27 +1,21 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/storj/storj/protos/overlay"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"storj.io/storj/protos/overlay"
|
||||
)
|
||||
|
||||
// NewServer creates a new Overlay Service Server and begins serving requests on the provided port
|
||||
func NewServer(port uint32) (*grpc.Server, error) {
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// NewServer creates a new Overlay Service Server
|
||||
func NewServer() *grpc.Server {
|
||||
|
||||
grpcServer := grpc.NewServer()
|
||||
overlay.RegisterOverlayServer(grpcServer, &Overlay{})
|
||||
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return grpcServer, nil
|
||||
return grpcServer
|
||||
}
|
||||
|
||||
// NewClient connects to grpc server at the provided address with the provided options
|
||||
|
44
pkg/overlay/service_test.go
Normal file
44
pkg/overlay/service_test.go
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
proto "github.com/coyle/storj/protos/overlay" // naming proto to avoid confusion with this package
|
||||
)
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
|
||||
assert.NoError(t, err)
|
||||
|
||||
srv := NewServer()
|
||||
assert.NotNil(t, srv)
|
||||
|
||||
go srv.Serve(lis)
|
||||
srv.Stop()
|
||||
}
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
|
||||
assert.NoError(t, err)
|
||||
srv := NewServer()
|
||||
go srv.Serve(lis)
|
||||
defer srv.Stop()
|
||||
|
||||
address := lis.Addr().String()
|
||||
c, err := NewClient(&address, grpc.WithInsecure())
|
||||
assert.NoError(t, err)
|
||||
|
||||
r, err := c.Lookup(context.Background(), &proto.LookupRequest{})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, r)
|
||||
}
|
Loading…
Reference in New Issue
Block a user