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
86b1e564
Unverified
Commit
86b1e564
authored
Aug 14, 2020
by
Petar Radovic
Committed by
GitHub
Aug 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Peer registry fix - multiple connections (#570)
* peer registry multiple connections case
parent
c1af7d40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
peer.go
pkg/p2p/libp2p/peer.go
+15
-10
No files found.
pkg/p2p/libp2p/peer.go
View file @
86b1e564
...
...
@@ -59,15 +59,17 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) {
return
}
overlay
:=
r
.
overlays
[
peerID
]
delete
(
r
.
overlays
,
peerID
)
delete
(
r
.
underlays
,
overlay
.
ByteString
())
// if there are multiple libp2p connections, consider the node disconnected only when the last connection is disconnected
delete
(
r
.
connections
[
peerID
],
c
)
if
len
(
r
.
connections
[
peerID
])
==
0
{
delete
(
r
.
connections
,
peerID
)
if
len
(
r
.
connections
[
peerID
])
>
0
{
r
.
mu
.
Unlock
()
return
}
delete
(
r
.
connections
,
peerID
)
overlay
:=
r
.
overlays
[
peerID
]
delete
(
r
.
overlays
,
peerID
)
delete
(
r
.
underlays
,
overlay
.
ByteString
())
for
_
,
cancel
:=
range
r
.
streams
[
peerID
]
{
cancel
()
}
...
...
@@ -131,14 +133,17 @@ func (r *peerRegistry) addIfNotExists(c network.Conn, overlay swarm.Address) (ex
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
if
_
,
exists
:=
r
.
underlays
[
overlay
.
ByteString
()];
exists
{
return
true
}
if
_
,
ok
:=
r
.
connections
[
peerID
];
!
ok
{
r
.
connections
[
peerID
]
=
make
(
map
[
network
.
Conn
]
struct
{})
}
// the connection is added even if the peer already exists in peer registry
// this is solving a case of multiple underlying libp2p connections for the same peer
r
.
connections
[
peerID
][
c
]
=
struct
{}{}
if
_
,
exists
:=
r
.
underlays
[
overlay
.
ByteString
()];
exists
{
return
true
}
r
.
streams
[
peerID
]
=
make
(
map
[
network
.
Stream
]
context
.
CancelFunc
)
r
.
underlays
[
overlay
.
ByteString
()]
=
peerID
r
.
overlays
[
peerID
]
=
overlay
...
...
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