update secret-stack to 8.1

This commit is contained in:
Andre Staltz 2024-01-08 11:33:45 +02:00
parent 26dcefc459
commit ae3d1d83d8
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
4 changed files with 10 additions and 61 deletions

View File

@ -24,31 +24,11 @@ function countIter(iter) {
return count
}
/**
* @param {{ dict: PPPPPDict | null }} peer
* @returns {asserts peer is { dict: PPPPPDict }}
*/
function assertDictPlugin(peer) {
if (!peer.dict) {
throw new Error('sync plugin requires ppppp-dict plugin')
}
}
/**
* @param {{ set: PPPPPSet | null }} peer
* @returns {asserts peer is { set: PPPPPSet }}
*/
function assertSetPlugin(peer) {
if (!peer.set) {
throw new Error('sync plugin requires ppppp-set plugin')
}
}
class Algorithm {
/** @type {{ db: PPPPPDB, dict: PPPPPDict | null, set: PPPPPSet | null }} */
/** @type {ConstructorParameters<typeof Algorithm>[0]} */
#peer
/** @param {{ db: PPPPPDB, dict: PPPPPDict | null, set: PPPPPSet | null }} peer */
/** @param {{ db: PPPPPDB, dict: PPPPPDict, set: PPPPPSet }} peer */
constructor(peer) {
this.#peer = peer
}
@ -149,12 +129,10 @@ class Algorithm {
return this.#wantAllRange(localHave, remoteHave)
case 'dict':
assertDictPlugin(this.#peer)
const minDictGhostDepth = this.#peer.dict.minGhostDepth(goal.id)
return this.#wantDictOrSetRange(minDictGhostDepth, remoteHave)
case 'set':
assertSetPlugin(this.#peer)
const minSetGhostDepth = this.#peer.set.minGhostDepth(goal.id)
return this.#wantDictOrSetRange(minSetGhostDepth, remoteHave)

View File

@ -27,44 +27,17 @@ function isMuxrpcMissingError(err, namespace, methodName) {
return err.message === jsErrorMessage || err.message === goErrorMessage
}
/**
* @param {{ db: PPPPPDB | null }} peer
* @returns {asserts peer is { db: PPPPPDB }}
*/
function assertDBExists(peer) {
if (!peer.db) throw new Error('"sync" plugin requires "db" plugin')
}
/**
* @param {{ goals: PPPPPGoals | null }} peer
* @returns {asserts peer is { goals: PPPPPGoals }}
*/
function assertGoalsExists(peer) {
if (!peer.goals) throw new Error('"sync" plugin requires "goals" plugin')
}
/**
* @param {{ shse: SHSE | null }} peer
* @returns {asserts peer is { shse: SHSE }}
*/
function assertSHSEExists(peer) {
if (!peer.shse) throw new Error('"sync" plugin requires "shse" plugin')
}
/**
* @param {Emitter & {
* db: PPPPPDB | null,
* dict: PPPPPDict | null,
* set: PPPPPSet | null,
* goals: PPPPPGoals | null,
* shse: SHSE | null
* db: PPPPPDB,
* dict: PPPPPDict,
* set: PPPPPSet,
* goals: PPPPPGoals,
* shse: SHSE
* }} peer
* @param {unknown} config
*/
function initSync(peer, config) {
assertDBExists(peer)
assertGoalsExists(peer)
assertSHSEExists(peer)
const debug = makeDebug(`ppppp:sync`)
const algo = new Algorithm(peer)
let started = false
@ -76,8 +49,6 @@ function initSync(peer, config) {
* @param {boolean} iamClient
*/
function createStream(remoteId, iamClient) {
assertSHSEExists(peer)
assertGoalsExists(peer)
// prettier-ignore
debug('Opening a stream with remote %s %s', iamClient ? 'server' : 'client', remoteId)
const stream = new SyncStream(peer.shse.pubkey, debug, peer.goals, algo)
@ -90,7 +61,6 @@ function initSync(peer, config) {
* @param {boolean} iamClient
*/
function onSyncRPCConnect(rpc, iamClient) {
assertSHSEExists(peer)
if (rpc.shse.pubkey === peer.shse.pubkey) return // connecting to myself
if (!iamClient) return
const stream = createStream(rpc.shse.pubkey, true)
@ -136,6 +106,7 @@ function initSync(peer, config) {
}
exports.name = 'sync'
exports.needs = ['db', 'dict', 'set', 'goals', 'shse']
exports.manifest = {
connect: 'duplex',
initiate: 'sync',

View File

@ -46,7 +46,7 @@
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"rimraf": "^4.4.0",
"secret-stack": "~8.0.0",
"secret-stack": "~8.1.0",
"secret-handshake-ext": "0.0.11",
"ssb-box": "^1.0.1",
"typescript": "^5.1.3"

View File

@ -11,6 +11,6 @@
"module": "node16",
"skipLibCheck": true,
"strict": true,
"target": "es2021"
"target": "es2022"
}
}