Skip to content

Commit

Permalink
remove debug option as its unused now (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh authored Oct 9, 2024
1 parent 77c67a9 commit 1e801be
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 42 deletions.
8 changes: 0 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class HyperDHT extends DHT {
this._randomPunches = 0
this._randomPunchLimit = 1 // set to one for extra safety for now

this._debugStream = (opts.debug && opts.debug.stream) || null
this._debugHandshakeLatency = toRange((opts.debug && opts.debug.handshake && opts.debug.handshake.latency) || 0)

this.once('persistent', () => {
this._persistent = new Persistent(this, persistent)
})
Expand Down Expand Up @@ -535,11 +532,6 @@ function mapMutable (node) {

function noop () {}

function toRange (n) {
if (!n) return null
return typeof n === 'number' ? [n, n] : n
}

function filterNode (node) {
// always skip these testnet nodes that got mixed in by accident, until they get updated
return !(node.port === 49738 && (node.host === '134.209.28.98' || node.host === '167.99.142.185')) &&
Expand Down
14 changes: 2 additions & 12 deletions lib/connect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const NoiseSecretStream = require('@hyperswarm/secret-stream')
const b4a = require('b4a')
const relay = require('blind-relay')
const DebuggingStream = require('debugging-stream')
const { isPrivate, isBogon } = require('bogon')
const safetyCatch = require('safety-catch')
const unslab = require('unslab')
Expand Down Expand Up @@ -426,12 +425,7 @@ async function connectThroughNode (c, address, socket) {
if (remoteChanging) remoteChanging.catch(safetyCatch)
} else {
c.rawStream.connect(socket, c.connect.payload.udx.id, port, host)

const rawStream = c.dht._debugStream !== null
? new DebuggingStream(c.rawStream, c.dht._debugStream)
: c.rawStream

c.encryptedSocket.start(rawStream, { handshake: hs })
c.encryptedSocket.start(c.rawStream, { handshake: hs })
}

if (c.reusableSocket && payload.udx.reusableSocket) {
Expand Down Expand Up @@ -725,11 +719,7 @@ function relayConnection (c, relayThrough, payload, hs) {
.on('close', () => c.relaySocket.destroy())
.connect(socket, remoteId, remotePort, remoteHost)

const rawStream = c.dht._debugStream !== null
? new DebuggingStream(c.rawStream, c.dht._debugStream)
: c.rawStream

c.encryptedSocket.start(rawStream, { handshake: hs })
c.encryptedSocket.start(c.rawStream, { handshake: hs })
}

function onabort (err) {
Expand Down
23 changes: 2 additions & 21 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { FIREWALL, ERROR } = require('./constants')
const { unslabbedHash } = require('./crypto')
const SecurePayload = require('./secure-payload')
const Holepuncher = require('./holepuncher')
const DebuggingStream = require('debugging-stream')
const { isPrivate } = require('bogon')
const { ALREADY_LISTENING, NODE_DESTROYED } = require('./errors')

Expand Down Expand Up @@ -304,12 +303,7 @@ module.exports = class Server extends EventEmitter {
if (remoteChanging) remoteChanging.catch(safetyCatch)
} else {
hs.rawStream.connect(socket, remotePayload.udx.id, port, host)

const rawStream = this.dht._debugStream !== null
? new DebuggingStream(hs.rawStream, this.dht._debugStream)
: hs.rawStream

hs.encryptedSocket = this.createSecretStream(false, rawStream, {
hs.encryptedSocket = this.createSecretStream(false, hs.rawStream, {
handshake: h,
keepAlive: this.dht.connectionKeepAlive
})
Expand Down Expand Up @@ -363,11 +357,6 @@ module.exports = class Server extends EventEmitter {
return null
}

if (this.dht._debugHandshakeLatency !== null) {
const [start, end] = this.dht._debugHandshakeLatency
await sleep(start + Math.round(Math.random() * (end - start)))
}

const h = handshake.final()

if (error !== ERROR.NONE) {
Expand Down Expand Up @@ -640,11 +629,7 @@ module.exports = class Server extends EventEmitter {
.on('close', () => hs.relaySocket.destroy())
.connect(socket, remoteId, remotePort, remoteHost)

const rawStream = this.dht._debugStream !== null
? new DebuggingStream(hs.rawStream, this.dht._debugStream)
: hs.rawStream

hs.encryptedSocket = this.createSecretStream(false, rawStream, { handshake: h })
hs.encryptedSocket = this.createSecretStream(false, hs.rawStream, { handshake: h })

this.onconnection(hs.encryptedSocket)
})
Expand Down Expand Up @@ -685,10 +670,6 @@ function defaultCreateSecretStream (isInitiator, rawStream, opts) {
return new NoiseSecretStream(isInitiator, rawStream, opts)
}

function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

function onlyPrivateHosts (addr) {
return isPrivate(addr.host)
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"bogon": "^1.0.0",
"compact-encoding": "^2.4.1",
"compact-encoding-net": "^1.0.1",
"debugging-stream": "^2.0.0",
"dht-rpc": "^6.15.1",
"hypercore-crypto": "^3.3.0",
"hypercore-id-encoding": "^1.2.0",
Expand Down

0 comments on commit 1e801be

Please sign in to comment.