mirror of https://codeberg.org/pzp/pzp-sync.git
update to msg-v4
This commit is contained in:
parent
dd8499cf91
commit
d7a5c2694f
|
@ -1,6 +1,6 @@
|
|||
const p = require('promisify-4loc')
|
||||
const { BloomFilter } = require('bloom-filters')
|
||||
const MsgV3 = require('ppppp-db/msg-v3')
|
||||
const MsgV4 = require('ppppp-db/msg-v4')
|
||||
const makeDebug = require('debug')
|
||||
const debug = makeDebug('ppppp:sync')
|
||||
const { EMPTY_RANGE, isEmptyRange, estimateMsgCount } = require('./range')
|
||||
|
@ -9,7 +9,7 @@ const { EMPTY_RANGE, isEmptyRange, estimateMsgCount } = require('./range')
|
|||
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
||||
* @typedef {ReturnType<import('ppppp-dict').init>} PPPPPDict
|
||||
* @typedef {ReturnType<import('ppppp-set').init>} PPPPPSet
|
||||
* @typedef {import('ppppp-db/msg-v3').Msg} Msg
|
||||
* @typedef {import('ppppp-db/msg-v4').Msg} Msg
|
||||
* @typedef {import('ppppp-goals').Goal} Goal
|
||||
* @typedef {import('./range').Range} Range
|
||||
* @typedef {string} MsgID
|
||||
|
@ -191,7 +191,7 @@ class Algorithm {
|
|||
const rangeMsgs = this.getMsgsInRange(rootID, range)
|
||||
const accountMsgs = this.getAccountMsgsFor(rangeMsgs)
|
||||
for (const msg of accountMsgs.concat(rangeMsgs)) {
|
||||
filter.add('' + round + MsgV3.getMsgID(msg))
|
||||
filter.add('' + round + MsgV4.getMsgID(msg))
|
||||
}
|
||||
}
|
||||
const ghosts = this.#peer.db.ghosts.get(rootID)
|
||||
|
@ -227,7 +227,7 @@ class Algorithm {
|
|||
const rangeMsgs = this.getMsgsInRange(rootID, range)
|
||||
const accountMsgs = this.getAccountMsgsFor(rangeMsgs)
|
||||
for (const msg of accountMsgs.concat(rangeMsgs)) {
|
||||
const msgID = MsgV3.getMsgID(msg)
|
||||
const msgID = MsgV4.getMsgID(msg)
|
||||
if (!remoteFilter.has('' + round + msgID)) {
|
||||
missing.push(msgID)
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ class Algorithm {
|
|||
getAccountMsgsFor(msgs) {
|
||||
const accountTips = /** @type {Map<MsgID, Set<string>>} */ (new Map())
|
||||
for (const msg of msgs) {
|
||||
if (MsgV3.isFeedMsg(msg)) {
|
||||
if (MsgV4.isFeedMsg(msg)) {
|
||||
const set = accountTips.get(msg.metadata.account) ?? new Set()
|
||||
for (const tip of msg.metadata.accountTips) {
|
||||
set.add(tip)
|
||||
|
@ -319,7 +319,7 @@ class Algorithm {
|
|||
if (Array.isArray(msgs) && msgs.length === 0) return []
|
||||
if (!Array.isArray(msgs) && msgs.size === 0) return []
|
||||
const msgIDs = [...msgs].map((m) =>
|
||||
typeof m === 'string' ? m : MsgV3.getMsgID(m)
|
||||
typeof m === 'string' ? m : MsgV4.getMsgID(m)
|
||||
)
|
||||
const tangle = this.#peer.db.getTangle(rootID)
|
||||
return tangle.slice(msgIDs, [])
|
||||
|
@ -365,7 +365,7 @@ class Algorithm {
|
|||
.filter((msg) => {
|
||||
if (msg.metadata.account === 'self') return true
|
||||
const depth = msg.metadata.tangles[rootID]?.depth ?? 0
|
||||
if (depth === 0 && MsgV3.getMsgID(msg) !== rootID) {
|
||||
if (depth === 0 && MsgV4.getMsgID(msg) !== rootID) {
|
||||
return false // the rootMsg is the only acceptable depth-zero msg
|
||||
}
|
||||
if (!msg.data) {
|
||||
|
|
|
@ -4,7 +4,7 @@ const { isEmptyRange } = require('./range')
|
|||
|
||||
/**
|
||||
* @typedef {ReturnType<import('ppppp-goals').init>} PPPPPGoals
|
||||
* @typedef {import('ppppp-db/msg-v3').Msg} Msg
|
||||
* @typedef {import('ppppp-db/msg-v4').Msg} Msg
|
||||
* @typedef {import('./range').Range} Range
|
||||
* @typedef {import('./algorithm')} Algorithm
|
||||
* @typedef {import('ppppp-goals').Goal} Goal
|
||||
|
|
|
@ -2,7 +2,7 @@ const test = require('node:test')
|
|||
const assert = require('node:assert')
|
||||
const p = require('node:util').promisify
|
||||
const Keypair = require('ppppp-keypair')
|
||||
const MsgV3 = require('ppppp-db/msg-v3')
|
||||
const MsgV4 = require('ppppp-db/msg-v4')
|
||||
const { createPeer } = require('./util')
|
||||
|
||||
const aliceKeypair = Keypair.generate('ed25519', 'alice')
|
||||
|
@ -67,10 +67,10 @@ test('sync goal=dict with ghostSpan=2', async (t) => {
|
|||
|
||||
// Bob knows a branched off msg that Alice doesn't know
|
||||
{
|
||||
const tangle = new MsgV3.Tangle(moot.id)
|
||||
const tangle = new MsgV4.Tangle(moot.id)
|
||||
tangle.add(moot.id, moot.msg)
|
||||
tangle.add(rec1.id, rec1.msg)
|
||||
const msg = MsgV3.create({
|
||||
const msg = MsgV4.create({
|
||||
keypair: aliceKeypair,
|
||||
domain: 'dict_v1__profile',
|
||||
account: aliceID,
|
||||
|
|
|
@ -2,7 +2,7 @@ const test = require('node:test')
|
|||
const assert = require('node:assert')
|
||||
const p = require('node:util').promisify
|
||||
const Keypair = require('ppppp-keypair')
|
||||
const MsgV3 = require('ppppp-db/msg-v3')
|
||||
const MsgV4 = require('ppppp-db/msg-v4')
|
||||
const { createPeer } = require('./util')
|
||||
|
||||
const aliceKeypair = Keypair.generate('ed25519', 'alice')
|
||||
|
@ -79,10 +79,10 @@ test('sync goal=set with ghostSpan=2', async (t) => {
|
|||
|
||||
// Bob knows a branched off msg that Alice doesn't know
|
||||
{
|
||||
const tangle = new MsgV3.Tangle(moot.id)
|
||||
const tangle = new MsgV4.Tangle(moot.id)
|
||||
tangle.add(moot.id, moot.msg)
|
||||
tangle.add(rec1.id, rec1.msg)
|
||||
const msg = MsgV3.create({
|
||||
const msg = MsgV4.create({
|
||||
keypair: aliceKeypair,
|
||||
domain: 'set_v1__follows',
|
||||
account: aliceID,
|
||||
|
|
Loading…
Reference in New Issue