Expand economy, autobase, network, observability, and scheduling modules.
Add auction withdraw/cancel, marketplace search helpers, update gossip history, autobase fork/lease/indexer/view APIs, link-probe and circuit-loom utilities, trace trees, pheromone ranking, and scheduling/measurement helpers with tests. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -81,6 +81,21 @@ class HyperP2PPheromoneTrail extends EventEmitter {
|
||||
|
||||
trailCount () { return this._trails.size }
|
||||
|
||||
pathsForDest (dest) {
|
||||
const d = String(dest)
|
||||
return [...this._trails.values()].filter((t) => t.dest === d)
|
||||
}
|
||||
|
||||
rankPaths (dest, limit = 5) {
|
||||
return this.pathsForDest(dest)
|
||||
.sort((a, b) => b.strength - a.strength)
|
||||
.slice(0, Math.max(0, limit | 0))
|
||||
}
|
||||
|
||||
clearPath (pathId) {
|
||||
return this._trails.delete(String(pathId))
|
||||
}
|
||||
|
||||
async ready () {
|
||||
if (this.swarm || !this.topic) return this
|
||||
await initModuleSwarm(this, {
|
||||
|
||||
@@ -18,6 +18,16 @@ test('pheromone-trail: evaporate', async (t) => {
|
||||
t.not(p.sniff('x'))
|
||||
await p.close()
|
||||
})
|
||||
|
||||
test('pheromone-trail: rank and clear', async (t) => {
|
||||
const p = new HyperP2PPheromoneTrail()
|
||||
p.deposit('a', 0.2, 'dest')
|
||||
p.deposit('b', 0.9, 'dest')
|
||||
t.is(p.rankPaths('dest', 1)[0].pathId, 'b')
|
||||
t.ok(p.clearPath('a'))
|
||||
t.is(p.pathsForDest('dest').length, 1)
|
||||
await p.close()
|
||||
})
|
||||
test('hyper-p2p-pheromone-trail: close without leak', async (t) => {
|
||||
const m = new HyperP2PPheromoneTrail()
|
||||
await m.close()
|
||||
|
||||
Reference in New Issue
Block a user