Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
8020b87d
Unverified
Commit
8020b87d
authored
Apr 29, 2021
by
acud
Committed by
GitHub
Apr 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libp2p: improve cleanup on shutdown (#1622)
parent
dddfa6eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
9 deletions
+6
-9
connections_test.go
pkg/p2p/libp2p/connections_test.go
+1
-8
libp2p.go
pkg/p2p/libp2p/libp2p.go
+5
-1
No files found.
pkg/p2p/libp2p/connections_test.go
View file @
8020b87d
...
@@ -40,7 +40,6 @@ func TestConnectDisconnect(t *testing.T) {
...
@@ -40,7 +40,6 @@ func TestConnectDisconnect(t *testing.T) {
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -66,7 +65,6 @@ func TestDoubleConnect(t *testing.T) {
...
@@ -66,7 +65,6 @@ func TestDoubleConnect(t *testing.T) {
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -91,7 +89,6 @@ func TestDoubleDisconnect(t *testing.T) {
...
@@ -91,7 +89,6 @@ func TestDoubleDisconnect(t *testing.T) {
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -195,7 +192,6 @@ func TestDoubleConnectOnAllAddresses(t *testing.T) {
...
@@ -195,7 +192,6 @@ func TestDoubleConnectOnAllAddresses(t *testing.T) {
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
addrs
,
err
:=
s1
.
Addresses
()
addrs
,
err
:=
s1
.
Addresses
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -236,7 +232,6 @@ func TestDifferentNetworkIDs(t *testing.T) {
...
@@ -236,7 +232,6 @@ func TestDifferentNetworkIDs(t *testing.T) {
defer
cancel
()
defer
cancel
()
s1
,
_
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
_
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
_
:=
newService
(
t
,
2
,
libp2pServiceOpts
{})
s2
,
_
:=
newService
(
t
,
2
,
libp2pServiceOpts
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -286,6 +281,7 @@ func TestConnectRepeatHandshake(t *testing.T) {
...
@@ -286,6 +281,7 @@ func TestConnectRepeatHandshake(t *testing.T) {
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
_
,
err
:=
s2
.
Connect
(
ctx
,
addr
)
_
,
err
:=
s2
.
Connect
(
ctx
,
addr
)
...
@@ -321,7 +317,6 @@ func TestBlocklisting(t *testing.T) {
...
@@ -321,7 +317,6 @@ func TestBlocklisting(t *testing.T) {
addr1
:=
serviceUnderlayAddress
(
t
,
s1
)
addr1
:=
serviceUnderlayAddress
(
t
,
s1
)
addr2
:=
serviceUnderlayAddress
(
t
,
s2
)
addr2
:=
serviceUnderlayAddress
(
t
,
s2
)
// s2 connects to s1, thus the notifier on s1 should be called on Connect
_
,
err
:=
s2
.
Connect
(
context
.
Background
(),
addr1
)
_
,
err
:=
s2
.
Connect
(
context
.
Background
(),
addr1
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -337,7 +332,6 @@ func TestBlocklisting(t *testing.T) {
...
@@ -337,7 +332,6 @@ func TestBlocklisting(t *testing.T) {
expectPeers
(
t
,
s2
)
expectPeers
(
t
,
s2
)
expectPeersEventually
(
t
,
s1
)
expectPeersEventually
(
t
,
s1
)
// s2 connects to s1, thus the notifier on s1 should be called on Connect
_
,
err
=
s2
.
Connect
(
context
.
Background
(),
addr1
)
_
,
err
=
s2
.
Connect
(
context
.
Background
(),
addr1
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"expected error during connection, got nil"
)
t
.
Fatal
(
"expected error during connection, got nil"
)
...
@@ -346,7 +340,6 @@ func TestBlocklisting(t *testing.T) {
...
@@ -346,7 +340,6 @@ func TestBlocklisting(t *testing.T) {
expectPeers
(
t
,
s2
)
expectPeers
(
t
,
s2
)
expectPeersEventually
(
t
,
s1
)
expectPeersEventually
(
t
,
s1
)
// s2 connects to s1, thus the notifier on s1 should be called on Connect
_
,
err
=
s1
.
Connect
(
context
.
Background
(),
addr2
)
_
,
err
=
s1
.
Connect
(
context
.
Background
(),
addr2
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"expected error during connection, got nil"
)
t
.
Fatal
(
"expected error during connection, got nil"
)
...
...
pkg/p2p/libp2p/libp2p.go
View file @
8020b87d
...
@@ -545,7 +545,7 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.
...
@@ -545,7 +545,7 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.
}
}
if
blocked
{
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
()
_
=
handshakeStream
.
Reset
()
_
=
s
.
host
.
Network
()
.
ClosePeer
(
info
.
ID
)
_
=
s
.
host
.
Network
()
.
ClosePeer
(
info
.
ID
)
return
nil
,
fmt
.
Errorf
(
"peer blocklisted"
)
return
nil
,
fmt
.
Errorf
(
"peer blocklisted"
)
...
@@ -703,6 +703,10 @@ func (s *Service) Close() error {
...
@@ -703,6 +703,10 @@ func (s *Service) Close() error {
if
err
:=
s
.
libp2pPeerstore
.
Close
();
err
!=
nil
{
if
err
:=
s
.
libp2pPeerstore
.
Close
();
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
s
.
natManager
.
Close
();
err
!=
nil
{
return
err
}
return
s
.
host
.
Close
()
return
s
.
host
.
Close
()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment