hyperswarm
Advanced tools
Comparing version 4.7.0 to 4.7.1
20
index.js
@@ -77,5 +77,5 @@ const { EventEmitter } = require('events') | ||
_maybeRelayConnection () { | ||
_maybeRelayConnection (force) { | ||
if (!this.relayThrough) return null | ||
return this.relayThrough() | ||
return this.relayThrough(force) | ||
} | ||
@@ -161,3 +161,3 @@ | ||
const relayThrough = this._maybeRelayConnection() | ||
const relayThrough = this._maybeRelayConnection(peerInfo.forceRelaying) | ||
const conn = this.dht.connect(peerInfo.publicKey, { | ||
@@ -190,3 +190,9 @@ relayAddresses: peerInfo.relayAddresses, | ||
}) | ||
conn.on('error', noop) | ||
conn.on('error', err => { | ||
if (this.relayThrough && shouldForceRelaying(err.code)) { | ||
peerInfo.forceRelaying = true | ||
// Reset the attempts in order to fast connect to relay | ||
peerInfo.attempts = 0 | ||
} | ||
}) | ||
conn.on('open', () => { | ||
@@ -505,1 +511,7 @@ opened = true | ||
} | ||
function shouldForceRelaying (code) { | ||
return (code === 'HOLEPUNCH_ABORTED') || | ||
(code === 'HOLEPUNCH_DOUBLE_RANDOMIZED_NATS') || | ||
(code === 'REMOTE_NOT_HOLEPUNCHABLE') | ||
} |
@@ -23,2 +23,3 @@ const { EventEmitter } = require('events') | ||
this.waiting = false | ||
this.forceRelaying = false | ||
@@ -25,0 +26,0 @@ // Set by the Swarm |
{ | ||
"name": "hyperswarm", | ||
"version": "4.7.0", | ||
"version": "4.7.1", | ||
"description": "A distributed networking stack for connecting peers", | ||
@@ -5,0 +5,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36567
822