Skip to content

Commit

Permalink
Fix pin save/load to work with go repo, simplify key set storage
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamStone committed Nov 26, 2017
1 parent f8627b9 commit c47f2af
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 115 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"peer-info": "~0.11.0",
"progress": "^2.0.0",
"promisify-es6": "^1.0.3",
"protons": "^1.0.0",
"pull-abortable": "^4.1.1",
"pull-file": "^1.0.0",
"pull-ndjson": "^0.1.1",
Expand Down
31 changes: 0 additions & 31 deletions src/core/components/key-set.js

This file was deleted.

32 changes: 17 additions & 15 deletions src/core/components/pin-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

const multihashes = require('multihashes')
const CID = require('cids')
const protobuf = require('protocol-buffers')
const crypto = require('crypto')
const protobuf = require('protons')
const fnv1a = require('fnv1a')
const dagPB = require('ipld-dag-pb')
const DAGNode = dagPB.DAGNode
Expand All @@ -17,17 +16,18 @@ const defaultFanout = 256
const maxItems = 8192

// Protobuf interface
const pbSchema = (
// from go-ipfs/pin/internal/pb/header.proto
'message Set { ' +
// 1 for now
'optional uint32 version = 1; ' +
// how many of the links are subtrees
'optional uint32 fanout = 2; ' +
// hash seed for subtree selection, a random number
'optional fixed32 seed = 3; ' +
'}'
)
// from go-ipfs/pin/internal/pb/header.proto
const pbSchema = `
syntax = "proto2";
package ipfs.pin;
message Set {
optional uint32 version = 1;
optional uint32 fanout = 2;
optional fixed32 seed = 3;
}
`
const pb = protobuf(pbSchema)
function readHeader (rootNode) {
// rootNode.data should be a buffer of the format:
Expand Down Expand Up @@ -113,10 +113,11 @@ exports = module.exports = function (dag) {
})
},

storeItems: (items, logInternalKey, callback, _subcalls, _done) => {
storeItems: (items, logInternalKey, callback, _depth, _subcalls, _done) => {
// callback (err, rootNode)
callback = once(callback)
const seed = crypto.randomBytes(4).readUInt32LE(0, true)
// const seed = crypto.randomBytes(4).readUInt32LE(0, true) // old nondeterministic behavior
const seed = _depth // new deterministic behavior
const pbHeader = pb.Set.encode({
version: 1,
fanout: defaultFanout,
Expand Down Expand Up @@ -205,6 +206,7 @@ exports = module.exports = function (dag) {
hashed[h],
logInternalKey,
storeItemsCb.bind({h: h}),
_depth + 1,
_subcalls,
_done
)
Expand Down
Loading

0 comments on commit c47f2af

Please sign in to comment.