-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from ssbc/partial-replication-changes
Partial replication changes
- Loading branch information
Showing
17 changed files
with
1,069 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const SSBURI = require('ssb-uri2') | ||
const bendyButt = require('ssb-bendy-butt') | ||
|
||
module.exports = { | ||
name: 'bendybutt-v1', | ||
prepareForIsFeed(sbot, feedId, cb) { | ||
cb() | ||
}, | ||
// used in request, block, cleanClock, sbot.post, vectorClock | ||
isFeed (sbot, feedId) { | ||
return SSBURI.isBendyButtV1FeedSSBURI(feedId) | ||
}, | ||
getAtSequence (sbot, pair, cb) { | ||
sbot.getAtSequence([pair.id, pair.sequence], (err, msg) => { | ||
cb(err, msg ? bendyButt.encode(msg.value) : null) | ||
}) | ||
}, | ||
appendMsg (sbot, msgVal, cb) { | ||
sbot.add(bendyButt.decode(msgVal), (err, msg) => { | ||
cb(err && err.fatal ? err : null, msg) | ||
}) | ||
}, | ||
convertMsg (sbot, msgVal, cb) { | ||
cb(null, bendyButt.encode(msgVal)) | ||
}, | ||
// used in vectorClock | ||
isReady (sbot) { | ||
return Promise.resolve(true) | ||
}, | ||
|
||
// used in ebt:stream to distinguish between messages and notes | ||
isMsg (bbVal) { | ||
if (Buffer.isBuffer(bbVal)) { | ||
const msgVal = bendyButt.decode(bbVal) | ||
return msgVal && SSBURI.isBendyButtV1FeedSSBURI(msgVal.author) | ||
} else { | ||
return bbVal && SSBURI.isBendyButtV1FeedSSBURI(bbVal.author) | ||
} | ||
}, | ||
// used in ebt:events | ||
getMsgAuthor (bbVal) { | ||
if (Buffer.isBuffer(bbVal)) { return bendyButt.decode(bbVal).author } else { return bbVal.author } | ||
}, | ||
// used in ebt:events | ||
getMsgSequence (bbVal) { | ||
if (Buffer.isBuffer(bbVal)) { return bendyButt.decode(bbVal).sequence } else { return bbVal.sequence } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const ref = require('ssb-ref') | ||
|
||
module.exports = { | ||
name: 'classic', | ||
prepareForIsFeed(sbot, feedId, cb) { | ||
cb() | ||
}, | ||
// used in request, block, cleanClock, sbot.post, vectorClock | ||
isFeed (sbot, feedId) { | ||
return ref.isFeed(feedId) | ||
}, | ||
getAtSequence (sbot, pair, cb) { | ||
sbot.getAtSequence([pair.id, pair.sequence], (err, msg) => { | ||
cb(err, msg ? msg.value : null) | ||
}) | ||
}, | ||
appendMsg (sbot, msgVal, cb) { | ||
sbot.add(msgVal, (err, msg) => { | ||
cb(err && err.fatal ? err : null, msg) | ||
}) | ||
}, | ||
// used in onAppend | ||
convertMsg (sbot, msgVal, cb) { | ||
cb(null, msgVal) | ||
}, | ||
// used in vectorClock | ||
isReady (sbot) { | ||
return Promise.resolve(true) | ||
}, | ||
|
||
// used in ebt:stream to distinguish between messages and notes | ||
isMsg (msgVal) { | ||
return Number.isInteger(msgVal.sequence) && msgVal.sequence > 0 && | ||
ref.isFeed(msgVal.author) && msgVal.content | ||
}, | ||
// used in ebt:events | ||
getMsgAuthor (msgVal) { | ||
return msgVal.author | ||
}, | ||
// used in ebt:events | ||
getMsgSequence (msgVal) { | ||
return msgVal.sequence | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const pify = require('promisify-4loc') | ||
const ref = require('ssb-ref') | ||
const { QL0 } = require('ssb-subset-ql') | ||
|
||
module.exports = { | ||
name: 'indexed', | ||
prepareForIsFeed(sbot, feedId, cb) { | ||
sbot.metafeeds.ensureLoaded(feedId, cb) | ||
}, | ||
isFeed (sbot, author) { | ||
const info = sbot.metafeeds.findByIdSync(author) | ||
return info && info.feedpurpose === 'index' | ||
}, | ||
appendMsg (sbot, msgTuple, cb) { | ||
const [msgVal, payload] = msgTuple | ||
sbot.db.addTransaction([msgVal], [payload], cb) | ||
}, | ||
getAtSequence (sbot, pair, cb) { | ||
sbot.getAtSequence([pair.id, pair.sequence], (err, msg) => { | ||
if (err) return cb(err) | ||
|
||
module.exports.convertMsg(sbot, msg.value, cb) | ||
}) | ||
}, | ||
convertMsg (sbot, msgVal, cb) { | ||
const { sequence } = msgVal.content.indexed | ||
const authorInfo = sbot.metafeeds.findByIdSync(msgVal.author) | ||
if (!authorInfo) return cb(new Error('Unknown author:' + msgVal.author)) | ||
const { author } = QL0.parse(authorInfo.metadata.query) | ||
sbot.getAtSequence([author, sequence], (err, indexedMsg) => { | ||
if (err) return cb(err) | ||
|
||
cb(null, [msgVal, indexedMsg.value]) | ||
}) | ||
}, | ||
isReady (sbot) { | ||
return pify(sbot.metafeeds.loadState)() | ||
}, | ||
isMsg (msgTuple) { | ||
if (Array.isArray(msgTuple) && msgTuple.length === 2) { | ||
const [msgVal, payload] = msgTuple | ||
return Number.isInteger(msgVal.sequence) && msgVal.sequence > 0 && | ||
ref.isFeed(msgVal.author) && msgVal.content | ||
} else | ||
return false | ||
}, | ||
getMsgAuthor (msgTuple) { | ||
return msgTuple[0].author | ||
}, | ||
getMsgSequence (msgTuple) { | ||
return msgTuple[0].sequence | ||
} | ||
} |
Oops, something went wrong.