Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to hypercore-protocol@7 via kappa-core #61

Merged
merged 5 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js
node_js:
- '8'
- '10'
os:
- windows
- osx
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. This is necessary for setting up the encryption mechanism.

`opts` are passed down into the underlying `hypercore` replication.

### cabal.ready(cb)

Call `cb()` when the underlying indexes are caught up.
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion views/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down