2
2
3
3
const multihashes = require ( 'multihashes' )
4
4
const CID = require ( 'cids' )
5
- const protobuf = require ( 'protocol-buffers' )
6
- const crypto = require ( 'crypto' )
5
+ const protobuf = require ( 'protons' )
7
6
const fnv1a = require ( 'fnv1a' )
8
7
const dagPB = require ( 'ipld-dag-pb' )
9
8
const DAGNode = dagPB . DAGNode
@@ -17,17 +16,18 @@ const defaultFanout = 256
17
16
const maxItems = 8192
18
17
19
18
// 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
+ `
31
31
const pb = protobuf ( pbSchema )
32
32
function readHeader ( rootNode ) {
33
33
// rootNode.data should be a buffer of the format:
@@ -113,10 +113,11 @@ exports = module.exports = function (dag) {
113
113
} )
114
114
} ,
115
115
116
- storeItems : ( items , logInternalKey , callback , _subcalls , _done ) => {
116
+ storeItems : ( items , logInternalKey , callback , _depth , _subcalls , _done ) => {
117
117
// callback (err, rootNode)
118
118
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
120
121
const pbHeader = pb . Set . encode ( {
121
122
version : 1 ,
122
123
fanout : defaultFanout ,
@@ -205,6 +206,7 @@ exports = module.exports = function (dag) {
205
206
hashed [ h ] ,
206
207
logInternalKey ,
207
208
storeItemsCb . bind ( { h : h } ) ,
209
+ _depth + 1 ,
208
210
_subcalls ,
209
211
_done
210
212
)
0 commit comments