feat(supercomputer,experimental): deepen share, steal, beacon, whisper

Bandwidth revoke/best offer, work-stealer batch/flush, entropy snapshot,
whisper clearSeen, and phase-shift setPhase/maxPeerDelta.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 02:28:21 -04:00
co-authored by Cursor
parent 8ac24ac6a2
commit a4e9131f66
7 changed files with 73 additions and 4 deletions
@@ -73,6 +73,14 @@ class HyperP2PEntropyBeacon extends EventEmitter {
return this.poolHash() return this.poolHash()
} }
drawHex (seed = '') {
return b4a.toString(this.draw(seed), 'hex')
}
snapshot () {
return { pool: b4a.toString(this._pool, 'hex'), contributions: this._contributions }
}
async ready () { async ready () {
if (this.swarm || !this.topic) return this if (this.swarm || !this.topic) return this
await initModuleSwarm(this, { await initModuleSwarm(this, {
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "hyper-p2p-entropy-beacon", "name": "hyper-p2p-entropy-beacon",
"version": "0.3.1", "version": "0.3.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "hyper-p2p-entropy-beacon", "name": "hyper-p2p-entropy-beacon",
"version": "0.3.1", "version": "0.3.2",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"b4a": "^1.6.7", "b4a": "^1.6.7",
@@ -55,6 +55,24 @@ class HyperP2PPhaseShiftClock extends EventEmitter {
return out return out
} }
setPhase (phaseMs) {
if (typeof phaseMs !== 'number' || Number.isNaN(phaseMs)) {
throw new Error('phaseMs must be a number')
}
this._phaseMs = phaseMs
this.emit('set', { phaseMs })
return this._phaseMs
}
maxPeerDelta () {
let max = 0
for (const phase of this._peerPhases.values()) {
const d = Math.abs(this._phaseMs - phase)
if (d > max) max = d
}
return max
}
_gossip (data) { _gossip (data) {
if (!this._peerMsgs) return if (!this._peerMsgs) return
gossipSend(this, data) gossipSend(this, data)
@@ -71,6 +71,17 @@ class HyperP2PWhisperMesh extends EventEmitter {
seenCount () { return this._seen.size } seenCount () { return this._seen.size }
setMaxHops (n) {
this.maxHops = Math.max(0, n | 0)
return this.maxHops
}
clearSeen () {
const n = this._seen.size
this._seen.clear()
return n
}
async ready () { async ready () {
if (this.swarm || !this.topic) return this if (this.swarm || !this.topic) return this
await initModuleSwarm(this, { await initModuleSwarm(this, {
@@ -87,6 +87,26 @@ class HyperP2PBandwidthShare extends EventEmitter {
this._used.clear() this._used.clear()
} }
revokeOffer (peerId) {
const id = this._pid(peerId)
const had = this._offers.delete(id)
if (had) {
for (const k of [...this._used.keys()]) {
if (k.startsWith(id + ':')) this._used.delete(k)
}
}
return had
}
bestOffer (direction = 'up') {
let best = null
for (const o of this._offers.values()) {
const mbps = direction === 'down' ? o.downMbps : o.upMbps
if (!best || mbps > (direction === 'down' ? best.downMbps : best.upMbps)) best = o
}
return best
}
async ready () { async ready () {
if (this.swarm || !this.topic) return this if (this.swarm || !this.topic) return this
await initModuleSwarm(this, { await initModuleSwarm(this, {
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "hyper-p2p-bandwidth-share", "name": "hyper-p2p-bandwidth-share",
"version": "0.3.0", "version": "0.3.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "hyper-p2p-bandwidth-share", "name": "hyper-p2p-bandwidth-share",
"version": "0.3.0", "version": "0.3.1",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"b4a": "^1.6.7", "b4a": "^1.6.7",
@@ -87,6 +87,18 @@ class HyperP2PWorkStealer extends EventEmitter {
return null return null
} }
pushBatch (shard, tasks) {
if (!Array.isArray(tasks)) throw new Error('tasks array required')
return tasks.map((task) => this.push(shard, task))
}
flushShard (shard = 'default') {
const q = this._queue(shard)
const n = q.length
q.length = 0
return n
}
async ready () { async ready () {
if (this.swarm || !this.topic) return this if (this.swarm || !this.topic) return this
await initModuleSwarm(this, { await initModuleSwarm(this, {