remove unnecessary wantRange() argument

This commit is contained in:
Andre Staltz 2023-04-14 11:44:20 +03:00
parent 7df89f3439
commit b0d20287ce
2 changed files with 9 additions and 10 deletions

View File

@ -45,7 +45,7 @@ class Algorithm {
* @param {Range} remoteHaveRange
* @returns {Range}
*/
#wantAllRange(rootMsgHash, localHaveRange, remoteHaveRange) {
#wantAllRange(localHaveRange, remoteHaveRange) {
return remoteHaveRange
}
@ -56,7 +56,7 @@ class Algorithm {
* @param {number} count
* @returns {Range}
*/
#wantNewestRange(rootMsgHash, localHaveRange, remoteHaveRange, count) {
#wantNewestRange(localHaveRange, remoteHaveRange, count) {
const [minLocalHave, maxLocalHave] = localHaveRange
const [minRemoteHave, maxRemoteHave] = remoteHaveRange
if (maxRemoteHave <= maxLocalHave) return [1, 0]
@ -73,27 +73,26 @@ class Algorithm {
* @param {number} count
* @returns {Range}
*/
#wantOldestRange(rootMsgHash, localHaveRange, remoteHaveRange, count) {
#wantOldestRange(localHaveRange, remoteHaveRange, count) {
// FIXME:
}
/**
* @param {string} rootMsgHash // FIXME: delete YAGNI
* @param {Range} localHave
* @param {Range} remoteHave
* @param {Goal?} goal
* @returns {Range}
*/
wantRange(rootMsgHash, localHave, remoteHave, goal) {
wantRange(localHave, remoteHave, goal) {
if (!goal) return [1, 0]
if (isEmptyRange(remoteHave)) return [1, 0]
const { type, count } = parseGoal(goal)
if (type === 'all') {
return this.#wantAllRange(rootMsgHash, localHave, remoteHave)
return this.#wantAllRange(localHave, remoteHave)
} else if (type === 'newest') {
return this.#wantNewestRange(rootMsgHash, localHave, remoteHave, count)
return this.#wantNewestRange(localHave, remoteHave, count)
} else if (type === 'oldest') {
return this.#wantOldestRange(rootMsgHash, localHave, remoteHave, count)
return this.#wantOldestRange(localHave, remoteHave, count)
}
}

View File

@ -113,7 +113,7 @@ class SyncStream extends Pipeable {
this.#remoteHave.set(id, remoteHaveRange)
const goal = this.#goals.get(id)
const haveRange = this.#algo.haveRange(id)
const wantRange = this.#algo.wantRange(id, haveRange, remoteHaveRange, goal)
const wantRange = this.#algo.wantRange(haveRange, remoteHaveRange, goal)
this.#localHave.set(id, haveRange)
this.#localWant.set(id, wantRange)
// prettier-ignore
@ -128,7 +128,7 @@ class SyncStream extends Pipeable {
this.#remoteWant.set(id, remoteWantRange)
const goal = this.#goals.get(id)
const haveRange = this.#localHave.get(id)
const wantRange = this.#algo.wantRange(id, haveRange, remoteHaveRange, goal)
const wantRange = this.#algo.wantRange(haveRange, remoteHaveRange, goal)
this.#localWant.set(id, wantRange)
const localBloom0 = this.#algo.bloomFor(id, 0, wantRange)
this.sink.write({