2019-09-04 19:29:34 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact
|
|
|
|
|
|
|
|
import (
|
2019-09-19 20:56:34 +01:00
|
|
|
"sync"
|
|
|
|
|
2019-09-10 17:05:07 +01:00
|
|
|
"github.com/zeebo/errs"
|
2019-09-04 19:29:34 +01:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
"storj.io/storj/pkg/rpc"
|
2019-09-04 19:29:34 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
)
|
|
|
|
|
2019-09-12 17:33:04 +01:00
|
|
|
// Error is the default error class for contact package.
|
2019-09-10 17:05:07 +01:00
|
|
|
var Error = errs.Class("contact")
|
|
|
|
|
2019-09-04 19:29:34 +01:00
|
|
|
var mon = monkit.Package()
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
// Config contains configurable values for contact service
|
|
|
|
type Config struct {
|
|
|
|
ExternalAddress string `user:"true" help:"the public address of the node, useful for nodes behind NAT" default:""`
|
|
|
|
}
|
|
|
|
|
2019-09-12 17:33:04 +01:00
|
|
|
// Service is the contact service between storage nodes and satellites.
|
|
|
|
// It is responsible for updating general node information like address, capacity, and uptime.
|
|
|
|
// It is also responsible for updating peer identity information for verifying signatures from that node.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-09-04 19:29:34 +01:00
|
|
|
type Service struct {
|
2019-09-19 20:56:34 +01:00
|
|
|
log *zap.Logger
|
|
|
|
|
|
|
|
mutex sync.Mutex
|
|
|
|
self *overlay.NodeDossier
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
overlay *overlay.Service
|
|
|
|
peerIDs overlay.PeerIdentities
|
|
|
|
dialer rpc.Dialer
|
2019-09-04 19:29:34 +01:00
|
|
|
}
|
|
|
|
|
2019-09-12 17:33:04 +01:00
|
|
|
// NewService creates a new contact service.
|
2019-09-19 05:46:39 +01:00
|
|
|
func NewService(log *zap.Logger, self *overlay.NodeDossier, overlay *overlay.Service, peerIDs overlay.PeerIdentities, dialer rpc.Dialer) *Service {
|
2019-09-04 19:29:34 +01:00
|
|
|
return &Service{
|
2019-09-19 05:46:39 +01:00
|
|
|
log: log,
|
|
|
|
self: self,
|
|
|
|
overlay: overlay,
|
|
|
|
peerIDs: peerIDs,
|
|
|
|
dialer: dialer,
|
2019-09-04 19:29:34 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-19 20:56:34 +01:00
|
|
|
|
|
|
|
// Local returns the satellite node dossier
|
|
|
|
func (service *Service) Local() overlay.NodeDossier {
|
|
|
|
service.mutex.Lock()
|
|
|
|
defer service.mutex.Unlock()
|
|
|
|
return *service.self
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes resources
|
|
|
|
func (service *Service) Close() error { return nil }
|