Autonat doesn't ask an incoming peer (#857)
This commit is contained in:
parent
f89bd0c77c
commit
444b837923
|
@ -152,6 +152,8 @@ method setup*(self: AutonatService, switch: Switch): Future[bool] {.async.} =
|
|||
if hasBeenSetup:
|
||||
if self.askNewConnectedPeers:
|
||||
self.newConnectedPeerHandler = proc (peerId: PeerId, event: PeerEvent): Future[void] {.async.} =
|
||||
if switch.connManager.selectConn(peerId, In) != nil: # no need to ask an incoming peer
|
||||
return
|
||||
discard askPeer(self, switch, peerId)
|
||||
await self.callHandler()
|
||||
switch.connManager.addPeerEventHandler(self.newConnectedPeerHandler, PeerEventKind.Joined)
|
||||
|
|
|
@ -320,3 +320,26 @@ suite "Autonat Service":
|
|||
|
||||
await allFuturesThrowing(
|
||||
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop(), switch5.stop())
|
||||
|
||||
asyncTest "Peer must not ask an incoming peer":
|
||||
let autonatService = AutonatService.new(AutonatClient.new(), newRng())
|
||||
|
||||
let switch1 = createSwitch(autonatService)
|
||||
let switch2 = createSwitch()
|
||||
|
||||
proc statusAndConfidenceHandler(networkReachability: NetworkReachability, confidence: Option[float]) {.gcsafe, async.} =
|
||||
fail()
|
||||
|
||||
check autonatService.networkReachability() == NetworkReachability.Unknown
|
||||
|
||||
autonatService.statusAndConfidenceHandler(statusAndConfidenceHandler)
|
||||
|
||||
await switch1.start()
|
||||
await switch2.start()
|
||||
|
||||
await switch2.connect(switch1.peerInfo.peerId, switch1.peerInfo.addrs)
|
||||
|
||||
await sleepAsync(500.milliseconds)
|
||||
|
||||
await allFuturesThrowing(
|
||||
switch1.stop(), switch2.stop())
|
||||
|
|
Loading…
Reference in New Issue