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
40208306
Commit
40208306
authored
Feb 25, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fire a listen close event when closing the listener
fixes
https://github.com/libp2p/go-libp2p-swarm/issues/163
parent
31bfe5bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
19 deletions
+28
-19
go.sum
go.sum
+5
-15
swarm_listen.go
swarm_listen.go
+6
-1
swarm_notif_test.go
swarm_notif_test.go
+17
-3
No files found.
go.sum
View file @
40208306
...
...
@@ -28,7 +28,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew
v1.1.0/go.mod h1:
J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew
v1.1.1 h1:
vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew
v1.1.1/go.mod h1:
J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/badger
v1.6.0-rc1/go.mod h1:
zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
github.com/dgraph-io/badger
v1.6.0/go.mod h1:
zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
github.com/dgryski/go-farm
v0.0.0-20190423205320-6a90982ecee2/go.mod h1:
SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize
v1.0.0/go.mod h1:
HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
...
...
@@ -41,6 +40,7 @@ github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP
github.com/gogo/protobuf
v1.3.1 h1:
DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf
v1.3.1/go.mod h1:
SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/glog
v0.0.0-20160126235308-23def4e6c14b/go.mod h1:
SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache
v0.0.0-20190702054246-869f871628b6 h1:
ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I=
github.com/golang/groupcache
v0.0.0-20190702054246-869f871628b6/go.mod h1:
cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock
v1.1.1/go.mod h1:
oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf
v1.2.0/go.mod h1:
6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
...
...
@@ -49,6 +49,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/snappy
v0.0.0-20180518054509-2e65f85255db/go.mod h1:
/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp
v0.2.0 h1:
+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp
v0.2.0/go.mod h1:
oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp
v0.3.0 h1:
crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp
v0.3.0/go.mod h1:
8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/uuid
v1.1.1 h1:
Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid
v1.1.1/go.mod h1:
TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
...
...
@@ -64,12 +65,9 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/ipfs/go-cid
v0.0.1/go.mod h1:
GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid
v0.0.2/go.mod h1:
GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid
v0.0.3/go.mod h1:
GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-datastore
v0.0.1/go.mod h1:
d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore
v0.1.0/go.mod h1:
d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore
v0.1.1/go.mod h1:
w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw=
github.com/ipfs/go-ds-badger
v0.0.5/go.mod h1:
g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaHzfGTzuE3s=
github.com/ipfs/go-ds-badger
v0.0.7/go.mod h1:
qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk=
github.com/ipfs/go-ds-leveldb
v0.0.1/go.mod h1:
feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc=
github.com/ipfs/go-ds-leveldb
v0.1.0/go.mod h1:
hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8=
github.com/ipfs/go-ipfs-delay
v0.0.0-20181109222059-70721b86a9a8/go.mod h1:
8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-log
v0.0.1 h1:
9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc=
...
...
@@ -103,10 +101,10 @@ github.com/libp2p/go-conn-security-multistream v0.1.0 h1:aqGmto+ttL/uJgX0JtQI0tD
github.com/libp2p/go-conn-security-multistream
v0.1.0/go.mod h1:
aw6eD7LOsHEX7+2hJkDxw1MteijaVcI+/eP2/x3J1xc=
github.com/libp2p/go-flow-metrics
v0.0.1 h1:
0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s=
github.com/libp2p/go-flow-metrics
v0.0.1/go.mod h1:
Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8=
github.com/libp2p/go-flow-metrics
v0.0.2 h1:
U5TvqfoyR6GVRM+bC15Ux1ltar1kbj6Zw6xOVR02CZs=
github.com/libp2p/go-flow-metrics
v0.0.2/go.mod h1:
HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
github.com/libp2p/go-libp2p-core
v0.0.1 h1:
HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I=
github.com/libp2p/go-libp2p-core
v0.0.1/go.mod h1:
g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco=
github.com/libp2p/go-libp2p-core
v0.0.4/go.mod h1:
jyuCQP356gzfCFtRKyvAbNkyeuxb7OlyhWZ3nls5d2I=
github.com/libp2p/go-libp2p-core
v0.2.0 h1:
ycFtuNwtZBAJSxzaHbyv6NjG3Yj5Nmra1csHaQ3zwaw=
github.com/libp2p/go-libp2p-core
v0.2.0/go.mod h1:
X0eyB0Gy93v0DZtSYbEM7RnMChm9Uv3j7yRXjO77xSI=
github.com/libp2p/go-libp2p-core
v0.2.2 h1:
Sv1ggdoMx9c7v7FOFkR7agraHCnAgqYsXrU1ARSRUMs=
...
...
@@ -120,12 +118,8 @@ github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3x
github.com/libp2p/go-libp2p-mplex
v0.2.0/go.mod h1:
Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo=
github.com/libp2p/go-libp2p-mplex
v0.2.1 h1:
E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8iGvirYI=
github.com/libp2p/go-libp2p-mplex
v0.2.1/go.mod h1:
SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE=
github.com/libp2p/go-libp2p-peerstore
v0.1.3 h1:
wMgajt1uM2tMiqf4M+4qWKVyyFc8SfA+84VV9glZq1M=
github.com/libp2p/go-libp2p-peerstore
v0.1.3/go.mod h1:
BJ9sHlm59/80oSkpWgr1MyY1ciXAXV397W6h1GH/uKI=
github.com/libp2p/go-libp2p-peerstore
v0.1.4 h1:
d23fvq5oYMJ/lkkbO4oTwBp/JP+I/1m5gZJobNXCE/k=
github.com/libp2p/go-libp2p-peerstore
v0.1.4/go.mod h1:
+4BDbDiiKf4PzpANZDAT+knVdLxvqh7hXOujessqdzs=
github.com/libp2p/go-libp2p-secio
v0.2.0 h1:
ywzZBsWEEz2KNTn5RtzauEDq5RFEefPsttXYwAWqHng=
github.com/libp2p/go-libp2p-secio
v0.2.0/go.mod h1:
2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g=
github.com/libp2p/go-libp2p-secio
v0.2.1 h1:
eNWbJTdyPA7NxhP7J3c5lT97DC5d+u+IldkgCYFTPVA=
github.com/libp2p/go-libp2p-secio
v0.2.1/go.mod h1:
cWtZpILJqkqrSkiYcDBh5lA3wbT2Q+hz3rJQq3iftD8=
github.com/libp2p/go-libp2p-testing
v0.0.2/go.mod h1:
gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E=
...
...
@@ -137,8 +131,6 @@ github.com/libp2p/go-libp2p-testing v0.1.1 h1:U03z3HnGI7Ni8Xx6ONVZvUFOAzWYmolWf5
github.com/libp2p/go-libp2p-testing
v0.1.1/go.mod h1:
xaZWMJrPUM5GlDBxCeGUi7kI4eqnjVyavGroI2nxEM0=
github.com/libp2p/go-libp2p-transport-upgrader
v0.1.1 h1:
PZMS9lhjK9VytzMCW3tWHAXtKXmlURSc3ZdvwEcKCzw=
github.com/libp2p/go-libp2p-transport-upgrader
v0.1.1/go.mod h1:
IEtA6or8JUbsV07qPW4r01GnTenLW4oi3lOPbUMGJJA=
github.com/libp2p/go-libp2p-yamux
v0.2.0 h1:
TSPZ5cMMz/wdoYsye/wU1TE4G3LDGMoeEN0xgnCKU/I=
github.com/libp2p/go-libp2p-yamux
v0.2.0/go.mod h1:
Db2gU+XfLpm6E4rG5uGCFX6uXA8MEXOxFcRoXUODaK8=
github.com/libp2p/go-libp2p-yamux
v0.2.1 h1:
Q3XYNiKCC2vIxrvUJL+Jg1kiyeEaIDNKLjgEjo3VQdI=
github.com/libp2p/go-libp2p-yamux
v0.2.1/go.mod h1:
1FBXiHDk1VyRM1C0aez2bCfHQ4vMZKkAQzZbkSQt5fI=
github.com/libp2p/go-maddr-filter
v0.0.4 h1:
hx8HIuuwk34KePddrp2mM5ivgPkZ09JH4AvsALRbFUs=
...
...
@@ -163,8 +155,6 @@ github.com/libp2p/go-stream-muxer-multistream v0.2.0 h1:714bRJ4Zy9mdhyTLJ+ZKiROm
github.com/libp2p/go-stream-muxer-multistream
v0.2.0/go.mod h1:
j9eyPol/LLRqT+GPLSxvimPhNph4sfYfMoDPd7HkzIc=
github.com/libp2p/go-tcp-transport
v0.1.1 h1:
yGlqURmqgNA2fvzjSgZNlHcsd/IulAnKM8Ncu+vlqnw=
github.com/libp2p/go-tcp-transport
v0.1.1/go.mod h1:
3HzGvLbx6etZjnFlERyakbaYPdfjg2pWP97dFZworkY=
github.com/libp2p/go-yamux
v1.2.2 h1:
s6J6o7+ajoQMjHe7BEnq+EynOj5D2EoG8CuQgL3F2vg=
github.com/libp2p/go-yamux
v1.2.2/go.mod h1:
FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow=
github.com/libp2p/go-yamux
v1.2.3 h1:
xX8A36vpXb59frIzWFdEgptLMsOANMFq2K7fPRlunYI=
github.com/libp2p/go-yamux
v1.2.3/go.mod h1:
FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow=
github.com/magiconair/properties
v1.8.0/go.mod h1:
PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
...
...
@@ -201,8 +191,6 @@ github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lg
github.com/multiformats/go-multiaddr
v0.1.0/go.mod h1:
xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
github.com/multiformats/go-multiaddr
v0.1.1 h1:
rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE=
github.com/multiformats/go-multiaddr
v0.1.1/go.mod h1:
aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo=
github.com/multiformats/go-multiaddr
v0.1.2 h1:
HWYHNSyyllbQopmVIF5K7JKJugiah+L9/kuZKHbmNdQ=
github.com/multiformats/go-multiaddr
v0.1.2/go.mod h1:
0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4=
github.com/multiformats/go-multiaddr
v0.2.0 h1:
lR52sFwcTCuQb6bTfnXF6zA2XfyYvyd+5a9qECv/J90=
github.com/multiformats/go-multiaddr
v0.2.0/go.mod h1:
0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4=
github.com/multiformats/go-multiaddr-dns
v0.0.1/go.mod h1:
9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
...
...
@@ -273,6 +261,7 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7V
github.com/xordataexchange/crypt
v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:
aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.opencensus.io
v0.21.0 h1:
mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg=
go.opencensus.io
v0.21.0/go.mod h1:
mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io
v0.22.1 h1:
8dP3SGL7MPB94crU3bEPplMPe83FI4EouesJUeFHv50=
go.opencensus.io
v0.22.1/go.mod h1:
Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA=
golang.org/x/crypto
v0.0.0-20170930174604-9419663f5a44/go.mod h1:
6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto
v0.0.0-20180904163835-0709b304e793/go.mod h1:
6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
...
...
@@ -320,6 +309,7 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSF
golang.org/x/sys
v0.0.0-20190626221950-04f50cda93cb/go.mod h1:
h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text
v0.3.0 h1:
g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text
v0.3.0/go.mod h1:
NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text
v0.3.2 h1:
tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text
v0.3.2/go.mod h1:
bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools
v0.0.0-20180221164845-07fd8470d635/go.mod h1:
n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools
v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:
n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
...
...
swarm_listen.go
View file @
40208306
...
...
@@ -61,7 +61,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
maddr
:=
list
.
Multiaddr
()
// signal to our notifiees on
successful con
n.
// signal to our notifiees on
liste
n.
s
.
notifyAll
(
func
(
n
network
.
Notifiee
)
{
n
.
Listen
(
s
,
maddr
)
})
...
...
@@ -73,6 +73,11 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
delete
(
s
.
listeners
.
m
,
list
)
s
.
listeners
.
cacheEOL
=
time
.
Time
{}
s
.
listeners
.
Unlock
()
// signal to our notifiees on listen close.
s
.
notifyAll
(
func
(
n
network
.
Notifiee
)
{
n
.
ListenClose
(
s
,
maddr
)
})
s
.
refs
.
Done
()
}()
for
{
...
...
swarm_notif_test.go
View file @
40208306
...
...
@@ -16,18 +16,32 @@ import (
func
TestNotifications
(
t
*
testing
.
T
)
{
const
swarmSize
=
5
notifiees
:=
make
([]
*
netNotifiee
,
swarmSize
)
ctx
:=
context
.
Background
()
swarms
:=
makeSwarms
(
ctx
,
t
,
swarmSize
)
defer
func
()
{
for
_
,
s
:=
range
swarms
{
s
.
Close
()
for
i
,
s
:=
range
swarms
{
select
{
case
<-
notifiees
[
i
]
.
listenClose
:
t
.
Error
(
"should not have been closed"
)
default
:
}
err
:=
s
.
Close
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
select
{
case
<-
notifiees
[
i
]
.
listenClose
:
default
:
t
.
Error
(
"expected a listen close notification"
)
}
}
}()
timeout
:=
5
*
time
.
Second
// signup notifs
notifiees
:=
make
([]
*
netNotifiee
,
len
(
swarms
))
for
i
,
swarm
:=
range
swarms
{
n
:=
newNetNotifiee
(
swarmSize
)
swarm
.
Notify
(
n
)
...
...
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