Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
395fb26a
Commit
395fb26a
authored
Jan 08, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comment on why we lock when handling (dis)connect notifs
parent
64b46c1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
notif.go
notif.go
+8
-1
No files found.
notif.go
View file @
395fb26a
...
...
@@ -26,6 +26,9 @@ func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) {
p
:=
v
.
RemotePeer
()
protos
,
err
:=
dht
.
peerstore
.
SupportsProtocols
(
p
,
dhtProtocols
...
)
if
err
==
nil
&&
len
(
protos
)
!=
0
{
// We lock here for consistency with the lock in testConnection.
// This probably isn't necessary because (dis)connect
// notifications are serialized but it's nice to be consistent.
dht
.
plk
.
Lock
()
defer
dht
.
plk
.
Unlock
()
if
dht
.
host
.
Network
()
.
Connectedness
(
p
)
==
inet
.
Connected
{
...
...
@@ -62,9 +65,11 @@ func (nn *netNotifiee) testConnection(v inet.Conn) {
// Remember this choice (makes subsequent negotiations faster)
dht
.
peerstore
.
AddProtocols
(
p
,
selected
)
// We lock here as we race with disconnect. If we didn't lock, we could
// finish processing a connect after handling the associated disconnect
// event and add the peer to the routing table after removing it.
dht
.
plk
.
Lock
()
defer
dht
.
plk
.
Unlock
()
// Make sure we're still connected under the lock (race with disconnect)
if
dht
.
host
.
Network
()
.
Connectedness
(
p
)
==
inet
.
Connected
{
dht
.
Update
(
dht
.
Context
(),
p
)
}
...
...
@@ -80,6 +85,8 @@ func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) {
p
:=
v
.
RemotePeer
()
// Lock and check to see if we're still connected. We lock to make sure
// we don't concurrently process a connect event.
dht
.
plk
.
Lock
()
defer
dht
.
plk
.
Unlock
()
if
dht
.
host
.
Network
()
.
Connectedness
(
p
)
==
inet
.
Connected
{
...
...
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