Skip to content

Commit 8782939

Browse files
committed
Add remoteContiguousLength field to hints
To support holepunchto/hypercore#743 persisting `remoteContiguousLength`.
1 parent b2cc2a8 commit 8782939

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

build.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ core.register({
286286
{
287287
name: 'contiguousLength',
288288
type: 'uint'
289+
},
290+
{
291+
name: 'remoteContiguousLength',
292+
type: 'uint'
289293
}
290294
]
291295
})

spec/hyperschema/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,27 @@ const encoding12 = {
397397
// @core/hints
398398
const encoding13 = {
399399
preencode(state, m) {
400-
state.end++ // max flag is 1 so always one byte
400+
state.end++ // max flag is 2 so always one byte
401401

402402
if (m.contiguousLength) c.uint.preencode(state, m.contiguousLength)
403+
if (m.remoteContiguousLength) c.uint.preencode(state, m.remoteContiguousLength)
403404
},
404405
encode(state, m) {
405-
const flags = m.contiguousLength ? 1 : 0
406+
const flags =
407+
(m.contiguousLength ? 1 : 0) |
408+
(m.remoteContiguousLength ? 2 : 0)
406409

407410
c.uint.encode(state, flags)
408411

409412
if (m.contiguousLength) c.uint.encode(state, m.contiguousLength)
413+
if (m.remoteContiguousLength) c.uint.encode(state, m.remoteContiguousLength)
410414
},
411415
decode(state) {
412416
const flags = c.uint.decode(state)
413417

414418
return {
415-
contiguousLength: (flags & 1) !== 0 ? c.uint.decode(state) : 0
419+
contiguousLength: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
420+
remoteContiguousLength: (flags & 2) !== 0 ? c.uint.decode(state) : 0
416421
}
417422
}
418423
}

spec/hyperschema/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@
348348
"name": "contiguousLength",
349349
"type": "uint",
350350
"version": 1
351+
},
352+
{
353+
"name": "remoteContiguousLength",
354+
"type": "uint",
355+
"version": 1
351356
}
352357
]
353358
},

test/atomic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ test('atomized flow with all non-delete operations on a single core', async (t)
186186
length: 3
187187
}
188188
const expHints = {
189-
contiguousLength: 1
189+
contiguousLength: 1,
190+
remoteContiguousLength: 0
190191
}
191192
const expBitfields = [b4a.from('bitfield-data-1'), null]
192193

test/basic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ test('can get info from store efficiently', async function (t) {
242242
},
243243
head: { fork: 0, length: 2, rootHash: b4a.alloc(32, 0), signature: null },
244244
hints: {
245-
contiguousLength: 0
245+
contiguousLength: 0,
246+
remoteContiguousLength: 0
246247
}
247248
})
248249
}

test/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ test('set and get hypercore hints', async (t) => {
399399
const rx = core.read()
400400
const p = rx.getHints()
401401
rx.tryFlush()
402-
t.alike(await p, { contiguousLength: 1 }, 'updated hints')
402+
t.alike(await p, { contiguousLength: 1, remoteContiguousLength: 0 }, 'updated hints')
403403
}
404404
})
405405

0 commit comments

Comments
 (0)