use random source port to work around 'address in use' error
This commit is contained in:
parent
56bfb253e5
commit
bf2fcc1602
|
@ -6,8 +6,6 @@ import asyncutils
|
||||||
import ../../message
|
import ../../message
|
||||||
import random
|
import random
|
||||||
|
|
||||||
const AcceptPort = Port(2000)
|
|
||||||
|
|
||||||
type
|
type
|
||||||
PunchdResponse = Future[tuple[msgContent: string, sock: AsyncSocket]]
|
PunchdResponse = Future[tuple[msgContent: string, sock: AsyncSocket]]
|
||||||
PunchdProgressCb = proc (future: PunchdResponse, msgContent: string) {.async.}
|
PunchdProgressCb = proc (future: PunchdResponse, msgContent: string) {.async.}
|
||||||
|
@ -214,11 +212,13 @@ proc runApp(serverHostname: string, serverPort: Port, peerId: string,
|
||||||
asyncCheck handlePunchdMessages(punchdConn)
|
asyncCheck handlePunchdMessages(punchdConn)
|
||||||
if otherPeerId.len == 0:
|
if otherPeerId.len == 0:
|
||||||
# register and wait for connections
|
# register and wait for connections
|
||||||
|
let acceptPort = rand(Port(1024) .. Port.high)
|
||||||
|
echo &"init server connection, probing port: {acceptPort}"
|
||||||
let serverConn = await initServerConnection(serverHostname, serverPort,
|
let serverConn = await initServerConnection(serverHostname, serverPort,
|
||||||
AcceptPort)
|
acceptPort)
|
||||||
asyncCheck handleServerMessages(serverConn)
|
asyncCheck handleServerMessages(serverConn)
|
||||||
asyncCheck handlePeerNotifications(serverConn, punchdConn, peerId)
|
asyncCheck handlePeerNotifications(serverConn, punchdConn, peerId)
|
||||||
let myPorts = (@[AcceptPort] & serverConn.probedPorts).join(",")
|
let myPorts = (@[acceptPort] & serverConn.probedPorts).join(",")
|
||||||
let req = &"{peerId}|{serverConn.probedIp}|{myPorts}"
|
let req = &"{peerId}|{serverConn.probedIp}|{myPorts}"
|
||||||
echo "registering: ", req
|
echo "registering: ", req
|
||||||
discard await serverConn.sendRequest("register", req)
|
discard await serverConn.sendRequest("register", req)
|
||||||
|
|
Loading…
Reference in New Issue