From 53cd15ecba28170de788e57bcc6d648d2ebec94b Mon Sep 17 00:00:00 2001 From: noffle Date: Tue, 12 Nov 2019 14:47:32 -0800 Subject: [PATCH 1/5] feat(BREAKING): upgrade hypercore (via multifeed) adds the new hypercore7 protocol --- README.md | 6 +++++- index.js | 4 ++-- swarm.js | 2 +- test/mod.js | 4 ++-- test/test.js | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 40185da..379d105 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,15 @@ var cabal = Cabal(storage, key, { db: level('/tmp/bot.db') }) Returns the local user's key (as a hex string). -### var ds = cabal.replicate() +### var ds = cabal.replicate(isInitiator[, opts]) Creates a new, live replication stream. This duplex stream can be piped into any transport expressed as a node stream (tcp, websockets, udp, utp, etc). +Ensure that `isInitiator` to `true` to one side, and `false` on the other. + +`opts` are passed down into the underlying `hypercore` replication. + ### cabal.ready(cb) Call `cb()` when the underlying indexes are caught up. diff --git a/index.js b/index.js index 1bde99f..e8405a7 100644 --- a/index.js +++ b/index.js @@ -195,13 +195,13 @@ Cabal.prototype.swarm = function (opts, cb) { swarm(this, opts, cb) } -Cabal.prototype.replicate = function (opts) { +Cabal.prototype.replicate = function (isInitiator, opts) { opts = opts || {} opts = Object.assign({}, { live: true, maxFeeds: 1024 }, opts) - return this.kcore.replicate(opts) + return this.kcore.replicate(isInitiator, opts) } Cabal.prototype.ready = function (cb) { diff --git a/swarm.js b/swarm.js index 673ad8b..2c896d1 100644 --- a/swarm.js +++ b/swarm.js @@ -34,7 +34,7 @@ module.exports = function (cabal, opts, cb) { blocked[remoteKey] = true connected[remoteKey] = connected[remoteKey] ? connected[remoteKey]+1 : 1 - var r = cabal.replicate() + var r = cabal.replicate(info.initiator) pump(conn, r, conn, function (err) { if (err) debug('ERROR', err) diff --git a/test/mod.js b/test/mod.js index 5dd41da..88025bf 100644 --- a/test/mod.js +++ b/test/mod.js @@ -221,8 +221,8 @@ function sync (cabals, cb) { var a = cabals[i] var b = cabals[(i+1)%cabals.length] ++pending - var ra = a.replicate({ live: false }) - var rb = b.replicate({ live: false }) + var ra = a.replicate(true, { live: false }) + var rb = b.replicate(false, { live: false }) pump(ra, rb, ra, function (err) { if (err) { pending = Infinity diff --git a/test/test.js b/test/test.js index 51abf2f..06831f6 100644 --- a/test/test.js +++ b/test/test.js @@ -244,8 +244,8 @@ test('swarm network replication', function (t) { }) function sync (a, b, cb) { - var r = a.replicate({live:false}) - pump(r, b.replicate({live:false}), r, cb) + var r = a.replicate(true, {live:false}) + pump(r, b.replicate(false, {live:false}), r, cb) } function syncNetwork (a, b, cb) { From da0f27b36186a3805c903b83e4b2e2487322744c Mon Sep 17 00:00:00 2001 From: noffle Date: Tue, 12 Nov 2019 16:31:58 -0800 Subject: [PATCH 2/5] doc: readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 379d105..5ac1f12 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Returns the local user's key (as a hex string). Creates a new, live replication stream. This duplex stream can be piped into any transport expressed as a node stream (tcp, websockets, udp, utp, etc). -Ensure that `isInitiator` to `true` to one side, and `false` on the other. +Ensure that `isInitiator` to `true` to one side, and `false` on the other. This is necessary for setting up the encryption mechanism. `opts` are passed down into the underlying `hypercore` replication. From 4460ae61fadf09944bdf5746ddec9415fcb577d4 Mon Sep 17 00:00:00 2001 From: noffle Date: Tue, 12 Nov 2019 16:32:08 -0800 Subject: [PATCH 3/5] fix: wait for view to be ready on mod api --- views/moderation.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/views/moderation.js b/views/moderation.js index c72f474..75dcae6 100644 --- a/views/moderation.js +++ b/views/moderation.js @@ -102,7 +102,11 @@ module.exports = function (cabal, modKey, db) { } else next() } }) - pump(auth.getMembers(channel), out) + + this.ready(function () { + pump(auth.getMembers(channel), out) + }) + return readonly(out) }, isBanned: function (core, r, cb) { From 4502cf38ed891ef9fb3a13588e4e558c24bd80e0 Mon Sep 17 00:00:00 2001 From: noffle Date: Thu, 14 Nov 2019 17:07:19 -0800 Subject: [PATCH 4/5] upgrade to kappa-core@6 --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 76be869..4926894 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "discovery-swarm": "^6.0.0", "hypercore-crypto": "^1.0.0", "inherits": "^2.0.4", - "kappa-core": "^4.0.0", + "kappa-core": "^6.0.0", "kappa-view-level": "^2.0.1", "level-mem": "^5.0.1", "materialized-group-auth": "^1.1.1", @@ -59,7 +59,6 @@ "devDependencies": { "collect-stream": "^1.2.1", "documentation": "^6.3.2", - "hypercore": "^7.5.1", "pump": "^3.0.0", "random-access-memory": "^3.0.0", "standard": "^11.0.1", From d4a64c5bc632c166fb63e4e917c57fb67d110d58 Mon Sep 17 00:00:00 2001 From: noffle Date: Thu, 14 Nov 2019 17:47:16 -0800 Subject: [PATCH 5/5] chore(travis): add node 10 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4affa59..39444f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: - '8' +- '10' os: - windows - osx