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) {
|
function initDict(peer, config) {
|
||||||
assertDBPlugin(peer)
|
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')
|
if (ghostSpan < 1) throw new Error('config.dict.ghostSpan must be >= 0')
|
||||||
|
|
||||||
//#region state
|
//#region state
|
||||||
|
@ -458,6 +458,15 @@ function initDict(peer, config) {
|
||||||
return ghostSpan
|
return ghostSpan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} span
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function setGhostSpan(span) {
|
||||||
|
if (span < 1) throw new Error('ghostSpan must be >= 0')
|
||||||
|
ghostSpan = span
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
* @param {string} subdomain
|
* @param {string} subdomain
|
||||||
|
@ -516,6 +525,7 @@ function initDict(peer, config) {
|
||||||
getFeedID,
|
getFeedID,
|
||||||
isGhostable,
|
isGhostable,
|
||||||
getGhostSpan,
|
getGhostSpan,
|
||||||
|
setGhostSpan,
|
||||||
minGhostDepth,
|
minGhostDepth,
|
||||||
minRequiredDepth,
|
minRequiredDepth,
|
||||||
squeeze,
|
squeeze,
|
||||||
|
|
|
@ -29,8 +29,8 @@ let aliceID
|
||||||
test('setup', async (t) => {
|
test('setup', async (t) => {
|
||||||
peer = createPeer({
|
peer = createPeer({
|
||||||
keypair: aliceKeypair,
|
keypair: aliceKeypair,
|
||||||
path: DIR,
|
db: {path: DIR},
|
||||||
dict: { ghostSpan: 4 },
|
dict: { ghostSpan: 40 },
|
||||||
})
|
})
|
||||||
|
|
||||||
await peer.db.loaded()
|
await peer.db.loaded()
|
||||||
|
@ -41,6 +41,7 @@ test('setup', async (t) => {
|
||||||
})
|
})
|
||||||
await p(peer.dict.load)(aliceID)
|
await p(peer.dict.load)(aliceID)
|
||||||
|
|
||||||
|
peer.dict.setGhostSpan(4)
|
||||||
assert.equal(peer.dict.getGhostSpan(), 4, 'getGhostSpan')
|
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 OS = require('node:os')
|
||||||
const path = require('node:path')
|
const Path = require('node:path')
|
||||||
const rimraf = require('rimraf')
|
const rimraf = require('rimraf')
|
||||||
const caps = require('ppppp-caps')
|
const caps = require('ppppp-caps')
|
||||||
const Keypair = require('ppppp-keypair')
|
const Keypair = require('ppppp-keypair')
|
||||||
|
|
||||||
function createPeer(opts) {
|
function createPeer(opts) {
|
||||||
if (opts.name) {
|
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.keypair ??= Keypair.generate('ed25519', opts.name)
|
||||||
opts.name = undefined
|
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()')
|
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')()
|
return require('secret-stack/bare')()
|
||||||
.use(require('secret-stack/plugins/net'))
|
.use(require('secret-stack/plugins/net'))
|
||||||
.use(require('secret-handshake-ext/secret-stack'))
|
.use(require('secret-handshake-ext/secret-stack'))
|
||||||
|
|
Loading…
Reference in New Issue