feat(routing,collab,trust): manually expand sticky-session and collab modules
Hyper-P2P Module Tests / unit-all (push) Has been cancelled
Hyper-P2P Module Tests / unit-all (push) Has been cancelled
- sticky-session: unbind, listSessions, bindBatch, remote remove gossip - cursor-presence: peersInDoc, pruneStale - whiteboard-op: listRooms, opCount, pruneRoom - key-rotation: listActiveKeys, revoke, tick activation sweep Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -32,9 +32,40 @@ class HyperP2PStickySession extends EventEmitter {
|
||||
return this._bindings.get(sessionId) || null
|
||||
}
|
||||
|
||||
unbind (sessionId) {
|
||||
assertNonEmpty(sessionId, 'sessionId')
|
||||
const ok = this._bindings.delete(sessionId)
|
||||
if (ok) {
|
||||
gossipSend(this, { type: 'sticky-session-remove', sessionId })
|
||||
this._stats.gossipOut++
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
hasSession (sessionId) {
|
||||
return this._bindings.has(sessionId)
|
||||
}
|
||||
|
||||
listSessions () {
|
||||
return [...this._bindings.entries()].map(([sessionId, peerId]) => ({ sessionId, peerId }))
|
||||
}
|
||||
|
||||
bindBatch (pairs) {
|
||||
if (!Array.isArray(pairs)) throw new Error('pairs must be an array')
|
||||
let n = 0
|
||||
for (const p of pairs) {
|
||||
if (p && this.bind(p.sessionId, p.peerId)) n++
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
_onGossip (d) {
|
||||
if (!d || d.type !== 'sticky-session-sync' || !d.sessionId) return
|
||||
this._stats.gossipIn++
|
||||
if (d.type === 'sticky-session-remove') {
|
||||
this._bindings.delete(d.sessionId)
|
||||
return
|
||||
}
|
||||
if (d.peerId) this._bindings.set(d.sessionId, d.peerId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user