feat(modules): deepen trust, experimental, routing, and search
Hyper-P2P Module Tests / unit-all (push) Failing after 1h17m5s
Hyper-P2P Module Tests / unit-all (push) Failing after 1h17m5s
Session revoke and encrypted-topic JSON helpers; silence/void channel snapshots; relay tunnel route listing; grow-only set algebra; CPU top donors; attestation chain slice/export; fulltext bulk and top terms. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -42,6 +42,26 @@ class HyperP2PSessionRotation extends EventEmitter {
|
||||
return [...this._sessions.values()]
|
||||
}
|
||||
|
||||
revokeSession (sessionId) {
|
||||
assertNonEmpty(sessionId, 'sessionId')
|
||||
const had = this._sessions.delete(sessionId)
|
||||
if (had) {
|
||||
this._gossip({ type: 'session-revoke', sessionId, at: Date.now() })
|
||||
this.emit('revoked', { sessionId })
|
||||
}
|
||||
return had
|
||||
}
|
||||
|
||||
validateToken (sessionId, token) {
|
||||
const s = this.getSession(sessionId)
|
||||
return !!(s && s.token === token)
|
||||
}
|
||||
|
||||
latestVersion (sessionId) {
|
||||
const s = this.getSession(sessionId)
|
||||
return s ? s.version : 0
|
||||
}
|
||||
|
||||
_gossip (data) {
|
||||
if (!this._peerMsgs) return
|
||||
gossipSend(this, data)
|
||||
@@ -49,7 +69,13 @@ class HyperP2PSessionRotation extends EventEmitter {
|
||||
}
|
||||
|
||||
_onGossip (d) {
|
||||
if (!d || d.type !== 'session-rotate' || !d.sessionId) return
|
||||
if (!d || !d.sessionId) return
|
||||
if (d.type === 'session-revoke') {
|
||||
this._stats.gossipIn++
|
||||
this._sessions.delete(d.sessionId)
|
||||
return
|
||||
}
|
||||
if (d.type !== 'session-rotate') return
|
||||
this._stats.gossipIn++
|
||||
const prev = this._sessions.get(d.sessionId)
|
||||
if (!prev || d.version >= prev.version) {
|
||||
|
||||
@@ -36,3 +36,14 @@ test('getStats', async (t) => {
|
||||
t.is(m.getStats().rotations, 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('validateToken revokeSession', async (t) => {
|
||||
const m = new HyperP2PSessionRotation()
|
||||
m.rotateSession('s', 'secret')
|
||||
t.ok(m.validateToken('s', 'secret'))
|
||||
t.not(m.validateToken('s', 'wrong'))
|
||||
t.is(m.latestVersion('s'), 1)
|
||||
t.ok(m.revokeSession('s'))
|
||||
t.is(m.getSession('s'), null)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user