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

libp2p: improve cleanup on shutdown #1622

Merged
merged 5 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions pkg/p2p/libp2p/connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestConnectDisconnect(t *testing.T) {
defer cancel()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{})

s2, overlay2 := newService(t, 1, libp2pServiceOpts{})

addr := serviceUnderlayAddress(t, s1)
Expand All @@ -66,7 +65,6 @@ func TestDoubleConnect(t *testing.T) {
defer cancel()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{})

s2, overlay2 := newService(t, 1, libp2pServiceOpts{})

addr := serviceUnderlayAddress(t, s1)
Expand All @@ -91,7 +89,6 @@ func TestDoubleDisconnect(t *testing.T) {
defer cancel()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{})

s2, overlay2 := newService(t, 1, libp2pServiceOpts{})

addr := serviceUnderlayAddress(t, s1)
Expand Down Expand Up @@ -195,7 +192,6 @@ func TestDoubleConnectOnAllAddresses(t *testing.T) {
defer cancel()

s1, overlay1 := newService(t, 1, libp2pServiceOpts{})

addrs, err := s1.Addresses()
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -236,7 +232,6 @@ func TestDifferentNetworkIDs(t *testing.T) {
defer cancel()

s1, _ := newService(t, 1, libp2pServiceOpts{})

s2, _ := newService(t, 2, libp2pServiceOpts{})

addr := serviceUnderlayAddress(t, s1)
Expand Down Expand Up @@ -286,6 +281,7 @@ func TestConnectRepeatHandshake(t *testing.T) {

s1, overlay1 := newService(t, 1, libp2pServiceOpts{})
s2, overlay2 := newService(t, 1, libp2pServiceOpts{})

addr := serviceUnderlayAddress(t, s1)

_, err := s2.Connect(ctx, addr)
Expand Down Expand Up @@ -321,7 +317,6 @@ func TestBlocklisting(t *testing.T) {
addr1 := serviceUnderlayAddress(t, s1)
addr2 := serviceUnderlayAddress(t, s2)

// s2 connects to s1, thus the notifier on s1 should be called on Connect
_, err := s2.Connect(context.Background(), addr1)
if err != nil {
t.Fatal(err)
Expand All @@ -337,7 +332,6 @@ func TestBlocklisting(t *testing.T) {
expectPeers(t, s2)
expectPeersEventually(t, s1)

// s2 connects to s1, thus the notifier on s1 should be called on Connect
_, err = s2.Connect(context.Background(), addr1)
if err == nil {
t.Fatal("expected error during connection, got nil")
Expand All @@ -346,7 +340,6 @@ func TestBlocklisting(t *testing.T) {
expectPeers(t, s2)
expectPeersEventually(t, s1)

// s2 connects to s1, thus the notifier on s1 should be called on Connect
_, err = s1.Connect(context.Background(), addr2)
if err == nil {
t.Fatal("expected error during connection, got nil")
Expand Down
6 changes: 5 additions & 1 deletion pkg/p2p/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.
}

if blocked {
s.logger.Errorf("blocked connection from blocklisted peer %s", info.ID)
s.logger.Errorf("blocked connection to blocklisted peer %s", info.ID)
_ = handshakeStream.Reset()
_ = s.host.Network().ClosePeer(info.ID)
return nil, fmt.Errorf("peer blocklisted")
Expand Down Expand Up @@ -703,6 +703,10 @@ func (s *Service) Close() error {
if err := s.libp2pPeerstore.Close(); err != nil {
return err
}
if err := s.natManager.Close(); err != nil {
return err
}

return s.host.Close()
}

Expand Down