Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

curvecp

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

curvecp - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

src/utils.js

2

package.json
{
"name": "curvecp",
"version": "0.9.1",
"version": "0.9.2",
"description": "Pure javascript CurveCP library",

@@ -5,0 +5,0 @@ "main": "src/index.js",

var hrtime = require('browser-process-hrtime')
var nacl = require('tweetnacl')
var debug = require('debug')('curvecp:chicago')

@@ -7,19 +6,4 @@ var NanoTimer = require('nanotimer')

var constants = require('./constants.js')
var utils = require('./utils.js')
var _safe_integer_addition = function (original, addition) {
if (Number.MAX_SAFE_INTEGER - addition < original) {
return Number.MAX_SAFE_INTEGER
} else {
return original + addition
}
}
var _safe_integer_multiplication = function (original, multiplier) {
if (Number.MAX_SAFE_INTEGER / 4 < original) {
return Number.MAX_SAFE_INTEGER
} else {
return original * multiplier
}
}
var Chicago = function () {

@@ -133,3 +117,3 @@ /* Clock instance */

Chicago.prototype._halve_transmission_rate = function () {
this.nsecperblock = _safe_integer_multiplication(this.nsecperblock, 2)
this.nsecperblock = utils.safe_integer_multiplication(this.nsecperblock, 2)
this.lastpanic = this.clock.clone()

@@ -173,3 +157,3 @@ this.lastedge = this.clock.clone()

var rtt_delta = rtt - this.rtt_average
this.rtt_average = _safe_integer_addition(this.rtt_average, rtt_delta / 8)
this.rtt_average = utils.safe_integer_addition(this.rtt_average, rtt_delta / 8)
if (rtt_delta < 0) {

@@ -179,4 +163,4 @@ rtt_delta = -rtt_delta

rtt_delta -= this.rtt_deviation
this.rtt_deviation = _safe_integer_addition(this.rtt_deviation, rtt_delta / 4)
this.rtt_timeout = _safe_integer_addition(this.rtt_average, _safe_integer_multiplication(this.rtt_deviation, 4))
this.rtt_deviation = utils.safe_integer_addition(this.rtt_deviation, rtt_delta / 4)
this.rtt_timeout = utils.safe_integer_addition(this.rtt_average, utils.safe_integer_multiplication(this.rtt_deviation, 4))
}

@@ -186,3 +170,3 @@

/* adjust for delayed acks with anti-spiking */
this.rtt_timeout = _safe_integer_addition(this.rtt_timeout, 8 * this.nsecperblock)
this.rtt_timeout = utils.safe_integer_addition(this.rtt_timeout, 8 * this.nsecperblock)
}

@@ -193,9 +177,9 @@

var rtt_delta = rtt - this.rtt_highwater
this.rtt_highwater = _safe_integer_addition(this.rtt_highwater, rtt_delta / 1024)
this.rtt_highwater = utils.safe_integer_addition(this.rtt_highwater, rtt_delta / 1024)
/* Adjust low watermark of congestion cycle */
rtt_delta = rtt - this.rtt_lowwater
if (rtt_delta > 0) {
this.rtt_lowwater = _safe_integer_addition(this.rtt_lowwater, rtt_delta / 8192)
this.rtt_lowwater = utils.safe_integer_addition(this.rtt_lowwater, rtt_delta / 8192)
} else {
this.rtt_lowwater = _safe_integer_addition(this.rtt_lowwater, rtt_delta / 256)
this.rtt_lowwater = utils.safe_integer_addition(this.rtt_lowwater, rtt_delta / 256)
}

@@ -205,3 +189,3 @@ }

Chicago.prototype._check_for_watermarks = function () {
if (this.rtt_average > _safe_integer_addition(this.rtt_highwater, 5 * constants.MILLISECOND)) {
if (this.rtt_average > utils.safe_integer_addition(this.rtt_highwater, 5 * constants.MILLISECOND)) {
this.rtt_seenrecenthigh = true

@@ -215,3 +199,3 @@ } else if (this.rtt_average < this.rtt_lowwater) {

Chicago.prototype._adjustment_cycle_has_completed = function () {
var cycle = _safe_integer_multiplication(this.nsecperblock, 16)
var cycle = utils.safe_integer_multiplication(this.nsecperblock, 16)
var endOfCycle = new Clock([this.lastspeedadjustment.seconds, this.lastspeedadjustment.nanoseconds])

@@ -227,3 +211,3 @@ endOfCycle.add(cycle)

this.nsecperblock = constants.SECOND /* slow restart */
this.nsecperblock = _safe_integer_addition(this.nsecperblock, this._randommod(this.nsecperblock / 8))
this.nsecperblock = utils.safe_integer_addition(this.nsecperblock, utils.randommod(this.nsecperblock / 8))
}

@@ -243,3 +227,3 @@ this.lastspeedadjustment = this.clock.clone()

var u = this.nsecperblock / 131072
var u_3 = _safe_integer_multiplication(_safe_integer_multiplication(u, u), u)
var u_3 = utils.safe_integer_multiplication(utils.safe_integer_multiplication(u, u), u)
this.nsecperblock = this.nsecperblock - u_3

@@ -259,3 +243,3 @@ } else {

this.lastedge = this.clock
this.nsecperblock = _safe_integer_addition(this.nsecperblock, this._randommod(this.nsecperblock / 4))
this.nsecperblock = utils.safe_integer_addition(this.nsecperblock, utils.randommod(this.nsecperblock / 4))
}

@@ -281,5 +265,5 @@ } else {

while (true) {
var n_4 = _safe_integer_multiplication(this.nsecperblock, 4)
var n_4 = utils.safe_integer_multiplication(this.nsecperblock, 4)
if (this.clock.subtract(this.lastedge) < 60 * constants.SECOND) {
var rto_64 = _safe_integer_multiplication(this.rtt_timeout, 64)
var rto_64 = utils.safe_integer_multiplication(this.rtt_timeout, 64)
compareClock = this.lastdoubling.clone()

@@ -294,3 +278,3 @@ compareClock.add(n_4)

} else {
var rto_2 = _safe_integer_multiplication(this.rtt_timeout, 2)
var rto_2 = utils.safe_integer_multiplication(this.rtt_timeout, 2)
compareClock = this.lastdoubling.clone()

@@ -315,15 +299,2 @@ compareClock.add(n_4)

Chicago.prototype._randommod = function (n) {
var result = 0
if (n <= 1) {
return 0
}
var randomBytes = nacl.randomBytes(32)
for (var j = 0; j < 32; ++j) {
result = _safe_integer_addition(_safe_integer_multiplication(result, 256), Number(randomBytes[j]))
result = result % n
}
return result
}
module.exports = Chicago
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc