From 1801a7ed04b5a4d428486d65bfcb6af3f384f3eb Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 24 Mar 2023 14:36:19 +0100 Subject: [PATCH 01/16] Add stay-on-exclude-other test --- test/exclude-members.test.js | 115 +++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 2c8f5c6..9b1a25a 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -10,6 +10,7 @@ const { fromMessageSigil } = require('ssb-uri2') const Testbot = require('./helpers/testbot') const replicate = require('./helpers/replicate') const countGroupFeeds = require('./helpers/count-group-feeds') +const pull = require('pull-stream') test('add and remove a person, post on the new feed', async (t) => { // Alice's feeds should look like @@ -154,3 +155,117 @@ test('add and remove a person, post on the new feed', async (t) => { await p(alice.close)(true) await p(bob.close)(true) }) + +test("If you're not the excluder nor the excludee then you should still be in the group and have access to the new epoch", async (t) => { + // alice creates the group. adds bob and carol. removes bob. + // bob gets added and is removed + // carol stays in the group + const alice = Testbot({ + keys: ssbKeys.generate(null, 'alice'), + mfSeed: Buffer.from( + '000000000000000000000000000000000000000000000000000000000000a1ce', + 'hex' + ), + }) + const bob = Testbot({ + keys: ssbKeys.generate(null, 'bob'), + mfSeed: Buffer.from( + '0000000000000000000000000000000000000000000000000000000000000b0b', + 'hex' + ), + }) + const carol = Testbot({ + keys: ssbKeys.generate(null, 'carol'), + mfSeed: Buffer.from( + '00000000000000000000000000000000000000000000000000000000000ca201', + 'hex' + ), + }) + + await alice.tribes2.start() + await bob.tribes2.start() + await carol.tribes2.start() + t.pass('tribes2 started for everyone') + + await p(alice.metafeeds.findOrCreate)() + const bobRoot = await p(bob.metafeeds.findOrCreate)() + const carolRoot = await p(carol.metafeeds.findOrCreate)() + + await replicate(alice, bob) + await replicate(alice, carol) + await replicate(bob, carol) + t.pass('everyone replicates their trees') + + const { id: groupId, writeKey: writeKey1 } = await alice.tribes2 + .create() + .catch((err) => t.error(err, 'alice failed to create group')) + + await replicate(alice, carol) + + await alice.tribes2 + .addMembers(groupId, [bobRoot.id, carolRoot.id]) + .catch((err) => t.error(err, 'add bob fail')) + + await replicate(alice, carol) + + await carol.tribes2.acceptInvite(groupId) + + await replicate(alice, carol) + + const { + value: { author: firstFeedId }, + } = await carol.tribes2 + .publish({ + type: 'test', + text: 'first post', + recps: [groupId], + }) + .catch((err) => t.error(err, 'carol failed to publish on first feed')) + + await alice.tribes2 + .excludeMembers(groupId, [bobRoot.id]) + .catch((err) => t.error(err, 'remove member fail')) + + await replicate(alice, carol) + + const { + value: { author: secondFeedId }, + } = await carol.tribes2 + .publish({ + type: 'test', + text: 'second post', + recps: [groupId], + }) + .catch(t.fail) + + t.notEquals( + secondFeedId, + firstFeedId, + 'feed for second publish is different to first publish' + ) + + const { writeKey: writeKey2 } = await carol.tribes2.get(groupId) + + const branches = await pull( + carol.metafeeds.branchStream({ root: carolRoot, old: true, live: false }), + pull.toPromise() + ) + + const groupFeedPurposes = branches + .filter((branch) => branch.length === 4) + .map((branch) => branch[3]) + .filter((feed) => feed.recps && feed.purpose.length === 44) + .map((feed) => feed.purpose) + + t.true( + groupFeedPurposes.includes(writeKey1.key.toString('base64')), + 'Carol has a feed for the old key' + ) + t.true( + groupFeedPurposes.includes(writeKey2.key.toString('base64')), + 'Carol has a feed for the new key' + ) + + await p(alice.close)(true) + await p(bob.close)(true) +}) From 97def6f6fcd6bbd3f57588d5325ecf00679d1516 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 24 Mar 2023 15:01:43 +0100 Subject: [PATCH 02/16] Give alice carol's first feed to enable exclusion --- test/exclude-members.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 9b1a25a..d7951ca 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -222,6 +222,8 @@ test("If you're not the excluder nor the excludee then you should still be in th }) .catch((err) => t.error(err, 'carol failed to publish on first feed')) + await replicate(alice, carol) + await alice.tribes2 .excludeMembers(groupId, [bobRoot.id]) .catch((err) => t.error(err, 'remove member fail')) @@ -248,7 +250,7 @@ test("If you're not the excluder nor the excludee then you should still be in th const branches = await pull( carol.metafeeds.branchStream({ root: carolRoot, old: true, live: false }), - pull.toPromise() + pull.collectAsPromise() ) const groupFeedPurposes = branches From 79b7553d6d040ce42ded12e945899152635e9f40 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 24 Mar 2023 16:48:28 +0100 Subject: [PATCH 03/16] Try to get epoch-detection to work --- index.js | 64 ++++++++++++++++++++++++++++++++++++ test/exclude-members.test.js | 3 ++ 2 files changed, 67 insertions(+) diff --git a/index.js b/index.js index 4bb5575..4148506 100644 --- a/index.js +++ b/index.js @@ -424,6 +424,70 @@ module.exports = { if (err) return cb(clarify(err, 'Error finding or creating additions feed when starting ssb-tribes2')) return cb() }) + + // look for new epochs that we're added to + ssb.metafeeds.findOrCreate((err, myRoot) => { + // prettier-ignore + if (err) return cb(clarify(err, 'todo')) + + pull( + ssb.db.query( + // TODO: does this output new stuff if we accept an invite to an old epoch and then find additions to newer epochs? + where(and(isDecrypted('box2'), type('group/add-member'))), + live({ old: true }), + toPullStream() + ), + // groups/epochs we're added to + pull.filter((msg) => msg.value?.content?.recps?.includes(myRoot.id)), + // to find new epochs we only check groups we've accepted the invite to + paraMap((msg, cb) => { + pull( + ssb.box2.listGroupIds(), + pull.collect((err, groupIds) => { + // prettier-ignore + if (err) return cb(clarify(err, 'todo')) + + if (groupIds.includes(msg.value?.content?.recps?.[0])) { + return cb(null, msg) + } else { + return cb() + } + }) + ) + }), + pull.filter(Boolean), + pull.drain( + (msg) => { + const groupId = msg.value?.content?.recps?.[0] + + const newKey = Buffer.from(msg.value?.content?.groupKey, 'base64') + ssb.box2.addGroupInfo(groupId, { key: newKey }, (err) => { + // prettier-ignore + if (err) return cb(clarify(err, 'todo')) + + const newKeyPick = { + key: newKey, + scheme: keySchemes.private_group, + } + // TODO: naively guessing that this is the latest key for now + ssb.box2.pickGroupWriteKey(groupId, newKeyPick, (err) => { + // prettier-ignore + if (err) return cb(clarify(err, "todo")) + + ssb.db.reindexEncrypted((err) => { + // prettier-ignore + if (err) cb(clarify(err, 'todo')) + }) + }) + }) + }, + (err) => { + // prettier-ignore + if (err) return cb(clarify(err, 'todo')) + } + ) + ) + }) } return { diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index d7951ca..3c9ce39 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -230,6 +230,9 @@ test("If you're not the excluder nor the excludee then you should still be in th await replicate(alice, carol) + // TODO: maybe remove? + await p(setTimeout)(5000) + const { value: { author: secondFeedId }, } = await carol.tribes2 From e4128d1c8602447126499315a8f7a5905aa08bc9 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 30 Mar 2023 20:36:18 +0200 Subject: [PATCH 04/16] Add debug logs --- index.js | 15 ++++++++++++--- test/exclude-members.test.js | 19 +++++++++++++++---- test/helpers/replicate.js | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 4148506..7f095e1 100644 --- a/index.js +++ b/index.js @@ -245,10 +245,11 @@ module.exports = { groupId, remainingMembers, reAddOpts, - (err) => { + (err, reAddMsg) => { // prettier-ignore if (err) return cb(clarify(err, "Couldn't re-add remaining members when excluding members")) - return cb() + //TODO: we probably don't want to return this exactly + return cb(null, reAddMsg) } ) }) @@ -438,9 +439,14 @@ module.exports = { toPullStream() ), // groups/epochs we're added to - pull.filter((msg) => msg.value?.content?.recps?.includes(myRoot.id)), + pull.filter((msg) => { + console.log('found an addition', myRoot.id, msg.value.content.recps) + return msg.value?.content?.recps?.includes(myRoot.id) + }), // to find new epochs we only check groups we've accepted the invite to paraMap((msg, cb) => { + console.log('i am', myRoot.id) + console.log('found an addition of me', msg.value) pull( ssb.box2.listGroupIds(), pull.collect((err, groupIds) => { @@ -458,6 +464,7 @@ module.exports = { pull.filter(Boolean), pull.drain( (msg) => { + console.log("addition was for a group i've already joined") const groupId = msg.value?.content?.recps?.[0] const newKey = Buffer.from(msg.value?.content?.groupKey, 'base64') @@ -474,6 +481,8 @@ module.exports = { // prettier-ignore if (err) return cb(clarify(err, "todo")) + console.log('picked new key') + ssb.db.reindexEncrypted((err) => { // prettier-ignore if (err) cb(clarify(err, 'todo')) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 3c9ce39..35d81b4 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -221,17 +221,26 @@ test("If you're not the excluder nor the excludee then you should still be in th recps: [groupId], }) .catch((err) => t.error(err, 'carol failed to publish on first feed')) + if (firstFeedId) t.pass('carol posted first post') - await replicate(alice, carol) + await replicate(alice, carol).catch(t.error) - await alice.tribes2 + const excludeMsg = await alice.tribes2 .excludeMembers(groupId, [bobRoot.id]) + .then((res) => { + t.pass('alice excluded bob') + return res + }) .catch((err) => t.error(err, 'remove member fail')) - await replicate(alice, carol) + await replicate(alice, carol).catch(t.error) // TODO: maybe remove? - await p(setTimeout)(5000) + await p(setTimeout)(10000) + + const carolHasExcludeMsg = await p(carol.db.getMsg)(excludeMsg.key) + + console.log('carol has exclude', carolHasExcludeMsg) const { value: { author: secondFeedId }, @@ -242,6 +251,7 @@ test("If you're not the excluder nor the excludee then you should still be in th recps: [groupId], }) .catch(t.fail) + if (secondFeedId) t.pass('carol posted second post') t.notEquals( secondFeedId, @@ -273,4 +283,5 @@ test("If you're not the excluder nor the excludee then you should still be in th await p(alice.close)(true) await p(bob.close)(true) + await p(carol.close)(true) }) diff --git a/test/helpers/replicate.js b/test/helpers/replicate.js index b094292..d78d409 100644 --- a/test/helpers/replicate.js +++ b/test/helpers/replicate.js @@ -42,6 +42,8 @@ module.exports = async function replicate(person1, person2) { await retryUntil(async () => { const newClock1 = await p(person1.getVectorClock)() const newClock2 = await p(person2.getVectorClock)() + //console.log('newClock1', newClock1) + //console.log('newClock2', newClock2) return deepEqual(newClock1, newClock2) }) From 0ef883cccf2323a08466964d18abb850b3040e0f Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 5 Apr 2023 15:12:37 +0200 Subject: [PATCH 05/16] more logs --- index.js | 4 ++-- test/exclude-members.test.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index e4f43c8..2fdf869 100644 --- a/index.js +++ b/index.js @@ -186,7 +186,7 @@ module.exports = { tangles: ['members'], isValid: isExclude, } - publish(excludeContent, excludeOpts, (err) => { + publish(excludeContent, excludeOpts, (err, excludeMsg) => { // prettier-ignore if (err) return cb(clarify(err, 'Failed to publish exclude msg')) @@ -235,7 +235,7 @@ module.exports = { // prettier-ignore if (err) return cb(clarify(err, "Couldn't re-add remaining members when excluding members")) //TODO: we probably don't want to return this exactly - return cb(null, reMsg) + return cb(null, { excludeMsg, reAddMsg: reMsg }) }) }) }) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 5c6294d..6cbf40d 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -176,7 +176,7 @@ test('add and remove a person, post on the new feed', async (t) => { await p(bob.close)(true) }) -test("If you're not the excluder nor the excludee then you should still be in the group and have access to the new epoch", async (t) => { +test.only("If you're not the excluder nor the excludee then you should still be in the group and have access to the new epoch", async (t) => { // alice creates the group. adds bob and carol. removes bob. // bob gets added and is removed // carol stays in the group @@ -245,7 +245,7 @@ test("If you're not the excluder nor the excludee then you should still be in th await replicate(alice, carol).catch(t.error) - const excludeMsg = await alice.tribes2 + const { reAddMsg } = await alice.tribes2 .excludeMembers(groupId, [bobRoot.id]) .then((res) => { t.pass('alice excluded bob') @@ -258,9 +258,9 @@ test("If you're not the excluder nor the excludee then you should still be in th // TODO: maybe remove? await p(setTimeout)(10000) - const carolHasExcludeMsg = await p(carol.db.getMsg)(excludeMsg.key) + const carolHasReAddMsg = await p(carol.db.getMsg)(reAddMsg.key) - console.log('carol has exclude', carolHasExcludeMsg) + console.log('carol has readd', carolHasReAddMsg) const { value: { author: secondFeedId }, @@ -286,12 +286,19 @@ test("If you're not the excluder nor the excludee then you should still be in th pull.collectAsPromise() ) + console.log('carol branches', branches) + const groupFeedPurposes = branches .filter((branch) => branch.length === 4) .map((branch) => branch[3]) .filter((feed) => feed.recps && feed.purpose.length === 44) .map((feed) => feed.purpose) + console.log({ + groupFeedPurposes, + key1: writeKey1.key.toString('base64'), + key2: writeKey2.key.toString('base64'), + }) t.true( groupFeedPurposes.includes(writeKey1.key.toString('base64')), 'Carol has a feed for the old key' From 965a7ebefbb29cd9865d7e3e2b698efac9d64c0d Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 5 Apr 2023 15:22:15 +0200 Subject: [PATCH 06/16] Always run ci --- .github/workflows/node.js.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index fc149e2..c263265 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -6,9 +6,9 @@ name: CI on: push: - branches: [master] + branches: [**] pull_request: - branches: [master] + branches: [**] jobs: licenses: From 91b8beb5fa7c70d96f6f268a2f9e3fbe58291de2 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 5 Apr 2023 15:23:43 +0200 Subject: [PATCH 07/16] Run ci on all branches --- .github/workflows/node.js.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c263265..9570f59 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -6,9 +6,11 @@ name: CI on: push: - branches: [**] + branches: + - '**' pull_request: - branches: [**] + branches: + - '**' jobs: licenses: From 7e1ccbd6a109101b6e0a59d58756646fc2c16f02 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 5 Apr 2023 15:27:50 +0200 Subject: [PATCH 08/16] Simplify ci branch matching --- .github/workflows/node.js.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9570f59..69d6b14 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -4,13 +4,7 @@ name: CI -on: - push: - branches: - - '**' - pull_request: - branches: - - '**' +on: push jobs: licenses: From 37453497981c8197f9eec6030bb6fea717c548ea Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 5 Apr 2023 18:18:57 +0200 Subject: [PATCH 09/16] Actually use the root id when querying --- test/exclude-members.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 6cbf40d..9dc3d02 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -282,7 +282,11 @@ test.only("If you're not the excluder nor the excludee then you should still be const { writeKey: writeKey2 } = await carol.tribes2.get(groupId) const branches = await pull( - carol.metafeeds.branchStream({ root: carolRoot, old: true, live: false }), + carol.metafeeds.branchStream({ + root: carolRoot.id, + old: true, + live: false, + }), pull.collectAsPromise() ) From 86b74cf8be060a55366fabf2dc5047d563daa559 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 5 Apr 2023 18:21:57 +0200 Subject: [PATCH 10/16] Remove only --- test/exclude-members.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 9dc3d02..e848d44 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -176,7 +176,7 @@ test('add and remove a person, post on the new feed', async (t) => { await p(bob.close)(true) }) -test.only("If you're not the excluder nor the excludee then you should still be in the group and have access to the new epoch", async (t) => { +test("If you're not the excluder nor the excludee then you should still be in the group and have access to the new epoch", async (t) => { // alice creates the group. adds bob and carol. removes bob. // bob gets added and is removed // carol stays in the group From d3073f2217860a27852806ac5a43bc11e9077a40 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 6 Apr 2023 10:24:03 +0200 Subject: [PATCH 11/16] Carol shouldn't have to post before being re-added --- test/exclude-members.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index e848d44..412ce99 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -243,8 +243,6 @@ test("If you're not the excluder nor the excludee then you should still be in th .catch((err) => t.error(err, 'carol failed to publish on first feed')) if (firstFeedId) t.pass('carol posted first post') - await replicate(alice, carol).catch(t.error) - const { reAddMsg } = await alice.tribes2 .excludeMembers(groupId, [bobRoot.id]) .then((res) => { From e8a1986720ffb739067990b6bb2c9e9ba0ee97d0 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 6 Apr 2023 10:46:40 +0200 Subject: [PATCH 12/16] Remove console logs --- index.js | 13 +++---------- test/exclude-members.test.js | 13 +------------ 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 2fdf869..e905af8 100644 --- a/index.js +++ b/index.js @@ -186,7 +186,7 @@ module.exports = { tangles: ['members'], isValid: isExclude, } - publish(excludeContent, excludeOpts, (err, excludeMsg) => { + publish(excludeContent, excludeOpts, (err) => { // prettier-ignore if (err) return cb(clarify(err, 'Failed to publish exclude msg')) @@ -231,11 +231,10 @@ module.exports = { // prettier-ignore if (err) return cb(clarify(err, "Couldn't post init msg on new epoch when excluding members")) - addMembers(groupId, remainingMembers, {}, (err, reMsg) => { + addMembers(groupId, remainingMembers, {}, (err) => { // prettier-ignore if (err) return cb(clarify(err, "Couldn't re-add remaining members when excluding members")) - //TODO: we probably don't want to return this exactly - return cb(null, { excludeMsg, reAddMsg: reMsg }) + return cb() }) }) }) @@ -423,13 +422,10 @@ module.exports = { ), // groups/epochs we're added to pull.filter((msg) => { - console.log('found an addition', myRoot.id, msg.value.content.recps) return msg.value?.content?.recps?.includes(myRoot.id) }), // to find new epochs we only check groups we've accepted the invite to paraMap((msg, cb) => { - console.log('i am', myRoot.id) - console.log('found an addition of me', msg.value) pull( ssb.box2.listGroupIds(), pull.collect((err, groupIds) => { @@ -447,7 +443,6 @@ module.exports = { pull.filter(Boolean), pull.drain( (msg) => { - console.log("addition was for a group i've already joined") const groupId = msg.value?.content?.recps?.[0] const newKey = Buffer.from(msg.value?.content?.groupKey, 'base64') @@ -464,8 +459,6 @@ module.exports = { // prettier-ignore if (err) return cb(clarify(err, "todo")) - console.log('picked new key') - ssb.db.reindexEncrypted((err) => { // prettier-ignore if (err) cb(clarify(err, 'todo')) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 412ce99..eb87310 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -243,7 +243,7 @@ test("If you're not the excluder nor the excludee then you should still be in th .catch((err) => t.error(err, 'carol failed to publish on first feed')) if (firstFeedId) t.pass('carol posted first post') - const { reAddMsg } = await alice.tribes2 + await alice.tribes2 .excludeMembers(groupId, [bobRoot.id]) .then((res) => { t.pass('alice excluded bob') @@ -256,10 +256,6 @@ test("If you're not the excluder nor the excludee then you should still be in th // TODO: maybe remove? await p(setTimeout)(10000) - const carolHasReAddMsg = await p(carol.db.getMsg)(reAddMsg.key) - - console.log('carol has readd', carolHasReAddMsg) - const { value: { author: secondFeedId }, } = await carol.tribes2 @@ -288,19 +284,12 @@ test("If you're not the excluder nor the excludee then you should still be in th pull.collectAsPromise() ) - console.log('carol branches', branches) - const groupFeedPurposes = branches .filter((branch) => branch.length === 4) .map((branch) => branch[3]) .filter((feed) => feed.recps && feed.purpose.length === 44) .map((feed) => feed.purpose) - console.log({ - groupFeedPurposes, - key1: writeKey1.key.toString('base64'), - key2: writeKey2.key.toString('base64'), - }) t.true( groupFeedPurposes.includes(writeKey1.key.toString('base64')), 'Carol has a feed for the old key' From 2fcf537c143f4482db0b867eaf53146e6b6f047d Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 7 Apr 2023 12:45:16 +0200 Subject: [PATCH 13/16] Clarify errs --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index e905af8..e5ce999 100644 --- a/index.js +++ b/index.js @@ -411,7 +411,7 @@ module.exports = { // look for new epochs that we're added to ssb.metafeeds.findOrCreate((err, myRoot) => { // prettier-ignore - if (err) return cb(clarify(err, 'todo')) + if (err) return cb(clarify(err, 'Error getting own root in start()')) pull( ssb.db.query( @@ -430,7 +430,7 @@ module.exports = { ssb.box2.listGroupIds(), pull.collect((err, groupIds) => { // prettier-ignore - if (err) return cb(clarify(err, 'todo')) + if (err) return cb(clarify(err, "Error getting groups we're already in when looking for new epochs")) if (groupIds.includes(msg.value?.content?.recps?.[0])) { return cb(null, msg) @@ -448,7 +448,7 @@ module.exports = { const newKey = Buffer.from(msg.value?.content?.groupKey, 'base64') ssb.box2.addGroupInfo(groupId, { key: newKey }, (err) => { // prettier-ignore - if (err) return cb(clarify(err, 'todo')) + if (err) return cb(clarify(err, 'Error adding new epoch key that we found')) const newKeyPick = { key: newKey, @@ -457,18 +457,18 @@ module.exports = { // TODO: naively guessing that this is the latest key for now ssb.box2.pickGroupWriteKey(groupId, newKeyPick, (err) => { // prettier-ignore - if (err) return cb(clarify(err, "todo")) + if (err) return cb(clarify(err, 'Error switching to new epoch key that we found')) ssb.db.reindexEncrypted((err) => { // prettier-ignore - if (err) cb(clarify(err, 'todo')) + if (err) cb(clarify(err, 'Error reindexing after finding new epoch')) }) }) }) }, (err) => { // prettier-ignore - if (err) return cb(clarify(err, 'todo')) + if (err) return cb(clarify(err, "Error finding new epochs we've been added to")) } ) ) From 48dc0ce096d315e550447ec0eb6466182de327ec Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 7 Apr 2023 13:00:53 +0200 Subject: [PATCH 14/16] Shorten wait to find epochs --- test/exclude-members.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index eb87310..f70cbf2 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -253,8 +253,8 @@ test("If you're not the excluder nor the excludee then you should still be in th await replicate(alice, carol).catch(t.error) - // TODO: maybe remove? - await p(setTimeout)(10000) + // let carol find the new epoch and switch to the new key + await p(setTimeout)(500) const { value: { author: secondFeedId }, From 2514344e7ff39e7d5a978e931a3c6ad6b61dbae8 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 12 Apr 2023 22:31:13 +0200 Subject: [PATCH 15/16] Check schema on msg instead of ?. --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e5ce999..e5d4eb4 100644 --- a/index.js +++ b/index.js @@ -420,9 +420,10 @@ module.exports = { live({ old: true }), toPullStream() ), + pull.filter(isAddMember), // groups/epochs we're added to pull.filter((msg) => { - return msg.value?.content?.recps?.includes(myRoot.id) + return msg.value.content.recps.includes(myRoot.id) }), // to find new epochs we only check groups we've accepted the invite to paraMap((msg, cb) => { @@ -432,7 +433,7 @@ module.exports = { // prettier-ignore if (err) return cb(clarify(err, "Error getting groups we're already in when looking for new epochs")) - if (groupIds.includes(msg.value?.content?.recps?.[0])) { + if (groupIds.includes(msg.value.content.recps[0])) { return cb(null, msg) } else { return cb() @@ -443,9 +444,9 @@ module.exports = { pull.filter(Boolean), pull.drain( (msg) => { - const groupId = msg.value?.content?.recps?.[0] + const groupId = msg.value.content.recps[0] - const newKey = Buffer.from(msg.value?.content?.groupKey, 'base64') + const newKey = Buffer.from(msg.value.content.groupKey, 'base64') ssb.box2.addGroupInfo(groupId, { key: newKey }, (err) => { // prettier-ignore if (err) return cb(clarify(err, 'Error adding new epoch key that we found')) From c81773c49819ea503707061da0a55a1ebddf8bc7 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 12 Apr 2023 22:35:19 +0200 Subject: [PATCH 16/16] Run paramap in para --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e5d4eb4..2e555b0 100644 --- a/index.js +++ b/index.js @@ -440,7 +440,7 @@ module.exports = { } }) ) - }), + }, 4), pull.filter(Boolean), pull.drain( (msg) => {