-
Notifications
You must be signed in to change notification settings - Fork 394
/
service.go
42 lines (31 loc) · 935 Bytes
/
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
36
37
38
39
40
41
42
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package bootstrapweb
import (
"context"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/pkg/pb"
)
// Service is handling bootstrap related logic
type Service struct {
log *zap.Logger
kademlia *kademlia.Kademlia
}
// NewService returns new instance of Service
func NewService(log *zap.Logger, kademlia *kademlia.Kademlia) (*Service, error) {
if log == nil {
return nil, errs.New("log can't be nil")
}
if kademlia == nil {
return nil, errs.New("kademlia can't be nil")
}
return &Service{log: log, kademlia: kademlia}, nil
}
// IsNodeAvailable is a method for checking if node is up
func (s *Service) IsNodeAvailable(ctx context.Context, nodeID pb.NodeID) (bool, error) {
_, err := s.kademlia.FetchPeerIdentity(ctx, nodeID)
isNodeAvailable := err == nil
return isNodeAvailable, err
}