-
Notifications
You must be signed in to change notification settings - Fork 2
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
Patchwork integration #54
base: master
Are you sure you want to change the base?
Changes from 31 commits
69cf20e
bcf159d
98883aa
82c9c2b
8f26469
68b2d13
dc88834
a3b0106
1d832f3
e45cf26
ddc9f58
f526c63
068db25
ed9b841
ccc662a
192cd0d
27d3018
61a7283
7ec787b
877e0a6
5ba42f3
1f3399f
6a3e3fd
45eac4f
10f7157
77ff194
ae0369f
20d6041
e564791
d6d9d7a
a59d724
2d6e381
771c7ce
f5c494e
c854420
2857197
ad55b44
b359959
f2d21ce
a3bbb62
a603a0e
6b39cfa
ece1f79
0f45ea3
5f8466e
61901a6
3d65df0
7a6b394
8bcfe87
49325a7
4ba4640
817c6e9
dd0c68c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { isForwardRequest, errorParser } = require('ssb-dark-crystal-schema') | ||
|
||
module.exports = function (server) { | ||
return function buildForwardRequest ({ secretOwner, recp }, callback) { | ||
var content = { | ||
type: 'dark-crystal/forward-request', | ||
version: '1.0.0', | ||
secretOwner, | ||
recps: [recp, server.id] | ||
} | ||
|
||
// TODO: check that secretOwner !== recp or sever.id | ||
|
||
if (!isForwardRequest(content)) return callback(isForwardRequest.errors) | ||
|
||
callback(null, content) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const pull = require('pull-stream') | ||
const { isMsg, isFeed } = require('ssb-ref') | ||
|
||
const buildForwardRequest = require('../async/build') | ||
const publish = require('../../lib/publish-msg') | ||
|
||
module.exports = function (server) { | ||
return function publishAll ({ secretOwner, recps }, callback) { | ||
let feedIds = recps | ||
.map(recp => typeof recp === 'string' ? recp : recp.link) | ||
.filter(Boolean) | ||
.filter(isFeed) | ||
|
||
if (feedIds.length !== recps.length) return callback(new Error('forwardRequests publishAll: all recps must be valid feedIds'), recps) | ||
if (!validRecps(feedIds)) return callback(new Error('forwardRequests publishAll: all recps must be valid feedIds', feedIds)) | ||
if (!isFeed(secretOwner)) return callback(new Error('forwardRequests publishAll: invalid feedId', secretOwner)) | ||
|
||
pull( | ||
pull.values(feedIds.map(recp => ({ secretOwner, recp }))), | ||
pull.asyncMap(buildForwardRequest(server)), | ||
pull.collect((err, forwardRequests) => { | ||
if (err) return callback(err) | ||
|
||
publishAll(forwardRequests) | ||
}) | ||
) | ||
|
||
function publishAll (forwardRequests) { | ||
pull( | ||
pull.values(forwardRequests), | ||
pull.asyncMap(publish(server)), | ||
pull.collect(callback) | ||
) | ||
} | ||
} | ||
} | ||
|
||
function validRecps (recps) { | ||
return recps.every(isFeed) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const pull = require('pull-stream') | ||
const next = require('pull-next-query') | ||
const { isForwardRequest } = require('ssb-dark-crystal-schema') | ||
const { isFeedId } = require('ssb-ref') | ||
|
||
module.exports = function (server) { | ||
return function bySecretOwner (secretOwner, opts = {}) { | ||
assert(isFeedId(secretOwner), 'secretOwner must be a valid feedId') | ||
const query = [{ | ||
$filter: { | ||
value: { | ||
timestamp: { $gt: 0 }, // needed for pull-next-query to stepOn on published timestamp | ||
content: { type: 'dark-crystal/forward-request' } | ||
} | ||
} | ||
}, { | ||
$filter: { | ||
value: { | ||
content: { secretOwner } | ||
} | ||
} | ||
}] | ||
|
||
const _opts = Object.assign({}, { query, limit: 100 }, opts) | ||
|
||
return pull( | ||
next(server.query.read, _opts), | ||
pull.filter(isForwardRequest) | ||
) | ||
} | ||
} | ||
|
||
function assert (test, message) { | ||
if (!test) throw new Error(message || 'AssertionError') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const pull = require('pull-stream') | ||
// const next = require('pull-next-query') | ||
const ShardsFromOthers = require('../../shard/pull/from-others') | ||
const forwardRequestBySecretOwner = require('./by-secret-owner') | ||
const { get } = require('lodash') | ||
|
||
module.exports = function (server) { | ||
const shardsFromOthers = ShardsFromOthers(server) | ||
return function forOwnShards (opts = {}) { | ||
return pull( | ||
shardsFromOthers(), | ||
// This query is specific to recovering SSB identities | ||
pull.filter(shard => get(shard, 'value.content.attachment.name') === 'gossip.json'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we can't dynamically pass in filter functions, that way we don't have make this so restrictive... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh i like that idea There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KGibb8 so i just changed it that it takes a filter function as an argument. probably it would be neater if this was a property of the |
||
pull.unique(s => get(s, 'value.author')), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what exactly this is this doing? |
||
pull.map(shard => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work, calling back with the forward-requests from the collect callback expects an asynchronous action to follow, while returning the pull stream expects a synchronous action to follow. We need to tell the pull stream to wait for the action to complete before calling back with the new dataset. Therefore this needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 good call |
||
pull( | ||
forwardRequestBySecretOwner(get(shard, 'value.author')), | ||
pull.collect((err, forwards) => { | ||
if (err) return err | ||
return forwards | ||
}) | ||
) | ||
}) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const pull = require('pull-stream') | ||
const next = require('pull-next-query') | ||
const { isForwardRequest } = require('ssb-dark-crystal-schema') | ||
|
||
module.exports = function (server) { | ||
return function friends (opts = {}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change! |
||
const query = [{ | ||
$filter: { | ||
value: { | ||
timestamp: { $gt: 0 }, // needed for pull-next-query to stepOn on published timestamp | ||
content: { type: 'dark-crystal/forward-request' } | ||
} | ||
} | ||
}, { | ||
$filter: { | ||
value: { | ||
author: server.id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If its from others, shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doh! |
||
} | ||
} | ||
}] | ||
|
||
const _opts = Object.assign({}, { query, limit: 100 }, opts) | ||
|
||
return pull( | ||
next(server.query.read, _opts), | ||
pull.filter(isForwardRequest) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const pull = require('pull-stream') | ||
const next = require('pull-next-query') | ||
const { isForwardRequest } = require('ssb-dark-crystal-schema') | ||
|
||
module.exports = function (server) { | ||
return function friends (opts = {}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. left over from copy/paste, incorrect name! :) |
||
const query = [{ | ||
$filter: { | ||
value: { | ||
timestamp: { $gt: 0 }, // needed for pull-next-query to stepOn on published timestamp | ||
content: { type: 'dark-crystal/forward-request' } | ||
} | ||
} | ||
}, { | ||
$filter: { | ||
value: { | ||
author: { $ne: server.id } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inverse of the previous one, if its from self, shouldn't it be where the author is me? That said, I don't see where we'd use this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realising now, we will need |
||
} | ||
} | ||
}] | ||
|
||
const _opts = Object.assign({}, { query, limit: 100 }, opts) | ||
|
||
return pull( | ||
next(server.query.read, _opts), | ||
pull.filter(isForwardRequest) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function assert (test, message) { | ||
if (!test) throw new Error(message || 'AssertionError') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const assert = require('./assert') | ||
const { isBlobId } = require('ssb-ref') | ||
|
||
module.exports = function unpackLink (link) { | ||
const index = link.indexOf('?') | ||
const blobId = link.substring(0, index) | ||
const blobKey = link.substring(index + 1) | ||
assert(((index > 0) && (blobKey.length)), 'Blob not encrypted') | ||
// TODO: test for well formed blob key | ||
assert((isBlobId(blobId)), 'attachment contains invalid blob reference') | ||
return { blobId, blobKey } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is
forSecretOwner
rather thanbySecretOwner
, because we're looking for all requests that have been created by person A, who may or may not be person B, and as person C, its a big semantic difference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im happy to change it. i was imaging its short for 'indexed by secret owner', like we've got a query for shards indexed 'by root'. but if you are seeing it as 'forward requests authored by secret owner' then thats not what we want.