From 9821a21e5c2c7f1640cbf186278441744b7071de Mon Sep 17 00:00:00 2001 From: paul cannon Date: Wed, 4 Sep 2019 14:04:18 -0500 Subject: [PATCH] satellite,storagenode,bootstrap: add contact service to peer (#2951) * satellite,storagenode,bootstrap: add contact service to peer --- satellite/peer.go | 10 ++++++++++ storagenode/contact/service.go | 6 +++--- storagenode/peer.go | 11 +++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/satellite/peer.go b/satellite/peer.go index 2ca8c637f..0799818cd 100644 --- a/satellite/peer.go +++ b/satellite/peer.go @@ -40,6 +40,7 @@ import ( "storj.io/storj/satellite/console" "storj.io/storj/satellite/console/consoleauth" "storj.io/storj/satellite/console/consoleweb" + "storj.io/storj/satellite/contact" "storj.io/storj/satellite/dbcleanup" "storj.io/storj/satellite/discovery" "storj.io/storj/satellite/gc" @@ -159,6 +160,10 @@ type Peer struct { Inspector *kademlia.Inspector } + Contact struct { + Service *contact.Service + } + Overlay struct { DB overlay.DB Service *overlay.Service @@ -352,6 +357,11 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, revocationDB exten pb.RegisterKadInspectorServer(peer.Server.PrivateGRPC(), peer.Kademlia.Inspector) } + { // setup contact service + log.Debug("Setting up contact service") + peer.Contact.Service = contact.NewService(peer.Log.Named("contact"), peer.Overlay.Service, peer.Transport) + } + { // setup discovery log.Debug("Setting up discovery") config := config.Discovery diff --git a/storagenode/contact/service.go b/storagenode/contact/service.go index c2f979d56..41223acd9 100644 --- a/storagenode/contact/service.go +++ b/storagenode/contact/service.go @@ -20,7 +20,7 @@ var mon = monkit.Package() // Service is the contact service between storage nodes and satellites type Service struct { log *zap.Logger - self *overlay.NodeDossier + self overlay.NodeDossier transport transport.Client mu sync.Mutex @@ -30,7 +30,7 @@ type Service struct { } // NewService creates a new contact service -func NewService(log *zap.Logger, self *overlay.NodeDossier, transport transport.Client) *Service { +func NewService(log *zap.Logger, self overlay.NodeDossier, transport transport.Client) *Service { return &Service{ log: log, self: self, @@ -56,5 +56,5 @@ func (service *Service) wasPinged(when time.Time, srcNodeID storj.NodeID, srcAdd // Local returns the local node func (service *Service) Local() overlay.NodeDossier { - return *service.self + return service.self } diff --git a/storagenode/peer.go b/storagenode/peer.go index 5aaf7ef4e..e58fe5f6c 100644 --- a/storagenode/peer.go +++ b/storagenode/peer.go @@ -29,6 +29,7 @@ import ( "storj.io/storj/storagenode/collector" "storj.io/storj/storagenode/console" "storj.io/storj/storagenode/console/consoleserver" + "storj.io/storj/storagenode/contact" "storj.io/storj/storagenode/inspector" "storj.io/storj/storagenode/monitor" "storj.io/storj/storagenode/nodestats" @@ -117,6 +118,11 @@ type Peer struct { Inspector *kademlia.Inspector } + Contact struct { + Service *contact.Service + Endpoint *contact.Endpoint + } + Storage2 struct { // TODO: lift things outside of it to organize better Trust *trust.Pool @@ -237,6 +243,11 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, revocationDB exten pb.RegisterKadInspectorServer(peer.Server.PrivateGRPC(), peer.Kademlia.Inspector) } + { // setup contact service + peer.Contact.Service = contact.NewService(peer.Log.Named("contact"), peer.Kademlia.RoutingTable.Local(), peer.Transport) + peer.Contact.Endpoint = contact.NewEndpoint(peer.Log.Named("contact:endpoint"), peer.Contact.Service) + } + { // setup storage peer.Storage2.BlobsCache = pieces.NewBlobsUsageCache(peer.DB.Pieces())