|
|
@ -4,6 +4,7 @@ const peers = require('ipv4-peers') |
|
|
|
const sodium = require('sodium-universal') |
|
|
|
const speedometer = require('speedometer') |
|
|
|
|
|
|
|
const VERSION = 1 |
|
|
|
const QUERY = Symbol('QUERY') |
|
|
|
const UPDATE = Symbol('UPDATE') |
|
|
|
|
|
|
@ -76,6 +77,7 @@ class IO { |
|
|
|
: this._free() |
|
|
|
|
|
|
|
const punch = { |
|
|
|
version: VERSION, |
|
|
|
type: req.message.type, |
|
|
|
rid, |
|
|
|
command: '_holepunch', |
|
|
@ -98,6 +100,8 @@ class IO { |
|
|
|
const message = decodeMessage(buf) |
|
|
|
if (!message) return |
|
|
|
if (message.id && message.id.length !== 32) return |
|
|
|
// Force eph if older version
|
|
|
|
if (message.id && !(message.version >= VERSION)) message.id = null |
|
|
|
|
|
|
|
const peer = { port: rinfo.port, host: rinfo.address } |
|
|
|
|
|
|
@ -239,6 +243,7 @@ class IO { |
|
|
|
|
|
|
|
response (request, value, closerNodes, peer) { |
|
|
|
const message = { |
|
|
|
version: VERSION, |
|
|
|
type: TYPE.RESPONSE, |
|
|
|
rid: request.rid, |
|
|
|
to: peers.encode([peer]), |
|
|
@ -252,6 +257,7 @@ class IO { |
|
|
|
|
|
|
|
error (request, error, closerNodes, peer, value) { |
|
|
|
const message = { |
|
|
|
version: VERSION, |
|
|
|
type: TYPE.RESPONSE, |
|
|
|
rid: request.rid, |
|
|
|
to: peers.encode([peer]), |
|
|
@ -267,6 +273,7 @@ class IO { |
|
|
|
if (!callback) callback = noop |
|
|
|
|
|
|
|
this._request({ |
|
|
|
version: VERSION, |
|
|
|
type: TYPE.QUERY, |
|
|
|
rid: 0, |
|
|
|
to: encodeIP(peer), |
|
|
@ -281,6 +288,7 @@ class IO { |
|
|
|
if (!callback) callback = noop |
|
|
|
|
|
|
|
this._requestImmediately({ |
|
|
|
version: VERSION, |
|
|
|
type: TYPE.QUERY, |
|
|
|
rid: 0, |
|
|
|
to: encodeIP(peer), |
|
|
@ -295,6 +303,7 @@ class IO { |
|
|
|
if (!callback) callback = noop |
|
|
|
|
|
|
|
this._request({ |
|
|
|
version: VERSION, |
|
|
|
type: TYPE.UPDATE, |
|
|
|
rid: 0, |
|
|
|
to: encodeIP(peer), |
|
|
@ -309,6 +318,7 @@ class IO { |
|
|
|
|
|
|
|
IO.QUERY = QUERY |
|
|
|
IO.UPDATE = UPDATE |
|
|
|
IO.VERSION = VERSION |
|
|
|
|
|
|
|
module.exports = IO |
|
|
|
|
|
|
|