Deepen supercomputer category with shared base and expanded APIs.
Adds supercomputer-base helpers, richer job/shard/steal/thermal modules, priority jobs, claimMatching, and bumps all 14 modules to 0.3.1. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -2,6 +2,7 @@ require('bare-process/global')
|
||||
const EventEmitter = require('bare-events')
|
||||
const b4a = require('b4a')
|
||||
const { initModuleSwarm, gossipSend } = require('../../_shared/p2p-bare.js')
|
||||
const { normalizePeerId, clusterStats, assertPositive } = require('../../_shared/supercomputer-base.js')
|
||||
|
||||
const PROTOCOL = 'bandwidth-share/v1'
|
||||
|
||||
@@ -65,6 +66,27 @@ class HyperP2PBandwidthShare extends EventEmitter {
|
||||
return { upMbps: up, downMbps: down, peers: this._offers.size }
|
||||
}
|
||||
|
||||
remainingBytes (peerId, direction = 'up') {
|
||||
const offer = this.getOffer(peerId)
|
||||
if (!offer) return 0
|
||||
const id = normalizePeerId(peerId)
|
||||
const key = id + ':' + direction
|
||||
const used = this._used.get(key) || 0
|
||||
const capMbps = direction === 'down' ? offer.downMbps : offer.upMbps
|
||||
return Math.max(0, capMbps * 125000 - used)
|
||||
}
|
||||
|
||||
resetUsage (peerId = null) {
|
||||
if (peerId) {
|
||||
const id = normalizePeerId(peerId)
|
||||
for (const k of [...this._used.keys()]) {
|
||||
if (k.startsWith(id + ':')) this._used.delete(k)
|
||||
}
|
||||
return
|
||||
}
|
||||
this._used.clear()
|
||||
}
|
||||
|
||||
async ready () {
|
||||
if (this.swarm || !this.topic) return this
|
||||
await initModuleSwarm(this, {
|
||||
@@ -82,7 +104,7 @@ class HyperP2PBandwidthShare extends EventEmitter {
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats, offers: this._offers.size, protocol: PROTOCOL }
|
||||
return clusterStats(this._stats, PROTOCOL, { offers: this._offers.size })
|
||||
}
|
||||
|
||||
async close () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hyper-p2p-bandwidth-share",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"description": "Shared uplink and downlink capacity for Bare/Pear P2P supercomputer mesh.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
|
||||
Reference in New Issue
Block a user