Skip to content

Commit c47f2af

Browse files
committed
Fix pin save/load to work with go repo, simplify key set storage
1 parent f8627b9 commit c47f2af

File tree

5 files changed

+75
-115
lines changed

5 files changed

+75
-115
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"peer-info": "~0.11.0",
146146
"progress": "^2.0.0",
147147
"promisify-es6": "^1.0.3",
148+
"protons": "^1.0.0",
148149
"pull-abortable": "^4.1.1",
149150
"pull-file": "^1.0.0",
150151
"pull-ndjson": "^0.1.1",

src/core/components/key-set.js

-31
This file was deleted.

src/core/components/pin-set.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
const multihashes = require('multihashes')
44
const CID = require('cids')
5-
const protobuf = require('protocol-buffers')
6-
const crypto = require('crypto')
5+
const protobuf = require('protons')
76
const fnv1a = require('fnv1a')
87
const dagPB = require('ipld-dag-pb')
98
const DAGNode = dagPB.DAGNode
@@ -17,17 +16,18 @@ const defaultFanout = 256
1716
const maxItems = 8192
1817

1918
// Protobuf interface
20-
const pbSchema = (
21-
// from go-ipfs/pin/internal/pb/header.proto
22-
'message Set { ' +
23-
// 1 for now
24-
'optional uint32 version = 1; ' +
25-
// how many of the links are subtrees
26-
'optional uint32 fanout = 2; ' +
27-
// hash seed for subtree selection, a random number
28-
'optional fixed32 seed = 3; ' +
29-
'}'
30-
)
19+
// from go-ipfs/pin/internal/pb/header.proto
20+
const pbSchema = `
21+
syntax = "proto2";
22+
23+
package ipfs.pin;
24+
25+
message Set {
26+
optional uint32 version = 1;
27+
optional uint32 fanout = 2;
28+
optional fixed32 seed = 3;
29+
}
30+
`
3131
const pb = protobuf(pbSchema)
3232
function readHeader (rootNode) {
3333
// rootNode.data should be a buffer of the format:
@@ -113,10 +113,11 @@ exports = module.exports = function (dag) {
113113
})
114114
},
115115

116-
storeItems: (items, logInternalKey, callback, _subcalls, _done) => {
116+
storeItems: (items, logInternalKey, callback, _depth, _subcalls, _done) => {
117117
// callback (err, rootNode)
118118
callback = once(callback)
119-
const seed = crypto.randomBytes(4).readUInt32LE(0, true)
119+
// const seed = crypto.randomBytes(4).readUInt32LE(0, true) // old nondeterministic behavior
120+
const seed = _depth // new deterministic behavior
120121
const pbHeader = pb.Set.encode({
121122
version: 1,
122123
fanout: defaultFanout,
@@ -205,6 +206,7 @@ exports = module.exports = function (dag) {
205206
hashed[h],
206207
logInternalKey,
207208
storeItemsCb.bind({h: h}),
209+
_depth + 1,
208210
_subcalls,
209211
_done
210212
)

0 commit comments

Comments
 (0)