mirror of https://github.com/vacp2p/nim-libp2p.git
Track all connections (#175)
* adding to do for future refactor * no mix conn and transport stopping or it will race * don't use intermediary vars
This commit is contained in:
parent
1819502fb5
commit
5583168965
|
@ -335,16 +335,16 @@ proc stop*(s: Switch) {.async.} =
|
||||||
# we want to report erros but we do not want to fail
|
# we want to report erros but we do not want to fail
|
||||||
# or crash here, cos we need to clean possibly MANY items
|
# or crash here, cos we need to clean possibly MANY items
|
||||||
# and any following conn/transport won't be cleaned up
|
# and any following conn/transport won't be cleaned up
|
||||||
var futs = newSeq[Future[void]]()
|
|
||||||
|
|
||||||
if s.pubSub.isSome:
|
if s.pubSub.isSome:
|
||||||
futs &= s.pubSub.get().stop()
|
await s.pubSub.get().stop()
|
||||||
|
|
||||||
futs &= toSeq(s.connections.values).mapIt(s.cleanupConn(it))
|
checkFutures(
|
||||||
futs &= s.transports.mapIt(it.close())
|
await allFinished(
|
||||||
|
toSeq(s.connections.values).mapIt(s.cleanupConn(it))))
|
||||||
|
|
||||||
futs = await allFinished(futs)
|
checkFutures(
|
||||||
checkFutures(futs)
|
await allFinished(
|
||||||
|
s.transports.mapIt(it.close())))
|
||||||
|
|
||||||
trace "switch stopped"
|
trace "switch stopped"
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ proc connHandler*(t: TcpTransport,
|
||||||
if not isNil(t.handler):
|
if not isNil(t.handler):
|
||||||
t.handlers &= t.handler(conn)
|
t.handlers &= t.handler(conn)
|
||||||
|
|
||||||
|
# TODO: store the streamtransport client here
|
||||||
t.connections.add(conn)
|
t.connections.add(conn)
|
||||||
t.cleanups &= t.cleanup(conn)
|
t.cleanups &= t.cleanup(conn)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue