-
Notifications
You must be signed in to change notification settings - Fork 25
/
peers-service.go
35 lines (29 loc) · 1.03 KB
/
peers-service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package peers
import (
"context"
peersv1 "github.com/fluxninja/aperture/api/gen/proto/go/aperture/peers/v1"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
)
// PeerDiscoveryService is the implementation of peersv1.PeerDiscoveryServiceServer interface.
type PeerDiscoveryService struct {
peersv1.UnimplementedPeerDiscoveryServiceServer
peerDiscovery *PeerDiscovery
}
// RegisterPeerDiscoveryService registers a service for peer discovery.
func RegisterPeerDiscoveryService(server *grpc.Server, pd *PeerDiscovery) {
svc := &PeerDiscoveryService{
peerDiscovery: pd,
}
peersv1.RegisterPeerDiscoveryServiceServer(server, svc)
}
// GetPeers returns all peers.
func (svc *PeerDiscoveryService) GetPeers(ctx context.Context, _ *emptypb.Empty) (*peersv1.Peers, error) {
pd := svc.peerDiscovery
return pd.GetPeers(), nil
}
// GetPeer returns a peer.
func (svc *PeerDiscoveryService) GetPeer(ctx context.Context, req *peersv1.PeerRequest) (*peersv1.Peer, error) {
pd := svc.peerDiscovery
return pd.GetPeer(req.Address)
}