From 97714d150f0bce2cf4c231165488f6a3edba8ac8 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Wed, 30 Jan 2019 22:57:13 +0200 Subject: [PATCH] Remove unused kademlia.Disconnect method (#1178) --- pkg/dht/dht.go | 1 - pkg/kademlia/kademlia.go | 12 ------------ pkg/kademlia/kademlia_test.go | 12 ++++-------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/pkg/dht/dht.go b/pkg/dht/dht.go index f4cb7ea07..b428d6093 100644 --- a/pkg/dht/dht.go +++ b/pkg/dht/dht.go @@ -19,7 +19,6 @@ type DHT interface { Bootstrap(ctx context.Context) error Ping(ctx context.Context, node pb.Node) (pb.Node, error) FindNode(ctx context.Context, ID storj.NodeID) (pb.Node, error) - Disconnect() error Seen() []*pb.Node } diff --git a/pkg/kademlia/kademlia.go b/pkg/kademlia/kademlia.go index 73dbbab2f..75631e50b 100644 --- a/pkg/kademlia/kademlia.go +++ b/pkg/kademlia/kademlia.go @@ -76,18 +76,6 @@ func (k *Kademlia) Close() error { return dialerErr } -// Disconnect safely closes connections to the Kademlia network -func (k *Kademlia) Disconnect() error { - dialerErr := k.dialer.Close() - k.lookups.Close() - k.lookups.Wait() - - return errs.Combine( - dialerErr, - k.routingTable.Close(), - ) -} - // FindNear returns all nodes from a starting node up to a maximum limit // stored in the local routing table limiting the result by the specified restrictions func (k *Kademlia) FindNear(ctx context.Context, start storj.NodeID, limit int, restrictions ...pb.Restriction) ([]*pb.Node, error) { diff --git a/pkg/kademlia/kademlia_test.go b/pkg/kademlia/kademlia_test.go index 6a2e225d9..a98ab8024 100644 --- a/pkg/kademlia/kademlia_test.go +++ b/pkg/kademlia/kademlia_test.go @@ -78,7 +78,7 @@ func TestNewKademlia(t *testing.T) { assert.Equal(t, kad.bootstrapNodes, v.bn) assert.NotNil(t, kad.dialer) assert.NotNil(t, kad.routingTable) - assert.NoError(t, kad.Disconnect()) + assert.NoError(t, kad.Close()) } } @@ -109,9 +109,7 @@ func TestPeerDiscovery(t *testing.T) { assert.Equal(t, rt.Local().Metadata.Email, "foo@bar.com") assert.Equal(t, rt.Local().Metadata.Wallet, "OperatorWallet") - defer func() { - assert.NoError(t, k.Disconnect()) - }() + defer ctx.Check(k.Close) cases := []struct { target storj.NodeID @@ -190,7 +188,7 @@ func testNode(t *testing.T, bn []pb.Node) (*Kademlia, *grpc.Server, func()) { return k, grpcServer, func() { defer cleanup() - assert.NoError(t, k.Disconnect()) + assert.NoError(t, k.Close()) } } @@ -252,9 +250,7 @@ func TestFindNear(t *testing.T) { defer cleanup() 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) - defer func() { - assert.NoError(t, k.Disconnect()) - }() + defer ctx.Check(k.Close) // add nodes ids := storj.NodeIDList{nodeIDA, nodeIDB, nodeIDC, nodeIDD}