Add Supercomputer category: 12 P2P resource-sharing modules (164 total)

Introduce a new production category for distributed system resource pooling
over Hyperswarm — CPU, RAM, GPU, bandwidth, disk, jobs, cache, and egress.

New modules (supercomputer/):
- hyper-p2p-capacity-registry — gossip CPU/RAM/GPU/disk/bandwidth ads
- hyper-p2p-cpu-share — CPU millisecond credit pool
- hyper-p2p-ram-pool — RAM byte lend/claim/release
- hyper-p2p-gpu-slot — GPU slot register/reserve
- hyper-p2p-bandwidth-share — shared up/down Mbps
- hyper-p2p-disk-stripe — striped block shards
- hyper-p2p-job-dispatcher — submit/claim/complete jobs
- hyper-p2p-thermal-guard — load/temperature throttle signals
- hyper-p2p-cache-farm — distributed LRU cache
- hyper-p2p-net-gateway — peer internet egress routing
- hyper-p2p-cluster-affinity — hardware tag placement scoring
- hyper-p2p-work-stealer — shard queues + work stealing

Each package: index.js, tests, README, api/architecture docs, examples/basic.js.
Shared layering guide: _shared/SUPERCOMPUTER_LAYERS.md.
Registry, module-paths, MODULE_CATEGORIES, and workspace README updated to 164.

Parent workspace also adds docs/supercomputer hub and demo-supercomputer-mesh
(outside this repo).

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 00:38:53 -04:00
co-authored by Cursor
parent 70119888cd
commit 693385bd7c
114 changed files with 24378 additions and 6 deletions
@@ -0,0 +1,5 @@
# Changelog
## 0.3.0
- Initial Supercomputer category release (cache-farm/v1).
@@ -0,0 +1,30 @@
# hyper-p2p-cache-farm
Production **Supercomputer** module: pool P2P system resources over Hyperswarm.
**Category:** Supercomputer · **Protocol:** `cache-farm/v1` · **Export:** `HyperP2PCacheFarm`
## When to use
Distributed LRU cache with gossip invalidation.
## Quick start
```js
const { HyperP2PCacheFarm } = require('hyper-p2p-cache-farm')
const mod = new HyperP2PCacheFarm({ topic: 'my-super-mesh' })
await mod.ready()
// ...
await mod.close()
```
## Docs
- [docs/api.md](docs/api.md)
- [docs/architecture.md](docs/architecture.md)
## Test
```bash
npm install && npm test
```
@@ -0,0 +1,36 @@
# API: hyper-p2p-cache-farm
**Protocol:** `cache-farm/v1` · **Export:** `HyperP2PCacheFarm`
## Overview
Distributed LRU cache with gossip invalidation.
## Constructor
```js
const mod = new HyperP2PCacheFarm(opts)
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic |
| `keyPair` | KeyPair | random | Discovery identity |
## Methods
See [`index.js`](../index.js) for the full method list. All modules implement `getStats()`, `async ready()`, and `async close()`.
## getStats()
Returns `{ ...stats, protocol: 'cache-farm/v1' }` plus module-specific counters.
## P2P
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `cache-farm/v1`.
## Testing
```bash
npm install && npm test
```
@@ -0,0 +1,14 @@
# Architecture: hyper-p2p-cache-farm
**Category:** Supercomputer · **Protocol:** `cache-farm/v1`
```mermaid
flowchart LR
App[Application] --> Mod[HyperP2PCacheFarm]
Mod --> Mux[Protomux cache-farm/v1]
Mux --> Swarm[Hyperswarm]
```
## Composition
See [`../../_shared/SUPERCOMPUTER_LAYERS.md`](../../_shared/SUPERCOMPUTER_LAYERS.md) and [`../README.md`](../README.md).
@@ -0,0 +1,10 @@
require('bare-process/global')
const { HyperP2PCacheFarm } = require('../index.js')
async function main () {
const mod = new HyperP2PCacheFarm()
console.log('stats', mod.getStats())
await mod.close()
console.log('done')
}
main().catch(console.error)
+101
View File
@@ -0,0 +1,101 @@
require('bare-process/global')
const EventEmitter = require('bare-events')
const b4a = require('b4a')
const { initModuleSwarm, gossipSend } = require('../../_shared/p2p-bare.js')
const PROTOCOL = 'cache-farm/v1'
class HyperP2PCacheFarm extends EventEmitter {
constructor (opts = {}) {
super()
this._stats = { puts: 0, hits: 0, misses: 0 }
this.topic = opts.topic || null
this.keyPair = opts.keyPair || require('hypercore-crypto').keyPair()
this.maxEntries = opts.maxEntries ?? 4096
this._cache = new Map()
this._order = []
this.swarm = null
this._peerMsgs = null
}
_evict () {
while (this._cache.size > this.maxEntries && this._order.length) {
const k = this._order.shift()
this._cache.delete(k)
}
}
put (key, value, ttlMs = null) {
if (key == null) throw new Error('key required')
const entry = { key: String(key), value, ttlMs, at: Date.now(), expiresAt: ttlMs ? Date.now() + ttlMs : null }
if (!this._cache.has(entry.key)) this._order.push(entry.key)
else {
const i = this._order.indexOf(entry.key)
if (i >= 0) this._order.splice(i, 1)
this._order.push(entry.key)
}
this._cache.set(entry.key, entry)
this._stats.puts++
this._evict()
if (this._peerMsgs) gossipSend(this, { type: 'put', entry })
this.emit('put', entry)
return true
}
get (key) {
const entry = this._cache.get(String(key))
if (!entry) {
this._stats.misses++
return undefined
}
if (entry.expiresAt && Date.now() > entry.expiresAt) {
this._cache.delete(entry.key)
this._stats.misses++
return undefined
}
const i = this._order.indexOf(entry.key)
if (i >= 0) { this._order.splice(i, 1); this._order.push(entry.key) }
this._stats.hits++
return entry.value
}
invalidate (key) {
const k = String(key)
const ok = this._cache.delete(k)
if (ok) {
const i = this._order.indexOf(k)
if (i >= 0) this._order.splice(i, 1)
if (this._peerMsgs) gossipSend(this, { type: 'invalidate', key: k })
this.emit('invalidate', { key: k })
}
return ok
}
size () { return this._cache.size }
async ready () {
if (this.swarm || !this.topic) return this
await initModuleSwarm(this, {
keyPair: this.keyPair, topic: this.topic, protocol: PROTOCOL,
onmessage: (data) => {
if (data?.type === 'put' && data.entry) this.put(data.entry.key, data.entry.value, data.entry.ttlMs)
else if (data?.type === 'invalidate') this._cache.delete(data.key)
}
})
return this
}
getStats () {
return { ...this._stats, entries: this._cache.size, protocol: PROTOCOL }
}
async close () {
if (this.swarm) await this.swarm.destroy().catch(() => {})
this.swarm = null
this._cache.clear()
this._order = []
this.emit('closed')
}
}
module.exports = { HyperP2PCacheFarm, PROTOCOL }
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,23 @@
{
"name": "hyper-p2p-cache-farm",
"version": "0.3.0",
"description": "Distributed LRU cache farm for Bare/Pear P2P supercomputer mesh.",
"main": "index.js",
"type": "commonjs",
"license": "Apache-2.0",
"scripts": { "test": "brittle-bare test/test.js" },
"dependencies": {
"bare-events": "^2.8.0",
"bare-process": "^4.4.0",
"b4a": "^1.6.7",
"hypercore-crypto": "^3.0.0",
"protomux": "^3.0.0",
"compact-encoding": "^2.0.0"
},
"peerDependencies": { "hyperswarm": "^4.0.0", "bare": ">=1.0.0" },
"devDependencies": { "brittle": "^3.0.0" },
"imports": {
"process": { "bare": "bare-process", "default": "process" },
"events": { "bare": "bare-events", "default": "events" }
}
}
@@ -0,0 +1,23 @@
require('bare-process/global')
const test = require('brittle')
const { HyperP2PCacheFarm } = require('../index.js')
test('cache-farm: put get invalidate', async (t) => {
const c = new HyperP2PCacheFarm()
c.put('k1', { v: 1 })
t.is(c.get('k1').v, 1)
t.ok(c.invalidate('k1'))
t.is(c.get('k1'), undefined)
await c.close()
})
test('cache-farm: validation', async (t) => {
const c = new HyperP2PCacheFarm()
try {
c.put(null, 1)
t.fail('expected throw')
} catch (e) {
t.ok(e instanceof Error)
}
await c.close()
})