mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-27 21:09:28 +00:00
Close peer event handler
This commit is contained in:
parent
ede9bb1bfe
commit
3362e1a343
@ -297,7 +297,7 @@ proc holePunchIfRelayed*(
|
||||
except DcutrError as err:
|
||||
debug "Hole punching failed during dcutr", description = err.msg
|
||||
|
||||
proc setupHolePunching*(switch: Switch) =
|
||||
proc setupHolePunching*(switch: Switch): PeerEventHandler =
|
||||
try:
|
||||
switch.mount(Dcutr.new(switch))
|
||||
except LPError as err:
|
||||
@ -308,3 +308,4 @@ proc setupHolePunching*(switch: Switch) =
|
||||
) {.async: (raises: [CancelledError]).} =
|
||||
await holePunchIfRelayed(switch, peerId)
|
||||
switch.addPeerEventHandler(handler, PeerEventKind.Joined)
|
||||
handler
|
||||
|
||||
@ -17,6 +17,7 @@ import pkg/chronos
|
||||
import pkg/taskpools
|
||||
import pkg/presto
|
||||
import pkg/libp2p
|
||||
import pkg/libp2p/connmanager
|
||||
import pkg/libp2p/protocols/connectivity/autonatv2/[service, client]
|
||||
import pkg/libp2p/protocols/connectivity/relay/client as relayClientModule
|
||||
import pkg/libp2p/protocols/connectivity/relay/relay as relayModule
|
||||
@ -60,6 +61,7 @@ type
|
||||
autoRelayService*: Option[AutoRelayService]
|
||||
natMapper*: Option[NatPortMapper]
|
||||
natRouter*: Option[NatRouter]
|
||||
holePunchHandler: Option[connmanager.PeerEventHandler]
|
||||
isStarted: bool
|
||||
|
||||
StoragePrivateKey* = libp2p.PrivateKey # alias
|
||||
@ -142,6 +144,11 @@ proc stop*(s: StorageServer) {.async.} =
|
||||
if s.natMapper.isSome:
|
||||
s.natMapper.get.close()
|
||||
|
||||
if s.holePunchHandler.isSome:
|
||||
s.storageNode.switch.removePeerEventHandler(
|
||||
s.holePunchHandler.get, PeerEventKind.Joined
|
||||
)
|
||||
|
||||
var futures = @[
|
||||
s.storageNode.switch.stop(),
|
||||
s.storageNode.stop(),
|
||||
@ -412,6 +419,7 @@ proc new*(
|
||||
# NAT services
|
||||
var natMapper: Option[NatPortMapper]
|
||||
var autoRelayService: Option[AutoRelayService]
|
||||
var holePunchHandler: Option[connmanager.PeerEventHandler]
|
||||
|
||||
if autonatService.isSome:
|
||||
let relayService = AutoRelayService.new(
|
||||
@ -453,7 +461,7 @@ proc new*(
|
||||
)
|
||||
)
|
||||
|
||||
setupHolePunching(switch)
|
||||
holePunchHandler = some(setupHolePunching(switch))
|
||||
|
||||
# REST server
|
||||
var restServer: RestServerRef = nil
|
||||
@ -483,4 +491,5 @@ proc new*(
|
||||
autoRelayService: autoRelayService,
|
||||
natMapper: natMapper,
|
||||
natRouter: natRouter,
|
||||
holePunchHandler: holePunchHandler,
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user