Browse Source

do a fast holepunch attempt if no reply has come in 500ms

v4
Mathias Buus 5 years ago
parent
commit
df284d86d9
  1. 13
      lib/io.js

13
lib/io.js

@ -133,6 +133,7 @@ class IO {
_finish (rid, err, val, peer) {
const req = this._requests[rid]
if (!req) return
if (req.holepunch) clearTimeout(req.holepunch)
this._requests[rid] = undefined
const top = this.inflight[this.inflight.length - 1]
@ -180,7 +181,13 @@ class IO {
buffer,
peer,
timeout: this._ticking ? 5 : 4, // if ticking this will be decremented after this fun call
tries: 0
tries: 0,
holepunch: null
}
if (req.peer.referrer && !req.peer.fastHolepunch) {
req.peer.fastHolepunch = true
req.holepunch = setTimeout(holepunchNT, 500, this, req)
}
this._requests[rid] = req
@ -324,6 +331,10 @@ module.exports = IO
function noop () {}
function holepunchNT (io, req) {
io._holepunch(req)
}
function decodeMessage (buf) {
try {
return Message.decode(buf)

Loading…
Cancel
Save