Comparing version 0.9.4 to 0.9.5
{ | ||
"name": "curvecp", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"description": "Pure javascript CurveCP library", | ||
@@ -21,3 +21,2 @@ "main": "src/index.js", | ||
"browser-process-hrtime": "^0.1.2", | ||
"debug": "^2.2.0", | ||
"extend.js": "0.0.2", | ||
@@ -31,3 +30,5 @@ "inherits": "^2.0.1", | ||
"tweetnacl": "^0.14.3", | ||
"tweetnacl-util": "^0.13.3" | ||
"tweetnacl-util": "^0.13.3", | ||
"winston": "^2.2.0", | ||
"winston-meta-wrapper": "^1.0.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
var hrtime = require('browser-process-hrtime') | ||
var debug = require('debug')('curvecp:chicago') | ||
var winston = require('winston') | ||
var winstonWrapper = require('winston-meta-wrapper') | ||
var NanoTimer = require('nanotimer') | ||
@@ -8,3 +9,13 @@ var Clock = require('./clock.js') | ||
var Chicago = function () { | ||
var Chicago = function (options) { | ||
if (!options) { | ||
options = {} | ||
} | ||
if (!options.logger) { | ||
options.logger = winston | ||
} | ||
this._log = winstonWrapper(options.logger) | ||
this._log.addMeta({ | ||
module: 'curvecp-chicago' | ||
}) | ||
/* Clock instance */ | ||
@@ -70,3 +81,3 @@ this.clock = new Clock([0, 0]) | ||
Chicago.prototype._set_timeout = function () { | ||
debug('_set_timeout ' + this.nsecperblock) | ||
this._log.debug('_set_timeout ' + this.nsecperblock) | ||
this.timer.setTimeout(this._timeout_callback.bind(this), [], this.nsecperblock.toString() + 'n') | ||
@@ -126,3 +137,2 @@ } | ||
Chicago.prototype.acknowledgement = function (original_blocktime) { | ||
debug('acknowledgement') | ||
this._refresh_clock() | ||
@@ -203,3 +213,3 @@ var rtt = this._initialize_rtt(original_blocktime) | ||
Chicago.prototype._reinitialize_lastspeedadjustment = function () { | ||
debug('_reinitialize_lastspeedadjustment ' + this.nsecperblock) | ||
this._log.debug('_reinitialize_lastspeedadjustment ' + this.nsecperblock) | ||
if (this.clock.subtract(this.lastspeedadjustment) > 10 * constants.SECOND) { | ||
@@ -213,3 +223,3 @@ this.nsecperblock = constants.SECOND /* slow restart */ | ||
Chicago.prototype._apply_additive_increase = function () { | ||
debug('_apply_additive_increase ' + this.nsecperblock) | ||
this._log.debug('_apply_additive_increase ' + this.nsecperblock) | ||
if (this.nsecperblock >= 131072) { | ||
@@ -233,3 +243,3 @@ /* additive increase: adjust 1/N by a constant c */ | ||
Chicago.prototype._phase_events = function () { | ||
debug('_phase_events ' + this.nsecperblock) | ||
this._log.debug('_phase_events ' + this.nsecperblock) | ||
if (this.rtt_phase === 0) { | ||
@@ -256,3 +266,3 @@ if (this.rtt_seenolderhigh) { | ||
Chicago.prototype._apply_rate_doubling = function () { | ||
debug('_apply_rate_doubling ' + this.nsecperblock) | ||
this._log.debug('_apply_rate_doubling ' + this.nsecperblock) | ||
var compareClock | ||
@@ -259,0 +269,0 @@ var result |
@@ -8,8 +8,18 @@ var Chicago = require('./chicago.js') | ||
var _ = require('lodash') | ||
var debug = require('debug')('curvecp:MessageStream') | ||
var constants = require('./constants.js') | ||
var isBuffer = require('is-buffer') | ||
var winston = require('winston') | ||
var winstonWrapper = require('winston-meta-wrapper') | ||
var MessageStream = function (options) { | ||
debug('initialize') | ||
if (!options) { | ||
options = {} | ||
} | ||
if (!options.logger) { | ||
options.logger = winston | ||
} | ||
this._log = winstonWrapper(options.logger) | ||
this._log.addMeta({ | ||
module: 'curvecp-messagestream' | ||
}) | ||
var opts = {} | ||
@@ -89,3 +99,3 @@ opts.objectMode = false | ||
MessageStream.prototype._receiveData = function (data) { | ||
debug('_receiveData') | ||
this._log.debug('_receiveData') | ||
if (_.size(this._incoming) < constants.MAX_INCOMING) { | ||
@@ -119,3 +129,3 @@ var message = new Message() | ||
MessageStream.prototype._process = function () { | ||
debug('_process') | ||
this._log.debug('_process') | ||
var maxReached = _.some(this._outgoing, function (block) { | ||
@@ -125,3 +135,3 @@ return block.transmissions > constants.MAX_RETRANSMISSIONS | ||
if (maxReached) { | ||
debug('maximum retransmissions reached') | ||
this._log.warn('maximum retransmissions reached') | ||
this._cleanup() | ||
@@ -141,6 +151,6 @@ this.emit('error', new Error('Maximum retransmissions reached - remote host down')) | ||
MessageStream.prototype._write = function (chunk, encoding, done) { | ||
debug('_write') | ||
this._log.debug('_write') | ||
assert(isBuffer(chunk)) | ||
if (this._sendBytes.length > constants.MAXIMUM_UNPROCESSED_SEND_BYTES) { | ||
debug('Buffer is full') | ||
this._log.warn('Buffer is full') | ||
done(new Error('Buffer is full')) | ||
@@ -155,4 +165,4 @@ return | ||
this._sendBytes = Buffer.concat([this._sendBytes, chunk]) | ||
debug('_sendBytes length: ' + this._sendBytes.length) | ||
debug('_sendProcessed length: ' + this._sendProcessed) | ||
this._log.debug('_sendBytes length: ' + this._sendBytes.length) | ||
this._log.debug('_sendProcessed length: ' + this._sendProcessed) | ||
this._chicago.enable_timer() | ||
@@ -168,9 +178,14 @@ return this._sendBytes.length < constants.MAXIMUM_UNPROCESSED_SEND_BYTES | ||
MessageStream.prototype.canResend = function () { | ||
return this.__streamReady && !_.isEmpty(this._outgoing) && _.some(this._outgoing, function (block) { | ||
return this._chicago.block_is_timed_out(block.transmission_time) | ||
}, this) | ||
var self = this | ||
if (this.__streamReady && !_.isEmpty(this._outgoing)) { | ||
var some = _.some(this._outgoing, function (block) { | ||
return self._chicago.block_is_timed_out(block.transmission_time) | ||
}) | ||
return some | ||
} | ||
return false | ||
} | ||
MessageStream.prototype.resendBlock = function () { | ||
debug('resendBlock') | ||
this._log.debug('resendBlock') | ||
var block = this._outgoing[0] | ||
@@ -183,3 +198,2 @@ _.forEach(this._outgoing, function (compareBlock) { | ||
block.transmission_time = this._chicago.get_clock() | ||
debug(block.transmissions) | ||
block.transmissions = block.transmissions + 1 | ||
@@ -196,5 +210,5 @@ block.id = this._nextMessageId() | ||
MessageStream.prototype.sendBlock = function () { | ||
debug('sendBlock') | ||
debug('sendBytes start: ' + this._sendBytes.length) | ||
debug('sendProcessed start: ' + this._sendProcessed) | ||
this._log.debug('sendBlock') | ||
this._log.debug('sendBytes start: ' + this._sendBytes.length) | ||
this._log.debug('sendProcessed start: ' + this._sendProcessed) | ||
var blockSize = this._sendBytes.length | ||
@@ -215,4 +229,4 @@ if (blockSize > this._maxBlockLength) { | ||
this._sendProcessed = this._sendProcessed + block.data.length | ||
debug('sendBytes stop: ' + this._sendBytes.length) | ||
debug('sendProcessed stop: ' + this._sendProcessed) | ||
this._log.debug('sendBytes stop: ' + this._sendBytes.length) | ||
this._log.debug('sendProcessed stop: ' + this._sendProcessed) | ||
this._outgoing.push(block) | ||
@@ -227,3 +241,3 @@ this._sendBlock(block) | ||
MessageStream.prototype._sendBlock = function (block) { | ||
debug('_sendBlock ' + block.start_byte + ' - ' + block.data.length) | ||
this._log.debug('_sendBlock ' + block.start_byte + ' - ' + block.data.length) | ||
var message = new Message() | ||
@@ -246,3 +260,3 @@ message.id = block.id | ||
MessageStream.prototype.processMessage = function () { | ||
debug('processMessage') | ||
this._log.debug('processMessage') | ||
var message = this._incoming.shift() | ||
@@ -254,3 +268,4 @@ this.processAcknowledgments(message) | ||
MessageStream.prototype.processAcknowledgments = function (message) { | ||
debug('processAcknowledgements') | ||
var self = this | ||
this._log.debug('processAcknowledgements') | ||
var removedList | ||
@@ -261,3 +276,3 @@ removedList = _.remove(this._outgoing, function (block) { | ||
_.forEach(removedList, function (block) { | ||
debug('block acknowledged: ' + block.start_byte + ' - ' + block.data.length) | ||
this._log.debug('block acknowledged: ' + block.start_byte + ' - ' + block.data.length) | ||
this._chicago.acknowledgement(block.transmission_time) | ||
@@ -269,3 +284,3 @@ }, this) | ||
_.forEach(removedList, function (writeRequest) { | ||
debug('write request acknowledged: ' + writeRequest.startByte + ' - ' + writeRequest.length) | ||
self._log.debug('write request acknowledged: ' + writeRequest.startByte + ' - ' + writeRequest.length) | ||
writeRequest.callback() | ||
@@ -279,3 +294,3 @@ }) | ||
MessageStream.prototype.sendAcknowledgment = function (message) { | ||
debug('sendAcknowledgment ' + this._receivedBytes) | ||
this._log.debug('sendAcknowledgment ' + this._receivedBytes) | ||
var reply = new Message() | ||
@@ -289,3 +304,3 @@ reply.id = this._nextMessageId() | ||
MessageStream.prototype._processMessage = function (message) { | ||
debug('_processMessage') | ||
this._log.debug('_processMessage') | ||
if (message.offset <= this._receivedBytes) { | ||
@@ -315,3 +330,3 @@ if (message.data_length > 1) { | ||
} else { | ||
debug('error while sending CurveCP message') | ||
this._log.warn('error while sending CurveCP message') | ||
} | ||
@@ -318,0 +333,0 @@ } |
@@ -5,3 +5,2 @@ 'use strict' | ||
var extend = require('extend.js') | ||
var debug = require('debug')('curvecp:PacketStream') | ||
var Uint64BE = require('int64-buffer').Uint64BE | ||
@@ -13,2 +12,4 @@ var nacl = require('tweetnacl') | ||
var utils = require('./utils.js') | ||
var winston = require('winston') | ||
var winstonWrapper = require('winston-meta-wrapper') | ||
@@ -31,4 +32,10 @@ var HELLO_MSG = nacl.util.decodeUTF8('QvnQ5XlH') | ||
var PacketStream = function (opts) { | ||
debug('initialize') | ||
if (!opts) opts = {} | ||
if (!opts.logger) { | ||
opts.logger = winston | ||
} | ||
this._log = winstonWrapper(opts.logger) | ||
this._log.addMeta({ | ||
module: 'curvecp-packetstream' | ||
}) | ||
opts.objectMode = false | ||
@@ -152,3 +159,3 @@ opts.decodeStrings = true | ||
PacketStream.prototype._onMessage = function (message) { | ||
debug('_onMessage') | ||
this._log.debug('_onMessage') | ||
if (this.isServer) { | ||
@@ -162,3 +169,3 @@ this._onMessageServer(message) | ||
PacketStream.prototype._onMessageClient = function (message) { | ||
debug('_onMessage@Client') | ||
this._log.debug('_onMessage@Client') | ||
if (message.length < 64 || message.length > 1152) { | ||
@@ -168,7 +175,7 @@ return | ||
if (!this._isEqual(this.clientExtension, message.subarray(8, 24))) { | ||
debug('invalid clientExtension') | ||
this._log.warn('invalid clientExtension') | ||
return | ||
} | ||
if (!this._isEqual(this.serverExtension, message.subarray(24, 40))) { | ||
debug('invalid serverExtension') | ||
this._log.warn('invalid serverExtension') | ||
return | ||
@@ -185,3 +192,3 @@ } | ||
} else { | ||
debug('invalid packet received') | ||
this._log.warn('invalid packet received') | ||
} | ||
@@ -191,3 +198,3 @@ } | ||
PacketStream.prototype._onMessageServer = function (message) { | ||
debug('_onMessage@Server') | ||
this._log.debug('_onMessage@Server') | ||
if (message.length < 96 || message.length > 1184) { | ||
@@ -197,11 +204,10 @@ return | ||
if (!this._isEqual(this.clientExtension, message.subarray(24, 40))) { | ||
debug('invalid clientExtension') | ||
this._log.warn('invalid clientExtension') | ||
return | ||
} | ||
if (!this._isEqual(this.serverExtension, message.subarray(8, 24))) { | ||
debug('invalid serverExtension') | ||
this._log.warn('invalid serverExtension') | ||
return | ||
} | ||
var messageType = message.subarray(0, 8) | ||
debug(messageType.toString()) | ||
if (this._isEqual(messageType, HELLO_MSG)) { | ||
@@ -218,3 +224,3 @@ this._onHello(message) | ||
} else { | ||
debug('invalid packet received') | ||
this._log.warn('invalid packet received') | ||
} | ||
@@ -224,4 +230,6 @@ } | ||
PacketStream.prototype.connect = function (boxId, connectionInfo) { | ||
debug('connect') | ||
debug(connectionInfo) | ||
this._log.debug('connect', { | ||
connectionInfo: connectionInfo, | ||
boxId: boxId | ||
}) | ||
var self = this | ||
@@ -237,3 +245,3 @@ if (!this.isServer) { | ||
this.stream.once('connect', function () { | ||
debug('underlying stream connected') | ||
self._log.debug('underlying stream connected') | ||
self.connect(boxId, connectionInfo) | ||
@@ -258,7 +266,7 @@ }) | ||
PacketStream.prototype._read = function (size) { | ||
debug('_read') | ||
this._log.debug('_read') | ||
} | ||
PacketStream.prototype._write = function (chunk, encoding, done) { | ||
debug('_write') | ||
this._log.debug('_write') | ||
if (this._canSend()) { | ||
@@ -313,3 +321,3 @@ if (this.isServer) { | ||
} catch (err) { | ||
debug('Decrypt failed with error ' + err) | ||
this._log.warn('Decrypt failed with error ' + err) | ||
} | ||
@@ -388,3 +396,3 @@ return result | ||
PacketStream.prototype._sendHello = function () { | ||
debug('sendHello') | ||
this._log.debug('sendHello') | ||
var self = this | ||
@@ -416,6 +424,6 @@ this._setCanSend(false) | ||
PacketStream.prototype._onHello = function (helloMessage) { | ||
debug('onHello') | ||
this._log.debug('onHello') | ||
this._setCanSend(false) | ||
if (helloMessage.length !== 224) { | ||
debug('Hello message has incorrect length') | ||
this._log.warn('Hello message has incorrect length') | ||
return | ||
@@ -425,3 +433,3 @@ } | ||
if (!this.__validNonce(helloMessage, 40 + 32 + 64)) { | ||
debug('Invalid nonce received') | ||
this._log.warn('Invalid nonce received') | ||
return | ||
@@ -431,7 +439,7 @@ } | ||
if (boxData === undefined) { | ||
debug('Hello: not able to decrypt box data') | ||
this._log.warn('Hello: not able to decrypt box data') | ||
return | ||
} | ||
if (!this._isEqual(boxData, new Uint8Array(64))) { | ||
debug('Hello: invalid data in signature box') | ||
this._log.warn('Hello: invalid data in signature box') | ||
return | ||
@@ -445,3 +453,3 @@ } | ||
PacketStream.prototype._sendCookie = function () { | ||
debug('sendCookie') | ||
this._log.debug('sendCookie') | ||
this._setCanSend(false) | ||
@@ -470,6 +478,6 @@ var keyPair = nacl.box.keyPair() | ||
PacketStream.prototype._onCookie = function (cookieMessage) { | ||
debug('onCookie') | ||
this._log.debug('onCookie') | ||
this._setCanSend(false) | ||
if (cookieMessage.length !== 200) { | ||
debug('Cookie message has incorrect length') | ||
this._log.warn('Cookie message has incorrect length') | ||
return | ||
@@ -479,3 +487,3 @@ } | ||
if (boxData === undefined) { | ||
debug('Not able to decrypt welcome box data') | ||
this._log.warn('Not able to decrypt welcome box data') | ||
return | ||
@@ -486,3 +494,3 @@ } | ||
if (this.__serverCookie.length !== 96) { | ||
debug('Welcome command server cookie invalid') | ||
this._log.warn('Welcome command server cookie invalid') | ||
return | ||
@@ -497,5 +505,5 @@ } | ||
PacketStream.prototype._sendInitiate = function (message, done) { | ||
debug('sendInitiate ' + nacl.util.encodeBase64(this.clientPublicKey) + ' > ' + nacl.util.encodeBase64(this.serverPublicKey)) | ||
this._log.debug('sendInitiate ' + nacl.util.encodeBase64(this.clientPublicKey) + ' > ' + nacl.util.encodeBase64(this.serverPublicKey)) | ||
if (message.length & 15) { | ||
debug('message is of incorrect length, needs to be multiple of 16') | ||
this._log.warn('message is of incorrect length, needs to be multiple of 16') | ||
return | ||
@@ -526,14 +534,14 @@ } | ||
PacketStream.prototype._onInitiate = function (initiateMessage) { | ||
debug('onInitiate') | ||
this._log.debug('onInitiate') | ||
this._setCanSend(false) | ||
if (initiateMessage.length < 544) { | ||
debug('Initiate command has incorrect length') | ||
this._log.warn('Initiate command has incorrect length') | ||
return | ||
} | ||
if (!this.__validNonce(initiateMessage, 72 + 96)) { | ||
debug('Invalid nonce received') | ||
this._log.warn('Invalid nonce received') | ||
return | ||
} | ||
if (!this._isEqual(initiateMessage.subarray(72, 72 + 96), this.__serverCookie)) { | ||
debug('Initiate command server cookie not recognized') | ||
this._log.warn('Initiate command server cookie not recognized') | ||
return | ||
@@ -543,3 +551,3 @@ } | ||
if (initiateBoxData === undefined) { | ||
debug('Not able to decrypt initiate box data') | ||
this._log.warn('Not able to decrypt initiate box data') | ||
return | ||
@@ -550,7 +558,7 @@ } | ||
if (vouch === undefined) { | ||
debug('not able to decrypt vouch data') | ||
this._log.warn('not able to decrypt vouch data') | ||
return | ||
} | ||
if (!this._isEqual(vouch, this.clientConnectionPublicKey)) { | ||
debug('Initiate command vouch contains different client connection public key than previously received') | ||
this._log.warn('Initiate command vouch contains different client connection public key than previously received') | ||
return | ||
@@ -566,3 +574,3 @@ } | ||
PacketStream.prototype._sendServerMessage = function (message, done) { | ||
debug('sendServerMessage') | ||
this._log.debug('sendServerMessage') | ||
var result = new Uint8Array(64 + message.length) | ||
@@ -578,9 +586,9 @@ result.set(SERVER_MSG) | ||
PacketStream.prototype._onServerMessage = function (message) { | ||
debug('onServerMessage@Client') | ||
this._log.debug('onServerMessage@Client') | ||
if (message.length < 64 || message.length > 1152) { | ||
debug('Message command has incorrect length') | ||
this._log.warn('Message command has incorrect length') | ||
return | ||
} | ||
if (!this.__validNonce(message, 40)) { | ||
debug('Invalid nonce received') | ||
this._log.warn('Invalid nonce received') | ||
return | ||
@@ -590,3 +598,3 @@ } | ||
if (boxData === undefined || !boxData) { | ||
debug('not able to decrypt box data') | ||
this._log.warn('not able to decrypt box data') | ||
return | ||
@@ -602,3 +610,3 @@ } | ||
PacketStream.prototype._sendClientMessage = function (message, done) { | ||
debug('sendClientMessage ' + nacl.util.encodeBase64(this.clientPublicKey) + ' > ' + nacl.util.encodeBase64(this.serverPublicKey)) | ||
this._log.debug('sendClientMessage ' + nacl.util.encodeBase64(this.clientPublicKey) + ' > ' + nacl.util.encodeBase64(this.serverPublicKey)) | ||
var result = new Uint8Array(96 + message.length) | ||
@@ -614,9 +622,9 @@ result.set(CLIENT_MSG) | ||
PacketStream.prototype._onClientMessage = function (message) { | ||
debug('onClientMessage@Server ' + nacl.util.encodeBase64(this.clientPublicKey) + ' > ' + nacl.util.encodeBase64(this.serverPublicKey)) | ||
this._log.debug('onClientMessage@Server ' + nacl.util.encodeBase64(this.clientPublicKey) + ' > ' + nacl.util.encodeBase64(this.serverPublicKey)) | ||
if (message.length < 96 || message.length > 1184) { | ||
debug('Message command has incorrect length') | ||
this._log.warn('Message command has incorrect length') | ||
return | ||
} | ||
if (!this.__validNonce(message, 40 + 32)) { | ||
debug('Invalid nonce received') | ||
this._log.warn('Invalid nonce received') | ||
return | ||
@@ -626,3 +634,3 @@ } | ||
if (boxData === undefined || !boxData) { | ||
debug('not able to decrypt box data') | ||
this._log.warn('not able to decrypt box data') | ||
return | ||
@@ -629,0 +637,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66981
1628
12
+ Addedwinston@^2.2.0
+ Addedwinston-meta-wrapper@^1.0.0
+ Addedasync@2.6.4(transitive)
+ Addedcolors@1.0.3(transitive)
+ Addedcycle@1.0.3(transitive)
+ Addedeyes@0.1.8(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedlodash@4.15.04.17.21(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedwinston@2.4.7(transitive)
+ Addedwinston-meta-wrapper@1.2.0(transitive)
- Removeddebug@^2.2.0
- Removeddebug@2.6.9(transitive)
- Removedms@2.0.0(transitive)