mirror of https://codeberg.org/pzp/pzp-dict.git
setGhostSpan
This commit is contained in:
parent
99a30b1aea
commit
e069033f9a
12
lib/index.js
12
lib/index.js
|
@ -77,7 +77,7 @@ function assertDBPlugin(peer) {
|
|||
function initDict(peer, config) {
|
||||
assertDBPlugin(peer)
|
||||
|
||||
const ghostSpan = config.dict?.ghostSpan ?? 32
|
||||
let ghostSpan = config.dict?.ghostSpan ?? 32
|
||||
if (ghostSpan < 1) throw new Error('config.dict.ghostSpan must be >= 0')
|
||||
|
||||
//#region state
|
||||
|
@ -458,6 +458,15 @@ function initDict(peer, config) {
|
|||
return ghostSpan
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} span
|
||||
* @returns {void}
|
||||
*/
|
||||
function setGhostSpan(span) {
|
||||
if (span < 1) throw new Error('ghostSpan must be >= 0')
|
||||
ghostSpan = span
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param {string} subdomain
|
||||
|
@ -516,6 +525,7 @@ function initDict(peer, config) {
|
|||
getFeedID,
|
||||
isGhostable,
|
||||
getGhostSpan,
|
||||
setGhostSpan,
|
||||
minGhostDepth,
|
||||
minRequiredDepth,
|
||||
squeeze,
|
||||
|
|
|
@ -29,8 +29,8 @@ let aliceID
|
|||
test('setup', async (t) => {
|
||||
peer = createPeer({
|
||||
keypair: aliceKeypair,
|
||||
path: DIR,
|
||||
dict: { ghostSpan: 4 },
|
||||
db: {path: DIR},
|
||||
dict: { ghostSpan: 40 },
|
||||
})
|
||||
|
||||
await peer.db.loaded()
|
||||
|
@ -41,6 +41,7 @@ test('setup', async (t) => {
|
|||
})
|
||||
await p(peer.dict.load)(aliceID)
|
||||
|
||||
peer.dict.setGhostSpan(4)
|
||||
assert.equal(peer.dict.getGhostSpan(), 4, 'getGhostSpan')
|
||||
})
|
||||
|
||||
|
|
11
test/util.js
11
test/util.js
|
@ -1,19 +1,20 @@
|
|||
const os = require('node:os')
|
||||
const path = require('node:path')
|
||||
const OS = require('node:os')
|
||||
const Path = require('node:path')
|
||||
const rimraf = require('rimraf')
|
||||
const caps = require('ppppp-caps')
|
||||
const Keypair = require('ppppp-keypair')
|
||||
|
||||
function createPeer(opts) {
|
||||
if (opts.name) {
|
||||
opts.path ??= path.join(os.tmpdir(), 'tanglesync-' + opts.name)
|
||||
const tmp = OS.tmpdir()
|
||||
opts.db ??= {path: Path.join(tmp, `ppppp-dict-${opts.name}-${Date.now()}`)}
|
||||
opts.keypair ??= Keypair.generate('ed25519', opts.name)
|
||||
opts.name = undefined
|
||||
}
|
||||
if (!opts.path) throw new Error('need opts.path in createPeer()')
|
||||
if (!opts.db.path) throw new Error('need opts.path in createPeer()')
|
||||
if (!opts.keypair) throw new Error('need opts.keypair in createPeer()')
|
||||
|
||||
rimraf.sync(opts.path)
|
||||
rimraf.sync(opts.db.path)
|
||||
return require('secret-stack/bare')()
|
||||
.use(require('secret-stack/plugins/net'))
|
||||
.use(require('secret-handshake-ext/secret-stack'))
|
||||
|
|
Loading…
Reference in New Issue