Skip to content

Commit

Permalink
fix(sender-link): use spec-defined calculation for linkCredit
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Feb 17, 2017
1 parent f0f267c commit 373b736
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/link.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/receiver_link.js
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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

Expand Down
11 changes: 5 additions & 6 deletions lib/sender_link.js
Expand Up @@ -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 + ')');
}
Expand Down

0 comments on commit 373b736

Please sign in to comment.