source port may take a bit to become available again, so retry binding three times
This commit is contained in:
parent
d1b104c666
commit
7f40ab0082
|
@ -166,10 +166,18 @@ proc punchHole(punchdConn: PunchdConnection, serverConn: ServerConnection,
|
|||
|
||||
proc initServerConnection(serverHostname: string, serverPort: Port,
|
||||
probingPort: Port): Future[ServerConnection] {.async.} =
|
||||
for i in 0 .. 1:
|
||||
var failCount = 0
|
||||
while result.probedPorts.len < 2:
|
||||
# FIXME: error handling
|
||||
let sock = newAsyncSocket()
|
||||
sock.bindAddr(probingPort)
|
||||
try:
|
||||
sock.bindAddr(probingPort)
|
||||
except OSError as e:
|
||||
if failCount == 3:
|
||||
raise e
|
||||
failCount.inc
|
||||
await sleepAsync(1000)
|
||||
continue
|
||||
await sock.connect(serverHostname, serverPort)
|
||||
let id = rand(uint32)
|
||||
await sock.send(&"get-endpoint|{id}\n")
|
||||
|
|
Loading…
Reference in New Issue