update secret-stack to 8.1
This commit is contained in:
parent
f35b368a41
commit
e82e369506
85
lib/index.js
85
lib/index.js
|
@ -12,55 +12,15 @@ const MsgV4 = require('ppppp-db/msg-v4')
|
||||||
* @typedef {`${string}@${GoalDSL}`} Rule
|
* @typedef {`${string}@${GoalDSL}`} Rule
|
||||||
* @typedef {[Array<Rule>, Array<Rule>]} Rules
|
* @typedef {[Array<Rule>, Array<Rule>]} Rules
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* db: PPPPPDB | null,
|
* db: PPPPPDB,
|
||||||
* goals: PPPPPGoal | null,
|
* goals: PPPPPGoal,
|
||||||
* set: PPPPPSet | null,
|
* set: PPPPPSet,
|
||||||
* dict: PPPPPDict | null,
|
* dict: PPPPPDict,
|
||||||
* sync: PPPPPSync | null,
|
* sync: PPPPPSync,
|
||||||
* gc: PPPPPGC | null,
|
* gc: PPPPPGC,
|
||||||
* }} UnknownPeer
|
* }} 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
|
* @param {any} rule
|
||||||
* @returns {[string, GoalDSL]}
|
* @returns {[string, GoalDSL]}
|
||||||
|
@ -76,16 +36,10 @@ function parseRule(rule) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {UnknownPeer} peer
|
* @param {Peer} peer
|
||||||
* @param {unknown} config
|
* @param {unknown} config
|
||||||
*/
|
*/
|
||||||
function initConductor(peer, 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
|
* How many bytes does a single msg ID take up
|
||||||
*/
|
*/
|
||||||
|
@ -140,7 +94,6 @@ function initConductor(peer, config) {
|
||||||
* @param {Rule} rule
|
* @param {Rule} rule
|
||||||
*/
|
*/
|
||||||
function getRealisticCount(rule) {
|
function getRealisticCount(rule) {
|
||||||
assertGoalsPlugin(peer)
|
|
||||||
const [, goalDSL] = parseRule(rule)
|
const [, goalDSL] = parseRule(rule)
|
||||||
const { count } = peer.goals.parse(goalDSL)
|
const { count } = peer.goals.parse(goalDSL)
|
||||||
const realisticCount = isFinite(count)
|
const realisticCount = isFinite(count)
|
||||||
|
@ -159,8 +112,6 @@ function initConductor(peer, config) {
|
||||||
* @returns {[Array<Rule>, Array<Rule>]}
|
* @returns {[Array<Rule>, Array<Rule>]}
|
||||||
*/
|
*/
|
||||||
function validateRules(rules, numFollowed, maxBytes) {
|
function validateRules(rules, numFollowed, maxBytes) {
|
||||||
assertGoalsPlugin(peer)
|
|
||||||
|
|
||||||
const [myRules, theirRules] = rules
|
const [myRules, theirRules] = rules
|
||||||
|
|
||||||
let estimateMsgCount =
|
let estimateMsgCount =
|
||||||
|
@ -198,10 +149,6 @@ function initConductor(peer, config) {
|
||||||
* @param {Array<Rule>} rules list of feed domains of interest
|
* @param {Array<Rule>} rules list of feed domains of interest
|
||||||
*/
|
*/
|
||||||
function setupAccountGoals(accountID, rules) {
|
function setupAccountGoals(accountID, rules) {
|
||||||
assertDBPlugin(peer)
|
|
||||||
assertSetPlugin(peer)
|
|
||||||
assertGoalsPlugin(peer)
|
|
||||||
|
|
||||||
peer.goals.set(accountID, 'all')
|
peer.goals.set(accountID, 'all')
|
||||||
|
|
||||||
const followDomain = peer.set.getDomain('follow')
|
const followDomain = peer.set.getDomain('follow')
|
||||||
|
@ -227,10 +174,6 @@ function initConductor(peer, config) {
|
||||||
* @param {Array<string>} rules
|
* @param {Array<string>} rules
|
||||||
*/
|
*/
|
||||||
function teardownAccountGoals(accountID, rules) {
|
function teardownAccountGoals(accountID, rules) {
|
||||||
assertDBPlugin(peer)
|
|
||||||
assertSetPlugin(peer)
|
|
||||||
assertGoalsPlugin(peer)
|
|
||||||
|
|
||||||
peer.goals.set(accountID, 'none')
|
peer.goals.set(accountID, 'none')
|
||||||
|
|
||||||
const followDomain = peer.set.getDomain('follow')
|
const followDomain = peer.set.getDomain('follow')
|
||||||
|
@ -260,18 +203,15 @@ function initConductor(peer, config) {
|
||||||
* @param {number} maxBytes
|
* @param {number} maxBytes
|
||||||
*/
|
*/
|
||||||
function start(myID, rules, maxBytes) {
|
function start(myID, rules, maxBytes) {
|
||||||
assertDBPlugin(peer)
|
|
||||||
assertSetPlugin(peer)
|
|
||||||
assertGoalsPlugin(peer)
|
|
||||||
assertGCPlugin(peer)
|
|
||||||
assertSyncPlugin(peer)
|
|
||||||
|
|
||||||
if (maxBytes < MIN_MAXBYTES) {
|
if (maxBytes < MIN_MAXBYTES) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
|
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
|
||||||
}
|
}
|
||||||
if (maxBytes > MAX_RECOMMENDED_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')
|
const followedAccounts = peer.set.values('follow')
|
||||||
|
@ -317,4 +257,5 @@ function initConductor(peer, config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.name = 'conductor'
|
exports.name = 'conductor'
|
||||||
|
exports.needs = ['db', 'goals', 'set', 'gc', 'sync']
|
||||||
exports.init = initConductor
|
exports.init = initConductor
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3",
|
||||||
"rimraf": "^4.4.0",
|
"rimraf": "^4.4.0",
|
||||||
"secret-handshake-ext": "~0.0.11",
|
"secret-handshake-ext": "~0.0.11",
|
||||||
"secret-stack": "~8.0.0",
|
"secret-stack": "~8.1.0",
|
||||||
"ssb-box": "^1.0.1"
|
"ssb-box": "^1.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue