grpc server and client
This commit is contained in:
parent
9e31cfc7a0
commit
1975b98eba
5
Makefile
5
Makefile
@ -10,3 +10,8 @@ lint:
|
||||
--enable=gosimple \
|
||||
--exclude=.*\.pb\.go \
|
||||
./...
|
||||
|
||||
|
||||
proto:
|
||||
@echo "Running ${@}"
|
||||
./scripts/build-protos.sh
|
22
pkg/overlay/overlay.go
Normal file
22
pkg/overlay/overlay.go
Normal file
@ -0,0 +1,22 @@
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coyle/storj/protos/overlay"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
// TODO: fill this in with logic to communicate with kademlia
|
||||
return nil, 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) {
|
||||
// TODO: fill this in with logic to communicate with kademlia
|
||||
return nil, nil
|
||||
}
|
36
pkg/overlay/service.go
Normal file
36
pkg/overlay/service.go
Normal file
@ -0,0 +1,36 @@
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/coyle/storj/protos/overlay"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
grpcServer := grpc.NewServer()
|
||||
overlay.RegisterOverlayServer(grpcServer, &Overlay{})
|
||||
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return grpcServer, nil
|
||||
}
|
||||
|
||||
// NewClient connects to grpc server at the provided address with the provided options
|
||||
// returns a new instance of an overlay Client
|
||||
func NewClient(serverAddr *string, opts ...grpc.DialOption) (overlay.OverlayClient, error) {
|
||||
conn, err := grpc.Dial(*serverAddr, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return overlay.NewOverlayClient(conn), nil
|
||||
}
|
3
scripts/build-protos.sh
Executable file
3
scripts/build-protos.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
protoc -Iprotos/overlay -Iprotos/google protos/overlay/overlay.proto --go_out=plugins=grpc:protos/overlay/
|
Loading…
Reference in New Issue
Block a user