use random source port for initiating connection too
This commit is contained in:
parent
bf2fcc1602
commit
53a9d0fc24
|
@ -178,6 +178,7 @@ proc initServerConnection(serverHostname: string, serverPort: Port,
|
|||
sock.bindAddr(probingPort)
|
||||
except OSError as e:
|
||||
if failCount == 3:
|
||||
echo "raising error"
|
||||
raise e
|
||||
failCount.inc
|
||||
await sleepAsync(100)
|
||||
|
@ -210,15 +211,15 @@ proc runApp(serverHostname: string, serverPort: Port, peerId: string,
|
|||
punchdConn.inConnections = newFutureStream[AsyncSocket]("runApp")
|
||||
await punchdConn.sock.connectUnix("/tmp/punchd.socket")
|
||||
asyncCheck handlePunchdMessages(punchdConn)
|
||||
let srcPort = rand(Port(1024) .. Port.high)
|
||||
if otherPeerId.len == 0:
|
||||
# register and wait for connections
|
||||
let acceptPort = rand(Port(1024) .. Port.high)
|
||||
echo &"init server connection, probing port: {acceptPort}"
|
||||
echo &"init server connection, probing port: {srcPort}"
|
||||
let serverConn = await initServerConnection(serverHostname, serverPort,
|
||||
acceptPort)
|
||||
srcPort)
|
||||
asyncCheck handleServerMessages(serverConn)
|
||||
asyncCheck handlePeerNotifications(serverConn, punchdConn, peerId)
|
||||
let myPorts = (@[acceptPort] & serverConn.probedPorts).join(",")
|
||||
let myPorts = (@[srcPort] & serverConn.probedPorts).join(",")
|
||||
let req = &"{peerId}|{serverConn.probedIp}|{myPorts}"
|
||||
echo "registering: ", req
|
||||
discard await serverConn.sendRequest("register", req)
|
||||
|
@ -234,7 +235,7 @@ proc runApp(serverHostname: string, serverPort: Port, peerId: string,
|
|||
else:
|
||||
# initiate a new connection
|
||||
var serverConn = await initServerConnection(serverHostname, serverPort,
|
||||
Port(1234))
|
||||
srcPort)
|
||||
asyncCheck handleServerMessages(serverConn)
|
||||
let sock = await punchHole(punchdConn, serverConn, peerId, otherPeerId)
|
||||
echo "connected!"
|
||||
|
|
Loading…
Reference in New Issue