From 373b736abbf6cd27019c5ff3b6a217fe4c84bce7 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 7 Feb 2017 18:51:51 -0500 Subject: [PATCH] fix(sender-link): use spec-defined calculation for linkCredit --- lib/link.js | 3 +-- lib/receiver_link.js | 4 +++- lib/sender_link.js | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/link.js b/lib/link.js index 4008993..5cc7018 100644 --- a/lib/link.js +++ b/lib/link.js @@ -131,7 +131,6 @@ Link.prototype.attach = function() { this.name = attachFrame.name; this.role = attachFrame.role; this.linkCredit = 0; - this.totalCredits = 0; this.available = 0; this.drain = false; this.session.connection.sendFrame(attachFrame); @@ -186,7 +185,7 @@ Link.prototype.flow = function(options) { var flowOptions = u.defaults(options, { channel: this.session.channel, handle: this.handle, - linkCredit: this.totalCredits, + linkCredit: this.linkCredit, nextIncomingId: this.session._sessionParams.nextIncomingId, incomingWindow: this.session._sessionParams.incomingWindow, nextOutgoingId: this.session._sessionParams.nextOutgoingId, diff --git a/lib/receiver_link.js b/lib/receiver_link.js index 8e2ae44..9b43c8d 100644 --- a/lib/receiver_link.js +++ b/lib/receiver_link.js @@ -55,10 +55,10 @@ ReceiverLink.prototype.addCredits = function(credits, flowOptions) { // increment credits this.linkCredit += credits; - this.totalCredits += credits; this.session._sessionParams.incomingWindow += credits; debug('addCredits ('+this.name+'): New values: link('+this.linkCredit+'), session('+this.session._sessionParams.incomingWindow+')'); + // send flow frame this.flow(flowOptions); }; @@ -132,6 +132,7 @@ ReceiverLink.prototype.settle = function(message, state) { // private API ReceiverLink.prototype._flowReceived = function(flowFrame) { this.drain = flowFrame.drain; + this.deliveryCount = Math.min(this.deliveryCount, flowFrame.deliveryCount); this.emit(ReceiverLink.CreditChange, this); }; @@ -186,6 +187,7 @@ ReceiverLink.prototype._messageReceived = function(transferFrame) { Object.defineProperty(message, '_deliveryId', { value: curFrame.deliveryId }); this.linkCredit--; + this.deliveryCount++; debug('Rx message ' + transferFrame.deliveryId + ' on ' + this.name + ', ' + this.linkCredit + ' credit, ' + this.session._sessionParams.incomingWindow + ' window left.'); // @todo: Bump link credit based on strategy diff --git a/lib/sender_link.js b/lib/sender_link.js index bfe72f0..d353c2b 100644 --- a/lib/sender_link.js +++ b/lib/sender_link.js @@ -209,16 +209,15 @@ SenderLink.prototype._sendMessage = function(message, options) { this.session.connection.sendFrame(frame); } + this.deliveryCount++; this.linkCredit--; return messageId; }; -SenderLink.prototype._flowReceived = function(flowFrame) { - if (flowFrame.handle !== null) { - this.available = flowFrame.available; - this.deliveryCount = flowFrame.deliveryCount; - this.linkCredit = flowFrame.linkCredit; - this.totalCredits += flowFrame.linkCredit; +SenderLink.prototype._flowReceived = function(frame) { + if (frame.handle !== null) { + this.available = frame.available; // TODO: ?? I believe we should not be overwriting this + this.linkCredit = frame.deliveryCount + frame.linkCredit - this.deliveryCount; debug('setting credits (' + this.linkCredit + ',' + this.session._sessionParams.remoteIncomingWindow + ')'); }