Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial stats #182

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HyperDHT extends DHT {
this.listening = new Set()
this.tracer = createTracer(this)
this.connectionKeepAlive = opts.connectionKeepAlive || 0
this.stats = { punches: { consistent: 0, random: 0, open: 0 } }

this._router = new Router(this, router)
this._socketPool = new SocketPool(this, opts.host || '0.0.0.0')
Expand Down
1 change: 1 addition & 0 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ async function holepunch (c, opts) {
const addr = getFirstRemoteAddress(payload.addresses4, serverAddress)
if (addr) {
const socket = c.dht.socket
c.dht.stats.punches.open++
c.onsocket(socket, addr.port, addr.host)
return
}
Expand Down
3 changes: 3 additions & 0 deletions lib/holepuncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,22 @@ module.exports = class Holepuncher {
}

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

if (!remoteVerifiedAddress) return false

if (local === FIREWALL.CONSISTENT && remote >= FIREWALL.RANDOM) {
this.dht.stats.punches.random++
this._incrementRandomized()
this._randomProbes(remoteVerifiedAddress)
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)
Expand Down
1 change: 1 addition & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ module.exports = class Server extends EventEmitter {

if (remotePayload.firewall === FIREWALL.OPEN || direct) {
const sock = direct ? socket : this.dht.socket
this.dht.stats.punches.open++
hs.onsocket(sock, clientAddress.port, clientAddress.host)
return hs
}
Expand Down
Loading