Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/holepuncher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const b4a = require('b4a')
const safetyCatch = require('safety-catch')
const Nat = require('./nat')
const Sleeper = require('./sleeper')
const { FIREWALL } = require('./constants')
Expand Down Expand Up @@ -187,7 +188,7 @@ module.exports = class Holepuncher {

if (local === FIREWALL.CONSISTENT && remote === FIREWALL.CONSISTENT) {
this.dht.stats.punches.consistent++
this._consistentProbe()
this._consistentProbe().catch(safetyCatch)
return true
}

Expand All @@ -196,22 +197,21 @@ module.exports = class Holepuncher {
if (local === FIREWALL.CONSISTENT && remote >= FIREWALL.RANDOM) {
this.dht.stats.punches.random++
this._incrementRandomized()
this._randomProbes(remoteVerifiedAddress)
this._randomProbes(remoteVerifiedAddress).catch(safetyCatch)
return true
}

if (local >= FIREWALL.RANDOM && remote === FIREWALL.CONSISTENT) {
this.dht.stats.punches.random++
this._incrementRandomized()
await this._openBirthdaySockets(remoteVerifiedAddress)
if (this.punching) this._keepAliveRandomNat(remoteVerifiedAddress)
if (this.punching) this._keepAliveRandomNat(remoteVerifiedAddress).catch(safetyCatch)
return true
}

return false
}

// Note that this never throws so it is safe to run in the background
async _consistentProbe() {
// Here we do the sleep first because the "fast open" mode in the server just fired a ping
if (!this.isInitiator) await this._sleeper.pause(1000)
Expand All @@ -230,7 +230,6 @@ module.exports = class Holepuncher {
this._autoDestroy()
}

// Note that this never throws so it is safe to run in the background
async _randomProbes(remoteAddr) {
let tries = 1750 // ~35s

Expand All @@ -243,7 +242,6 @@ module.exports = class Holepuncher {
this._autoDestroy()
}

// Note that this never throws so it is safe to run in the background
async _keepAliveRandomNat(remoteAddr) {
let i = 0
let lowTTLRounds = 1
Expand Down
Loading