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-swarm
Commits
4efc54f5
Commit
4efc54f5
authored
Feb 19, 2019
by
Matt Joiner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Do notifications synchronously"
This reverts commit
3dded3dc
.
parent
e647659b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
swarm.go
swarm.go
+13
-1
swarm_conn.go
swarm_conn.go
+11
-4
No files found.
swarm.go
View file @
4efc54f5
...
@@ -208,6 +208,9 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
...
@@ -208,6 +208,9 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
// * The other will be decremented when Conn.start exits.
// * The other will be decremented when Conn.start exits.
s
.
refs
.
Add
(
2
)
s
.
refs
.
Add
(
2
)
// Take the notification lock before releasing the conns lock to block
// Disconnect notifications until after the Connect notifications done.
c
.
notifyLk
.
Lock
()
s
.
conns
.
Unlock
()
s
.
conns
.
Unlock
()
// We have a connection now. Cancel all other in-progress dials.
// We have a connection now. Cancel all other in-progress dials.
...
@@ -217,6 +220,7 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
...
@@ -217,6 +220,7 @@ func (s *Swarm) addConn(tc transport.Conn, dir inet.Direction) (*Conn, error) {
s
.
notifyAll
(
func
(
f
inet
.
Notifiee
)
{
s
.
notifyAll
(
func
(
f
inet
.
Notifiee
)
{
f
.
Connected
(
s
,
c
)
f
.
Connected
(
s
,
c
)
})
})
c
.
notifyLk
.
Unlock
()
c
.
start
()
c
.
start
()
...
@@ -434,10 +438,18 @@ func (s *Swarm) Backoff() *DialBackoff {
...
@@ -434,10 +438,18 @@ func (s *Swarm) Backoff() *DialBackoff {
// notifyAll sends a signal to all Notifiees
// notifyAll sends a signal to all Notifiees
func
(
s
*
Swarm
)
notifyAll
(
notify
func
(
inet
.
Notifiee
))
{
func
(
s
*
Swarm
)
notifyAll
(
notify
func
(
inet
.
Notifiee
))
{
var
wg
sync
.
WaitGroup
s
.
notifs
.
RLock
()
s
.
notifs
.
RLock
()
wg
.
Add
(
len
(
s
.
notifs
.
m
))
for
f
:=
range
s
.
notifs
.
m
{
for
f
:=
range
s
.
notifs
.
m
{
go
func
(
f
inet
.
Notifiee
)
{
defer
wg
.
Done
()
notify
(
f
)
notify
(
f
)
}(
f
)
}
}
wg
.
Wait
()
s
.
notifs
.
RUnlock
()
s
.
notifs
.
RUnlock
()
}
}
...
...
swarm_conn.go
View file @
4efc54f5
...
@@ -65,10 +65,17 @@ func (c *Conn) doClose() {
...
@@ -65,10 +65,17 @@ func (c *Conn) doClose() {
s
.
Reset
()
s
.
Reset
()
}
}
// do this in a goroutine to avoid deadlocking if we call close in an open notification.
go
func
()
{
// prevents us from issuing close notifications before finishing the open notifications
c
.
notifyLk
.
Lock
()
defer
c
.
notifyLk
.
Unlock
()
c
.
swarm
.
notifyAll
(
func
(
f
inet
.
Notifiee
)
{
c
.
swarm
.
notifyAll
(
func
(
f
inet
.
Notifiee
)
{
f
.
Disconnected
(
c
.
swarm
,
c
)
f
.
Disconnected
(
c
.
swarm
,
c
)
})
})
c
.
swarm
.
refs
.
Done
()
// taken in Swarm.addConn
c
.
swarm
.
refs
.
Done
()
// taken in Swarm.addConn
}()
}
}
func
(
c
*
Conn
)
removeStream
(
s
*
Stream
)
{
func
(
c
*
Conn
)
removeStream
(
s
*
Stream
)
{
...
...
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