-
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
Open
ameba23
wants to merge
53
commits into
master
Choose a base branch
from
patchwork-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 37 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
69cf20e
send each shard with attachment if attached
bcf159d
remove log
98883aa
minimal assert function
ameba23 82c9c2b
function for unpacking blob ref and encryption key
ameba23 8f26469
share method handles attachment
ameba23 68b2d13
test for share method handles attachment
ameba23 dc88834
add test for unencrypted blob ref
ameba23 a3b0106
fix error handling
ameba23 1d832f3
shared also contains attachment name
ameba23 e45cf26
update test
ameba23 ddc9f58
add forward-request publish method
ameba23 f526c63
add test for forward-request publish method
ameba23 068db25
add query for forwardRequest from others
ameba23 ed9b841
add query for forwardRequest from yourself
ameba23 ccc662a
fix type being camel case
ameba23 192cd0d
add query for forwardRequest by author
ameba23 27d3018
expose forwardRequests methods
ameba23 61a7283
query for forwardRequest by secret owner
ameba23 7ec787b
query for forwardRequests relating to shards you hold
ameba23 877e0a6
export method
ameba23 5ba42f3
use lodash get
ameba23 1f3399f
bug in methods.js
ameba23 6a3e3fd
typo
ameba23 45eac4f
split publish into publishAll function
10f7157
add publishAll to methods API
77ff194
normalise recps as feedIds
ae0369f
find only forward requests relating to shards for SSB identities
ameba23 20d6041
Merge pull request #52 from blockades/add-blob-reference-on-shard-pub…
ameba23 e564791
Merge pull request #53 from blockades/forward-request
ameba23 d6d9d7a
fix forward-request test
a59d724
export forwardRequest sync
2d6e381
use aysncMap in forOwnShards
ameba23 771c7ce
fix from-others query
ameba23 f5c494e
fix from-self query
ameba23 c854420
change function name
ameba23 2857197
forOwnShards query takes filter as argument
ameba23 ad55b44
forOwnShards query filter argument is optional
ameba23 b359959
forward messages contain id of related shard message
ameba23 f2d21ce
forward messages contain id of forwardRequest if present
ameba23 a3bbb62
lint
ameba23 a603a0e
fix filter function
6b39cfa
link is required param by schema, not blobId
ece1f79
comment filter and pass pull/for-own-shards to API
0f45ea3
forward publish method takes an object, which may contain a requestId
ameba23 5f8466e
update test
ameba23 61901a6
update v2 test
ameba23 3d65df0
fix share method test for link not blobId
ameba23 7a6b394
remove unused variable
ameba23 8bcfe87
remove another unused variable
ameba23 49325a7
fix forwardRequest publishAll test
ameba23 4ba4640
uncomment filter
ameba23 817c6e9
readme
ameba23 dd0c68c
stuff
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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) | ||
} | ||
} |
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,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) | ||
} |
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,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') | ||
} |
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,30 @@ | ||
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 (filter, opts = {}) { | ||
if ((typeof filter === 'object') && (opts === null)) { | ||
opts = filter | ||
filter = null | ||
} | ||
if (!filter) filter = thing => thing | ||
return pull( | ||
shardsFromOthers(), | ||
pull.filter(filter), | ||
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.asyncMap((shard, cb) => { | ||
pull( | ||
forwardRequestBySecretOwner(get(shard, 'value.author')), | ||
pull.collect((err, forwards) => { | ||
if (err) cb(err) | ||
cb(null, forwards) | ||
}) | ||
) | ||
}) | ||
) | ||
} | ||
} |
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,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 fromOthers (opts = {}) { | ||
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 } | ||
} | ||
} | ||
}] | ||
|
||
const _opts = Object.assign({}, { query, limit: 100 }, opts) | ||
|
||
return pull( | ||
next(server.query.read, _opts), | ||
pull.filter(isForwardRequest) | ||
) | ||
} | ||
} |
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,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 fromSelf (opts = {}) { | ||
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 | ||
} | ||
} | ||
}] | ||
|
||
const _opts = Object.assign({}, { query, limit: 100 }, opts) | ||
|
||
return pull( | ||
next(server.query.read, _opts), | ||
pull.filter(isForwardRequest) | ||
) | ||
} | ||
} |
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,3 @@ | ||
module.exports = function assert (test, message) { | ||
if (!test) throw new Error(message || 'AssertionError') | ||
} |
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,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 } | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.