Skip to content
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

Fix seeks #552

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,8 @@ class Peer {
this._remoteContiguousLength = start
}

if (start === 0 && drop === false && length > this._remoteContiguousLength) {
this._remoteContiguousLength = length
if (start === 0 && drop === false) {
if (length > this._remoteContiguousLength) this._remoteContiguousLength = length
} else if (length === 1) {
const bitfield = this.core.skipBitfield === null ? this.core.bitfield : this.core.skipBitfield
this.remoteBitfield.set(start, has)
Expand Down Expand Up @@ -1095,7 +1095,7 @@ class Peer {
let index = off + i
if (index > s.seeker.end) index -= len

if (this.remoteBitfield.get(index) === false) continue
if (this._remoteHasBlock(index) === false) continue
if (this.core.bitfield.get(index) === true) continue
if (!this._hasTreeParent(index)) continue

Expand Down Expand Up @@ -1997,6 +1997,17 @@ module.exports = class Replicator {
}

_onwant (peer, start, length) {
const contig = Math.min(this.core.tree.length, this.core.header.hints.contiguousLength)

if (start + length < contig || (this.core.tree.length === contig)) {
peer.wireRange.send({
drop: false,
start: 0,
length: contig
})
return
}

length = Math.min(length, this.core.tree.length - start)

peer.protomux.cork()
Expand Down
5 changes: 0 additions & 5 deletions test/remote-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ test('announce-range-on-update flow with big core (multiple bitfield pages)', as
true,
'Sanity check: b knows about a'
)
t.is(
getPeer(b, a).remoteBitfield._pages.tiny.b[1] != null,
true,
'Sanity check: there is indeed >1 page'
)
mafintosh marked this conversation as resolved.
Show resolved Hide resolved

await b.get(nrBlocks - 1)
await new Promise(resolve => setTimeout(resolve, 500))
Expand Down
15 changes: 15 additions & 0 deletions test/replicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,21 @@ test('merkle-tree signature gets unslabbed', async function (t) {
)
})

test('seek against non sparse peer', async function (t) {
const a = await create()
await a.append(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'])

const b = await create(a.key)
replicate(a, b, t)

await b.get(a.length - 1)

const [block, offset] = await b.seek(5)

t.is(block, 5)
t.is(offset, 0)
})

async function waitForRequestBlock (core) {
while (true) {
const reqBlock = core.replicator._inflight._requests.find(req => req && req.block)
Expand Down
Loading