Skip to content

Commit

Permalink
Upgrade ncp to 1.1.1
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Feb 24, 2023
1 parent 133f1d2 commit e058fbe
Show file tree
Hide file tree
Showing 6 changed files with 3,007 additions and 2,841 deletions.
109 changes: 74 additions & 35 deletions dist/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -12715,14 +12715,14 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;

var _channel = _interopRequireDefault(require("./channel"));

var _heap = _interopRequireDefault(require("heap"));

var _packet_pb = require("./pb/packet_pb");
var _channel = _interopRequireDefault(require("./channel"));

var errors = _interopRequireWildcard(require("./errors"));

var _packet_pb = require("./pb/packet_pb");

var util = _interopRequireWildcard(require("./util"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
Expand All @@ -12734,7 +12734,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

class Connection {
constructor(session, localClientID, remoteClientID) {
constructor(session, localClientID, remoteClientID, initialWindowSize) {
_defineProperty(this, "session", void 0);

_defineProperty(this, "localClientID", void 0);
Expand All @@ -12756,7 +12756,7 @@ class Connection {
this.session = session;
this.localClientID = localClientID;
this.remoteClientID = remoteClientID;
this.windowSize = session.config.initialConnectionWindowSize;
this.windowSize = initialWindowSize;
this.retransmissionTimeout = session.config.initialRetransmissionTimeout;
this.sendWindowUpdate = new _channel.default(1);
this.timeSentSeq = new Map();
Expand All @@ -12782,11 +12782,7 @@ class Connection {
}

if (!this.resentSeq.has(sequenceID)) {
this.windowSize++;

if (this.windowSize > this.session.config.maxConnectionWindowSize) {
this.windowSize = this.session.config.maxConnectionWindowSize;
}
this.setWindowSize(this.windowSize + 1);
}

if (isSentByMe) {
Expand Down Expand Up @@ -12868,6 +12864,8 @@ class Connection {
}

console.log(e);
this.setWindowSize(this.windowSize / 2);
this.session.updateConnWindowSize();

switch (await _channel.default.select([this.session.resendChan.push(seq), this.session.context.done.shift()])) {
case this.session.resendChan:
Expand Down Expand Up @@ -12969,40 +12967,41 @@ class Connection {
}

let threshold = Date.now() - this.retransmissionTimeout;
let newResend = false;

for (let [seq, t] of this.timeSentSeq) {
if (this.resentSeq.has(seq)) {
continue;
}

if (t < threshold) {
await this.session.resendChan.push(seq);
this.resentSeq.set(seq, null);
this.windowSize /= 2;

if (this.windowSize < this.session.config.minConnectionWindowSize) {
this.windowSize = this.session.config.minConnectionWindowSize;
}

switch (await _channel.default.select([this.session.resendChan.push(seq), this.session.context.done.shift()])) {
case this.session.resendChan:
this.resentSeq.set(seq, null);
this.windowSize /= 2;

if (this.windowSize < this.session.config.minConnectionWindowSize) {
this.windowSize = this.session.config.minConnectionWindowSize;
}

this.setWindowSize(this.windowSize / 2);
newResend = true;
break;

case this.session.context.done:
throw this.session.context.err;
}
}
}

if (newResend) {
this.session.updateConnWindowSize();
}
}
}

setWindowSize(n) {
if (n < this.session.config.MinConnectionWindowSize) {
n = this.session.config.MinConnectionWindowSize;
}

this.windowSize = n;
}

}

exports.default = Connection;
Expand All @@ -13017,8 +13016,6 @@ const defaultConfig = {
nonStream: false,
sessionWindowSize: 4 << 20,
mtu: 1024,
initialConnectionWindowSize: 16,
maxConnectionWindowSize: 256,
minConnectionWindowSize: 1,
maxAckSeqListSize: 32,
flushInterval: 10,
Expand Down Expand Up @@ -13161,7 +13158,7 @@ exports.default = Context;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WriteDeadlineExceededError = exports.SessionNotEstablishedError = exports.SessionEstablishedError = exports.SessionClosedError = exports.RecvWindowFullError = exports.ReadDeadlineExceededError = exports.NotHandshakeError = exports.InvalidPacketError = exports.DialTimeoutError = exports.DataSizeTooLargeError = exports.BufferSizeTooSmallError = void 0;
exports.WriteDeadlineExceededError = exports.SessionNotEstablishedError = exports.SessionEstablishedError = exports.SessionClosedError = exports.RecvWindowFullError = exports.ReadDeadlineExceededError = exports.NotHandshakeError = exports.InvalidPacketError = exports.DialTimeoutError = exports.DataSizeTooLargeError = exports.ConnNotFoundError = exports.BufferSizeTooSmallError = void 0;

class SessionClosedError extends Error {
constructor(message = 'session closed', ...params) {
Expand Down Expand Up @@ -13327,6 +13324,21 @@ class DialTimeoutError extends Error {
}

exports.DialTimeoutError = DialTimeoutError;

class ConnNotFoundError extends Error {
constructor(message = 'Connection not found', ...params) {
super(message, ...params);

if (Error.captureStackTrace) {
Error.captureStackTrace(this, ConnNotFoundError);
}

this.name = 'ConnNotFoundError';
}

}

exports.ConnNotFoundError = ConnNotFoundError;
},{}],38:[function(require,module,exports){
'use strict';

Expand Down Expand Up @@ -13935,20 +13947,20 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;

var _channel = _interopRequireDefault(require("./channel"));

var _promise = _interopRequireDefault(require("core-js-pure/features/promise"));

var _connection = _interopRequireDefault(require("./connection"));

var context = _interopRequireWildcard(require("./context"));
var _channel = _interopRequireDefault(require("./channel"));

var _packet_pb = require("./pb/packet_pb");
var _connection = _interopRequireDefault(require("./connection"));

var consts = _interopRequireWildcard(require("./consts"));

var context = _interopRequireWildcard(require("./context"));

var errors = _interopRequireWildcard(require("./errors"));

var _packet_pb = require("./pb/packet_pb");

var util = _interopRequireWildcard(require("./util"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
Expand Down Expand Up @@ -14037,6 +14049,8 @@ class Session {

_defineProperty(this, "_writableStream", void 0);

_defineProperty(this, "sendWindowPacketCount", void 0);

this.config = Object.assign({}, consts.defaultConfig, config);
this.localAddr = localAddr;
this.remoteAddr = remoteAddr;
Expand All @@ -14063,6 +14077,7 @@ class Session {
this._readableStream = null;
this.WritableStream = null;
this._writableStream = null;
this.sendWindowPacketCount = this.sendWindowSize / this.sendMtu;
}

isStream() {
Expand Down Expand Up @@ -14189,6 +14204,8 @@ class Session {
}
}
}

this.updateConnWindowSize();
}

if (isEstablished && packet.getBytesRead() > this.remoteBytesRead) {
Expand Down Expand Up @@ -14221,6 +14238,8 @@ class Session {

if (conn) {
conn.sendAck(packet.getSequenceId());
} else {
throw new errors.ConnNotFoundError('Connection ' + util.connKey(localClientID, remoteClientID) + ' not found.');
}
}
}
Expand Down Expand Up @@ -14395,6 +14414,8 @@ class Session {
this.sendMtu = packet.getMtu();
}

this.sendWindowPacketCount = this.sendWindowSize / this.sendMtu;

if (packet.getClientIdsList().length === 0) {
throw new errors.InvalidPacketError('ClientIDs is empty');
}
Expand All @@ -14405,17 +14426,18 @@ class Session {
n = packet.getClientIdsList().length;
}

let initialWindowSize = this.sendWindowPacketCount / n;
let connections = new Map();

for (let i = 0; i < n; i++) {
let conn = new _connection.default(this, this.localClientIDs[i], packet.getClientIdsList()[i]);
let conn = new _connection.default(this, this.localClientIDs[i], packet.getClientIdsList()[i], initialWindowSize);
connections.set(util.connKey(conn.localClientID, conn.remoteClientID), conn);
}

this.connections = connections;
this.remoteClientIDs = packet.getClientIdsList();
this.sendChan = new _channel.default();
this.resendChan = new _channel.default(this.config.maxConnectionWindowSize * n);
this.resendChan = new _channel.default(this.sendWindowPacketCount + n);
this.sendWindowUpdate = new _channel.default(1);
this.recvDataUpdate = new _channel.default(1);
this.sendBuffer = new Uint8Array(0);
Expand Down Expand Up @@ -14790,6 +14812,23 @@ class Session {
return this._writableStream;
}

updateConnWindowSize() {
let totalSize = 0.0;

for (let conn of this.connections.values()) {
totalSize += conn.windowSize;
}

if (totalSize <= 0) {
return;
}

for (let conn of this.connections.values()) {
let n = this.sendWindowPacketCount * (conn.windowSize / totalSize);
conn.setWindowSize(n);
}
}

}

exports.default = Session;
Expand Down
2 changes: 1 addition & 1 deletion dist/nkn.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e058fbe

Please sign in to comment.