Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement storj.NodeURL in trusted satellites #2388

Merged
merged 27 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
283cdd5
implement storj.NodeURL in trusted satellites
cam-a Jun 28, 2019
e0b2b37
Merge branch 'master' into trusted-nodeURLs
cam-a Jun 28, 2019
b3fa922
gofmt
cam-a Jun 29, 2019
4ba6291
use type storj.NodeURLs
cam-a Jul 1, 2019
0e921ea
add method Type to implement flag.Value interface
cam-a Jul 1, 2019
36879b4
add storj.NodeURLs to bindConfig, add tests
cam-a Jul 1, 2019
b34ab11
Merge branch 'master' into trusted-nodeURLs
cam-a Jul 1, 2019
af3e0da
gofmt
cam-a Jul 1, 2019
beef335
Merge branch 'master' into trusted-nodeURLs
cam-a Jul 2, 2019
1a3a70b
add NodeURL to TestBindDevDefaults
cam-a Jul 2, 2019
6529625
add URL method to peers
cam-a Jul 2, 2019
9fa82ff
test addresses are stored correctly
cam-a Jul 2, 2019
309ecf7
gofmt
cam-a Jul 2, 2019
0ad6f66
gofmt
cam-a Jul 2, 2019
7226f8b
Merge branch 'trusted-nodeURLs' of github.com:storj/storj into truste…
cam-a Jul 2, 2019
0e62065
gofmt
cam-a Jul 2, 2019
40ca795
renaming
cam-a Jul 3, 2019
fedaf04
reword log
cam-a Jul 3, 2019
840358a
Merge branch 'master' into trusted-nodeURLs
cam-a Jul 3, 2019
257f4fd
add read lock in GetAddress, test parallel reads
cam-a Jul 3, 2019
5103ae3
Merge branch 'master' into trusted-nodeURLs
cam-a Jul 3, 2019
47c67b1
gofmt
cam-a Jul 3, 2019
e8a47f2
more gofmt
cam-a Jul 3, 2019
ccdff8b
Merge branch 'master' into trusted-nodeURLs
cam-a Jul 3, 2019
7a48478
restart jenkins, unrelated failure
cam-a Jul 3, 2019
2d296b4
Merge branch 'master' into trusted-nodeURLs
cam-a Jul 3, 2019
0b5b942
restart jenkins, unrelated failure
cam-a Jul 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions bootstrap/peer.go
Expand Up @@ -258,5 +258,8 @@ func (peer *Peer) Local() overlay.NodeDossier { return peer.Kademlia.RoutingTabl
// Addr returns the public address.
func (peer *Peer) Addr() string { return peer.Server.Addr().String() }

// URL returns the storj.NodeURL
func (peer *Peer) URL() storj.NodeURL { return storj.NodeURL{ID: peer.ID(), Address: peer.Addr()} }

// PrivateAddr returns the private address.
func (peer *Peer) PrivateAddr() string { return peer.Server.PrivateAddr().String() }
5 changes: 3 additions & 2 deletions internal/testplanet/planet.go
Expand Up @@ -35,6 +35,7 @@ import (
type Peer interface {
ID() storj.NodeID
Addr() string
URL() storj.NodeURL
Local() overlay.NodeDossier

Run(context.Context) error
Expand Down Expand Up @@ -178,9 +179,9 @@ func NewCustom(log *zap.Logger, config Config) (*Planet, error) {
return nil, errs.Combine(err, planet.Shutdown())
}

whitelistedSatellites := make([]string, len(planet.Satellites))
whitelistedSatellites := make(storj.NodeURLs, 0, len(planet.Satellites))
for _, satellite := range planet.Satellites {
whitelistedSatellites = append(whitelistedSatellites, satellite.ID().String())
whitelistedSatellites = append(whitelistedSatellites, satellite.URL())
}

planet.StorageNodes, err = planet.newStorageNodes(config.StorageNodeCount, whitelistedSatellites)
Expand Down
7 changes: 4 additions & 3 deletions internal/testplanet/storagenode.go
Expand Up @@ -16,6 +16,7 @@ import (
"storj.io/storj/pkg/peertls/extensions"
"storj.io/storj/pkg/peertls/tlsopts"
"storj.io/storj/pkg/server"
"storj.io/storj/pkg/storj"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/collector"
"storj.io/storj/storagenode/console/consoleserver"
Expand All @@ -27,7 +28,7 @@ import (
)

// newStorageNodes initializes storage nodes
func (planet *Planet) newStorageNodes(count int, whitelistedSatelliteIDs []string) ([]*storagenode.Peer, error) {
func (planet *Planet) newStorageNodes(count int, whitelistedSatelliteURLs storj.NodeURLs) ([]*storagenode.Peer, error) {
var xs []*storagenode.Peer
defer func() {
for _, x := range xs {
Expand Down Expand Up @@ -98,8 +99,8 @@ func (planet *Planet) newStorageNodes(count int, whitelistedSatelliteIDs []strin
AllocatedBandwidth: memory.TB,
KBucketRefreshInterval: time.Hour,

SatelliteIDRestriction: true,
WhitelistedSatelliteIDs: strings.Join(whitelistedSatelliteIDs, ","),
SatelliteIDRestriction: true,
WhitelistedSatelliteURLs: whitelistedSatelliteURLs,
},
Collector: collector.Config{
Interval: time.Minute,
Expand Down
38 changes: 29 additions & 9 deletions pkg/cfgstruct/bind_test.go
Expand Up @@ -121,14 +121,16 @@ func TestConfDir(t *testing.T) {
func TestBindDevDefaults(t *testing.T) {
f := pflag.NewFlagSet("test", pflag.PanicOnError)
var c struct {
String string `default:"dev"`
Bool bool `releaseDefault:"false" devDefault:"true"`
Int64 int64 `releaseDefault:"0" devDefault:"1"`
Int int `default:"2"`
Uint64 uint64 `default:"3"`
Uint uint `releaseDefault:"0" devDefault:"4"`
Float64 float64 `default:"5.5"`
Duration time.Duration `default:"1h"`
String string `default:"dev"`
Bool bool `releaseDefault:"false" devDefault:"true"`
Int64 int64 `releaseDefault:"0" devDefault:"1"`
Int int `default:"2"`
Uint64 uint64 `default:"3"`
Uint uint `releaseDefault:"0" devDefault:"4"`
Float64 float64 `default:"5.5"`
Duration time.Duration `default:"1h"`
NodeURL storj.NodeURL `releaseDefault:"" devDefault:"12EayRS2V1kEsWESU9QMRseFhdxYxKicsiFmxrsLZHeLUtdps3S@mars.tardigrade.io:7777"`
NodeURLs storj.NodeURLs `releaseDefault:"" devDefault:"12EayRS2V1kEsWESU9QMRseFhdxYxKicsiFmxrsLZHeLUtdps3S@mars.tardigrade.io:7777,12L9ZFwhzVpuEKMUNUqkaTLGzwY9G24tbiigLiXpmZWKwmcNDDs@jupiter.tardigrade.io:7777"`
Struct struct {
AnotherString string `default:"dev2"`
}
Expand All @@ -138,6 +140,11 @@ func TestBindDevDefaults(t *testing.T) {
}
Bind(f, &c, UseDevDefaults())

node1, err := storj.NodeIDFromString("12EayRS2V1kEsWESU9QMRseFhdxYxKicsiFmxrsLZHeLUtdps3S")
require.NoError(t, err)
node2, err := storj.NodeIDFromString("12L9ZFwhzVpuEKMUNUqkaTLGzwY9G24tbiigLiXpmZWKwmcNDDs")
require.NoError(t, err)

assertEqual(c.String, string("dev"))
assertEqual(c.Bool, bool(true))
assertEqual(c.Int64, int64(1))
Expand All @@ -146,10 +153,19 @@ func TestBindDevDefaults(t *testing.T) {
assertEqual(c.Uint, uint(4))
assertEqual(c.Float64, float64(5.5))
assertEqual(c.Duration, time.Hour)
assertEqual(c.NodeURL, storj.NodeURL{ID: node1, Address: "mars.tardigrade.io:7777"})
assertEqual(c.NodeURLs, storj.NodeURLs{
storj.NodeURL{ID: node1, Address: "mars.tardigrade.io:7777"},
storj.NodeURL{ID: node2, Address: "jupiter.tardigrade.io:7777"},
})
assertEqual(c.Struct.AnotherString, string("dev2"))
assertEqual(c.Fields[0].AnotherInt, int(6))
assertEqual(c.Fields[3].AnotherInt, int(6))
err := f.Parse([]string{

node3, err := storj.NodeIDFromString("121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6")
require.NoError(t, err)

err = f.Parse([]string{
"--string=1",
"--bool=true",
"--int64=1",
Expand All @@ -158,6 +174,8 @@ func TestBindDevDefaults(t *testing.T) {
"--uint=1",
"--float64=1",
"--duration=1h",
"--node-url=121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@saturn.tardigrade.io:7777",
"--node-ur-ls=121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@saturn.tardigrade.io:7777",
"--struct.another-string=1",
"--fields.03.another-int=1"})
if err != nil {
Expand All @@ -171,6 +189,8 @@ func TestBindDevDefaults(t *testing.T) {
assertEqual(c.Uint, uint(1))
assertEqual(c.Float64, float64(1))
assertEqual(c.Duration, time.Hour)
assertEqual(c.NodeURL, storj.NodeURL{ID: node3, Address: "saturn.tardigrade.io:7777"})
assertEqual(c.NodeURLs, storj.NodeURLs{storj.NodeURL{ID: node3, Address: "saturn.tardigrade.io:7777"}})
assertEqual(c.Struct.AnotherString, string("1"))
assertEqual(c.Fields[0].AnotherInt, int(6))
assertEqual(c.Fields[3].AnotherInt, int(1))
Expand Down
3 changes: 3 additions & 0 deletions satellite/peer.go
Expand Up @@ -749,5 +749,8 @@ func (peer *Peer) Local() overlay.NodeDossier { return peer.Kademlia.RoutingTabl
// Addr returns the public address.
func (peer *Peer) Addr() string { return peer.Server.Addr().String() }

// URL returns the storj.NodeURL.
func (peer *Peer) URL() storj.NodeURL { return storj.NodeURL{ID: peer.ID(), Address: peer.Addr()} }

// PrivateAddr returns the private address.
func (peer *Peer) PrivateAddr() string { return peer.Server.PrivateAddr().String() }
5 changes: 4 additions & 1 deletion storagenode/peer.go
Expand Up @@ -218,7 +218,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, config Config, ver

{ // setup storage
trustAllSatellites := !config.Storage.SatelliteIDRestriction
peer.Storage2.Trust, err = trust.NewPool(peer.Kademlia.Service, trustAllSatellites, config.Storage.WhitelistedSatelliteIDs)
peer.Storage2.Trust, err = trust.NewPool(peer.Kademlia.Service, trustAllSatellites, config.Storage.WhitelistedSatelliteURLs)
if err != nil {
return nil, errs.Combine(err, peer.Close())
}
Expand Down Expand Up @@ -419,5 +419,8 @@ func (peer *Peer) Local() overlay.NodeDossier { return peer.Kademlia.RoutingTabl
// Addr returns the public address.
func (peer *Peer) Addr() string { return peer.Server.Addr().String() }

// URL returns the storj.NodeURL.
func (peer *Peer) URL() storj.NodeURL { return storj.NodeURL{ID: peer.ID(), Address: peer.Addr()} }

// PrivateAddr returns the private address.
func (peer *Peer) PrivateAddr() string { return peer.Server.PrivateAddr().String() }
14 changes: 7 additions & 7 deletions storagenode/piecestore/endpoint.go
Expand Up @@ -22,6 +22,7 @@ import (
"storj.io/storj/pkg/auth/signing"
"storj.io/storj/pkg/identity"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/storj"
"storj.io/storj/storagenode/bandwidth"
"storj.io/storj/storagenode/monitor"
"storj.io/storj/storagenode/orders"
Expand All @@ -43,13 +44,12 @@ var _ pb.PiecestoreServer = (*Endpoint)(nil)

// OldConfig contains everything necessary for a server
type OldConfig struct {
Path string `help:"path to store data in" default:"$CONFDIR/storage"`

WhitelistedSatelliteIDs string `help:"a comma-separated list of approved satellite node ids" devDefault:"" releaseDefault:"12EayRS2V1kEsWESU9QMRseFhdxYxKicsiFmxrsLZHeLUtdps3S,118UWpMCHzs6CvSgWd9BfFVjw5K9pZbJjkfZJexMtSkmKxvvAW,121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6,12L9ZFwhzVpuEKMUNUqkaTLGzwY9G24tbiigLiXpmZWKwmcNDDs"`
SatelliteIDRestriction bool `help:"if true, only allow data from approved satellites" devDefault:"false" releaseDefault:"true"`
AllocatedDiskSpace memory.Size `user:"true" help:"total allocated disk space in bytes" default:"1TB"`
AllocatedBandwidth memory.Size `user:"true" help:"total allocated bandwidth in bytes" default:"2TB"`
KBucketRefreshInterval time.Duration `help:"how frequently Kademlia bucket should be refreshed with node stats" default:"1h0m0s"`
Path string `help:"path to store data in" default:"$CONFDIR/storage"`
WhitelistedSatelliteURLs storj.NodeURLs `help:"a comma-separated list of approved satellite node urls" devDefault:"" releaseDefault:"12EayRS2V1kEsWESU9QMRseFhdxYxKicsiFmxrsLZHeLUtdps3S@mars.tardigrade.io:7777,118UWpMCHzs6CvSgWd9BfFVjw5K9pZbJjkfZJexMtSkmKxvvAW@satellite.stefan-benten.de:7777,121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@saturn.tardigrade.io:7777,12L9ZFwhzVpuEKMUNUqkaTLGzwY9G24tbiigLiXpmZWKwmcNDDs@jupiter.tardigrade.io:7777"`
cam-a marked this conversation as resolved.
Show resolved Hide resolved
SatelliteIDRestriction bool `help:"if true, only allow data from approved satellites" devDefault:"false" releaseDefault:"true"`
AllocatedDiskSpace memory.Size `user:"true" help:"total allocated disk space in bytes" default:"1TB"`
AllocatedBandwidth memory.Size `user:"true" help:"total allocated bandwidth in bytes" default:"2TB"`
KBucketRefreshInterval time.Duration `help:"how frequently Kademlia bucket should be refreshed with node stats" default:"1h0m0s"`
}

// Config defines parameters for piecestore endpoint.
Expand Down
27 changes: 14 additions & 13 deletions storagenode/trust/service.go
Expand Up @@ -6,7 +6,6 @@ package trust
import (
"context"
"fmt"
"strings"
"sync"

"github.com/zeebo/errs"
Expand Down Expand Up @@ -36,10 +35,11 @@ type Pool struct {
type satelliteInfoCache struct {
mu sync.Mutex
identity *identity.PeerIdentity
nodeURL storj.NodeURL
}

// NewPool creates a new trust pool using kademlia to find certificates and with the specified list of trusted satellites.
func NewPool(kademlia *kademlia.Kademlia, trustAll bool, trustedSatelliteIDs string) (*Pool, error) {
func NewPool(kademlia *kademlia.Kademlia, trustAll bool, trustedSatelliteURLs storj.NodeURLs) (*Pool, error) {
cam-a marked this conversation as resolved.
Show resolved Hide resolved
if trustAll {
return &Pool{
kademlia: kademlia,
Expand All @@ -54,17 +54,8 @@ func NewPool(kademlia *kademlia.Kademlia, trustAll bool, trustedSatelliteIDs str
// parse the comma separated list of approved satellite IDs into an array of storj.NodeIDs
trusted := make(map[storj.NodeID]*satelliteInfoCache)

for _, s := range strings.Split(trustedSatelliteIDs, ",") {
s = strings.TrimSpace(s)
if s == "" {
continue
}

satelliteID, err := storj.NodeIDFromString(s)
if err != nil {
return nil, err
}
trusted[satelliteID] = &satelliteInfoCache{} // we will set these later
for _, node := range trustedSatelliteURLs {
trusted[node.ID] = &satelliteInfoCache{nodeURL: node}
}

return &Pool{
Expand Down Expand Up @@ -149,3 +140,13 @@ func (pool *Pool) GetSatellites(ctx context.Context) (satellites []storj.NodeID)
}
return satellites
}

// GetAddress returns the address of a satellite in the trusted list
func (pool *Pool) GetAddress(ctx context.Context, id storj.NodeID) (_ string, err error) {
defer mon.Task()(&ctx)(&err)
info, ok := pool.trustedSatellites[id]
cam-a marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return "", Error.New("ID not found in trusted satellites list (%v)", id)
cam-a marked this conversation as resolved.
Show resolved Hide resolved
}
return info.nodeURL.Address, nil
}
12 changes: 12 additions & 0 deletions storagenode/trust/service_test.go
Expand Up @@ -59,3 +59,15 @@ func TestGetSignee(t *testing.T) {

assert.NoError(t, group.Wait())
}

func TestGetAddress(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 5, StorageNodeCount: 1, UplinkCount: 0,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
for _, sat := range planet.Satellites {
address, err := planet.StorageNodes[0].Storage2.Trust.GetAddress(ctx, sat.ID())
require.NoError(t, err)
assert.Equal(t, sat.Addr(), address)
}
})
}