kademlia: remove a redundant argument (#951)
This commit is contained in:
parent
d4d0b0d13b
commit
3fbd8c7d15
@ -76,7 +76,7 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) (err error)
|
|||||||
|
|
||||||
logger := zap.L()
|
logger := zap.L()
|
||||||
|
|
||||||
kad, err := NewKademlia(logger, server.Identity().ID, nodeType, []pb.Node{*in}, addr, metadata, server.Identity(), c.DBPath, c.Alpha)
|
kad, err := NewKademlia(logger, nodeType, []pb.Node{*in}, addr, metadata, server.Identity(), c.DBPath, c.Alpha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,9 @@ type Kademlia struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewKademlia returns a newly configured Kademlia instance
|
// NewKademlia returns a newly configured Kademlia instance
|
||||||
func NewKademlia(log *zap.Logger, id storj.NodeID, nodeType pb.NodeType, bootstrapNodes []pb.Node, address string, metadata *pb.NodeMetadata, identity *provider.FullIdentity, path string, alpha int) (*Kademlia, error) {
|
func NewKademlia(log *zap.Logger, nodeType pb.NodeType, bootstrapNodes []pb.Node, address string, metadata *pb.NodeMetadata, identity *provider.FullIdentity, path string, alpha int) (*Kademlia, error) {
|
||||||
self := pb.Node{
|
self := pb.Node{
|
||||||
Id: id,
|
Id: identity.ID,
|
||||||
Type: nodeType,
|
Type: nodeType,
|
||||||
Address: &pb.NodeAddress{Address: address},
|
Address: &pb.NodeAddress{Address: address},
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
@ -72,7 +72,7 @@ func NewKademlia(log *zap.Logger, id storj.NodeID, nodeType pb.NodeType, bootstr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketIdentifier := id.String()[:5] // need a way to differentiate between nodes if running more than one simultaneously
|
bucketIdentifier := self.Id.String()[:5] // need a way to differentiate between nodes if running more than one simultaneously
|
||||||
dbpath := filepath.Join(path, fmt.Sprintf("kademlia_%s.db", bucketIdentifier))
|
dbpath := filepath.Join(path, fmt.Sprintf("kademlia_%s.db", bucketIdentifier))
|
||||||
|
|
||||||
dbs, err := boltdb.NewShared(dbpath, KademliaBucket, NodeBucket)
|
dbs, err := boltdb.NewShared(dbpath, KademliaBucket, NodeBucket)
|
||||||
|
@ -41,25 +41,25 @@ func TestNewKademlia(t *testing.T) {
|
|||||||
rootdir, cleanup := mktempdir(t, "kademlia")
|
rootdir, cleanup := mktempdir(t, "kademlia")
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
id storj.NodeID
|
id *provider.FullIdentity
|
||||||
bn []pb.Node
|
bn []pb.Node
|
||||||
addr string
|
addr string
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
id: func() storj.NodeID {
|
id: func() *provider.FullIdentity {
|
||||||
id, err := testidentity.NewTestIdentity()
|
id, err := testidentity.NewTestIdentity()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return id.ID
|
return id
|
||||||
}(),
|
}(),
|
||||||
bn: []pb.Node{{Id: teststorj.NodeIDFromString("foo")}},
|
bn: []pb.Node{{Id: teststorj.NodeIDFromString("foo")}},
|
||||||
addr: "127.0.0.1:8080",
|
addr: "127.0.0.1:8080",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: func() storj.NodeID {
|
id: func() *provider.FullIdentity {
|
||||||
id, err := testidentity.NewTestIdentity()
|
id, err := testidentity.NewTestIdentity()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return id.ID
|
return id
|
||||||
}(),
|
}(),
|
||||||
bn: []pb.Node{{Id: teststorj.NodeIDFromString("foo")}},
|
bn: []pb.Node{{Id: teststorj.NodeIDFromString("foo")}},
|
||||||
addr: "127.0.0.1:8080",
|
addr: "127.0.0.1:8080",
|
||||||
@ -69,12 +69,7 @@ func TestNewKademlia(t *testing.T) {
|
|||||||
for i, v := range cases {
|
for i, v := range cases {
|
||||||
dir := filepath.Join(rootdir, strconv.Itoa(i))
|
dir := filepath.Join(rootdir, strconv.Itoa(i))
|
||||||
|
|
||||||
ca, err := testidentity.NewTestCA(ctx)
|
kad, err := NewKademlia(zaptest.NewLogger(t), pb.NodeType_STORAGE, v.bn, v.addr, nil, v.id, dir, defaultAlpha)
|
||||||
assert.NoError(t, err)
|
|
||||||
identity, err := ca.NewIdentity()
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
kad, err := NewKademlia(zaptest.NewLogger(t), v.id, pb.NodeType_STORAGE, v.bn, v.addr, nil, identity, dir, defaultAlpha)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, v.expectedErr, err)
|
assert.Equal(t, v.expectedErr, err)
|
||||||
assert.Equal(t, kad.bootstrapNodes, v.bn)
|
assert.Equal(t, kad.bootstrapNodes, v.bn)
|
||||||
@ -104,7 +99,7 @@ func TestPeerDiscovery(t *testing.T) {
|
|||||||
Email: "foo@bar.com",
|
Email: "foo@bar.com",
|
||||||
Wallet: "OperatorWallet",
|
Wallet: "OperatorWallet",
|
||||||
}
|
}
|
||||||
k, err := NewKademlia(zaptest.NewLogger(t), testID.ID, pb.NodeType_STORAGE, bootstrapNodes, testAddress, metadata, testID, dir, defaultAlpha)
|
k, err := NewKademlia(zaptest.NewLogger(t), pb.NodeType_STORAGE, bootstrapNodes, testAddress, metadata, testID, dir, defaultAlpha)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
rt, err := k.GetRoutingTable(ctx)
|
rt, err := k.GetRoutingTable(ctx)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -179,7 +174,7 @@ func testNode(t *testing.T, bn []pb.Node) (*Kademlia, *grpc.Server, func()) {
|
|||||||
dir, cleanup := mktempdir(t, "kademlia")
|
dir, cleanup := mktempdir(t, "kademlia")
|
||||||
|
|
||||||
logger := zaptest.NewLogger(t)
|
logger := zaptest.NewLogger(t)
|
||||||
k, err := NewKademlia(logger, fid.ID, pb.NodeType_STORAGE, bn, lis.Addr().String(), nil, fid, dir, defaultAlpha)
|
k, err := NewKademlia(logger, pb.NodeType_STORAGE, bn, lis.Addr().String(), nil, fid, dir, defaultAlpha)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
s := node.NewServer(logger, k)
|
s := node.NewServer(logger, k)
|
||||||
// new ident opts
|
// new ident opts
|
||||||
@ -253,7 +248,7 @@ func TestGetNodes(t *testing.T) {
|
|||||||
assert.NotEqual(t, fid.ID, fid2.ID)
|
assert.NotEqual(t, fid.ID, fid2.ID)
|
||||||
dir, cleanup := mktempdir(t, "kademlia")
|
dir, cleanup := mktempdir(t, "kademlia")
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
k, err := NewKademlia(zaptest.NewLogger(t), fid.ID, pb.NodeType_STORAGE, []pb.Node{{Id: fid2.ID, Address: &pb.NodeAddress{Address: lis.Addr().String()}}}, lis.Addr().String(), nil, fid, dir, defaultAlpha)
|
k, err := NewKademlia(zaptest.NewLogger(t), pb.NodeType_STORAGE, []pb.Node{{Id: fid2.ID, Address: &pb.NodeAddress{Address: lis.Addr().String()}}}, lis.Addr().String(), nil, fid, dir, defaultAlpha)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.NoError(t, k.Disconnect())
|
assert.NoError(t, k.Disconnect())
|
||||||
|
Loading…
Reference in New Issue
Block a user