update secret-stack to 8.1

This commit is contained in:
Andre Staltz 2024-01-08 11:40:28 +02:00
parent f35b368a41
commit e82e369506
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 14 additions and 73 deletions

View File

@ -12,55 +12,15 @@ const MsgV4 = require('ppppp-db/msg-v4')
* @typedef {`${string}@${GoalDSL}`} Rule
* @typedef {[Array<Rule>, Array<Rule>]} Rules
* @typedef {{
* db: PPPPPDB | null,
* goals: PPPPPGoal | null,
* set: PPPPPSet | null,
* dict: PPPPPDict | null,
* sync: PPPPPSync | null,
* gc: PPPPPGC | null,
* }} UnknownPeer
* db: PPPPPDB,
* goals: PPPPPGoal,
* set: PPPPPSet,
* dict: PPPPPDict,
* sync: PPPPPSync,
* gc: PPPPPGC,
* }} Peer
*/
/**
* @param {{ db: PPPPPDB | null }} peer
* @returns {asserts peer is { db: PPPPPDB }}
*/
function assertDBPlugin(peer) {
if (!peer.db) throw new Error('"conductor" plugin requires "db" plugin')
}
/**
* @param {{ goals: PPPPPGoal | null }} peer
* @returns {asserts peer is { goals: PPPPPGoal }}
*/
function assertGoalsPlugin(peer) {
if (!peer.goals) throw new Error('"conductor" plugin requires "goals" plugin')
}
/**
* @param {{ set: PPPPPSet | null }} peer
* @returns {asserts peer is { set: PPPPPSet }}
*/
function assertSetPlugin(peer) {
if (!peer.set) throw new Error('"conductor" plugin requires "set" plugin')
}
/**
* @param {{ gc: PPPPPGC | null }} peer
* @returns {asserts peer is { gc: PPPPPGC }}
*/
function assertGCPlugin(peer) {
if (!peer.gc) throw new Error('"conductor" plugin requires "gc" plugin')
}
/**
* @param {{ sync: PPPPPSync | null }} peer
* @returns {asserts peer is { sync: PPPPPSync }}
*/
function assertSyncPlugin(peer) {
if (!peer.sync) throw new Error('"conductor" plugin requires "sync" plugin')
}
/**
* @param {any} rule
* @returns {[string, GoalDSL]}
@ -76,16 +36,10 @@ function parseRule(rule) {
}
/**
* @param {UnknownPeer} peer
* @param {Peer} peer
* @param {unknown} config
*/
function initConductor(peer, config) {
assertDBPlugin(peer)
assertGoalsPlugin(peer)
assertSetPlugin(peer)
assertGCPlugin(peer)
assertSyncPlugin(peer)
/**
* How many bytes does a single msg ID take up
*/
@ -140,7 +94,6 @@ function initConductor(peer, config) {
* @param {Rule} rule
*/
function getRealisticCount(rule) {
assertGoalsPlugin(peer)
const [, goalDSL] = parseRule(rule)
const { count } = peer.goals.parse(goalDSL)
const realisticCount = isFinite(count)
@ -159,8 +112,6 @@ function initConductor(peer, config) {
* @returns {[Array<Rule>, Array<Rule>]}
*/
function validateRules(rules, numFollowed, maxBytes) {
assertGoalsPlugin(peer)
const [myRules, theirRules] = rules
let estimateMsgCount =
@ -198,10 +149,6 @@ function initConductor(peer, config) {
* @param {Array<Rule>} rules list of feed domains of interest
*/
function setupAccountGoals(accountID, rules) {
assertDBPlugin(peer)
assertSetPlugin(peer)
assertGoalsPlugin(peer)
peer.goals.set(accountID, 'all')
const followDomain = peer.set.getDomain('follow')
@ -227,10 +174,6 @@ function initConductor(peer, config) {
* @param {Array<string>} rules
*/
function teardownAccountGoals(accountID, rules) {
assertDBPlugin(peer)
assertSetPlugin(peer)
assertGoalsPlugin(peer)
peer.goals.set(accountID, 'none')
const followDomain = peer.set.getDomain('follow')
@ -260,18 +203,15 @@ function initConductor(peer, config) {
* @param {number} maxBytes
*/
function start(myID, rules, maxBytes) {
assertDBPlugin(peer)
assertSetPlugin(peer)
assertGoalsPlugin(peer)
assertGCPlugin(peer)
assertSyncPlugin(peer)
if (maxBytes < MIN_MAXBYTES) {
// prettier-ignore
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
}
if (maxBytes > MAX_RECOMMENDED_MAXBYTES) {
debug('WARNING. maxBytes is too big, we recommend at most %s bytes', MAX_RECOMMENDED_MAXBYTES)
debug(
'WARNING. maxBytes is too big, we recommend at most %s bytes',
MAX_RECOMMENDED_MAXBYTES
)
}
const followedAccounts = peer.set.values('follow')
@ -317,4 +257,5 @@ function initConductor(peer, config) {
}
exports.name = 'conductor'
exports.needs = ['db', 'goals', 'set', 'gc', 'sync']
exports.init = initConductor

View File

@ -42,7 +42,7 @@
"pretty-quick": "^3.1.3",
"rimraf": "^4.4.0",
"secret-handshake-ext": "~0.0.11",
"secret-stack": "~8.0.0",
"secret-stack": "~8.1.0",
"ssb-box": "^1.0.1"
},
"scripts": {