From c7e991451b3dd7315963f4ec27dd7a55bd708beb Mon Sep 17 00:00:00 2001 From: luiz telles Date: Tue, 1 Dec 2020 09:54:09 -0200 Subject: [PATCH 1/2] Fixed. TFTP server recovers after packet loss --- lib/protocol/writer.js | 46 ++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/protocol/writer.js b/lib/protocol/writer.js index e6fba09..deaf293 100644 --- a/lib/protocol/writer.js +++ b/lib/protocol/writer.js @@ -212,42 +212,48 @@ Window.prototype.resume = function (block){ //rollover if (!this._mayRollover && (block < this._start - 1 || block > this._end)) return; + + if (this._mayRollover && + (block < this._start - 1 && block > this._end)) return; this._writerTimer.reset (); if (block !== this._end){ //Not all the blocks has been received in the server - if (block === this._start - 1){ - //The whole window must be send again - this._writerTimer.start (this._restransmitterSendFn); - this._blocks.forEach (this._sendFn); - }else{ - //Remove the blocks already received and shift the window - while (this._blocks[0].block !== block){ - this._blocks.shift (); - } - this._blocks.shift (); - } - }else{ + + while ( ((this._blocks[0].block <= block) || + (this._mayRollover && (this._blocks[0].block >= block))) && + (this._blocks.length >1)){ + this._blocks.shift (); + } + }else + { this._blocks = []; } - + this._start = block + 1; //Update the window - this._start = this._block + 1; if (this._start === 65536){ this._start = this._rollover; + this._mayRollover = false; }else{ this._mayRollover = true; } - this._end = this._block + this._windowSize; + this._end = block + this._windowSize; if (this._end > 65535){ - this._end -= 65535 + this._rolloverFix; + this._end -= 65536 + this._rollover; }else{ this._mayRollover = false; } - this._pending = this._windowSize; + this._pending = this._windowSize - this._blocks.length; var cb = this._cb; - this._cb = null; - cb (); -}; \ No newline at end of file + if (this._pending) { + this._cb = null; + cb (); + } + else { + this._writerTimer.start (this._restransmitterSendFn); + this._blocks.forEach (this._sendFn); + + } +}; From 68b9e90d62e296a5696551ee9d82c5db5afd09d9 Mon Sep 17 00:00:00 2001 From: luiz telles Date: Wed, 2 Dec 2020 09:44:24 -0200 Subject: [PATCH 2/2] Discard the received "ack" packet less than expected --- lib/protocol/writer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protocol/writer.js b/lib/protocol/writer.js index deaf293..52e9700 100644 --- a/lib/protocol/writer.js +++ b/lib/protocol/writer.js @@ -211,10 +211,10 @@ Window.prototype.resume = function (block){ //Ignore invalid acks (duplicates included) only when the window doesn't //rollover if (!this._mayRollover && - (block < this._start - 1 || block > this._end)) return; + (block < this._start || block > this._end)) return; if (this._mayRollover && - (block < this._start - 1 && block > this._end)) return; + (block < this._start && block > this._end)) return; this._writerTimer.reset ();