Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: amqp-node/amqplib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1b327eba45df6f417e598715aa9010f76407fc29
Choose a base ref
...
head repository: amqp-node/amqplib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 544bb5eaf463506921f7d114c08f4580817c3b4b
Choose a head ref
Loading
Showing with 2,232 additions and 1,555 deletions.
  1. +38 −0 .github/workflows/test.yml
  2. +2 −0 .gitignore
  3. +1 −11 .travis.yml
  4. +36 −0 CHANGELOG.md
  5. +5 −6 Makefile
  6. +0 −1 bin/generate-defs.js
  7. +6 −6 examples/tutorials/README.md
  8. +99 −72 lib/bitset.js
  9. +0 −1 lib/channel.js
  10. +268 −287 lib/channel_model.js
  11. +5 −1 lib/connect.js
  12. +14 −6 lib/connection.js
  13. +0 −1 lib/credentials.js
  14. +0 −1 lib/frame.js
  15. +1,683 −1,124 package-lock.json
  16. +4 −6 package.json
  17. +22 −21 test/bitset.js
  18. +0 −1 test/callback_api.js
  19. +0 −1 test/channel.js
  20. +0 −1 test/channel_api.js
  21. +0 −1 test/codec.js
  22. +47 −2 test/connect.js
  23. +0 −1 test/connection.js
  24. +0 −1 test/data.js
  25. +2 −3 test/frame.js
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
services:
rabbitmq:
image: rabbitmq
ports:
- 5672:5672

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

# Install all prerequisites
- run: npm ci

# Run the tests
- run: make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,3 +5,5 @@ node_modules/
bin/amqp-rabbitmq-0.9.1.json
etc/
coverage/
/.idea/
.nyc_output/
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.12"
- "iojs-v1"
- "iojs-v2"
- "iojs-v3"
- "4.2"
- "5.5"
- "6.12"
- "8.9"
- "9.11"
- "10.10"
- "11.1"
- "12"
- "13"
- "14"
- "15"
- "16"
- "node" # Latest stable Node version

sudo: false
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Change log for amqplib

## Changes in v0.9.0

git log v0.8.0..v0.9.0

* Update mocha and replace the deprecated istanbul with nyc ([PR
681](https://github.com/squaremo/amqp.node/pull/681)
* Update url-parse ([PR
675](https://github.com/squaremo/amqp.node/pull/675), thank you
@suhail-n and @kibertoad)
* fix: done called twice on invalid options ([PR
667](https://github.com/squaremo/amqp.node/pull/667), thank you
@luddd3 and @kibertoad)
* Close connection to server on connect errors ([PR
647](https://github.com/squaremo/amqp.node/pull/647), thank you
@luddd3 and @kibertoad)
* Modernise channel_model.js ([PR
635](https://github.com/squaremo/amqp.node/pull/635), thank you
@kibertoad and @jimmywarting)
* Bring package-lock.json up to date ([PR
653](https://github.com/squaremo/amqp.node/pull/653)
* Update url-parse ([PR
652](https://github.com/squaremo/amqp.node/pull/652), thank you
@giorgioatanasov and @buffolander)
* Modernise channel_model.js ([PR
651](https://github.com/squaremo/amqp.node/pull/651), thank you
for the review @kibertoad)
* Modernise bitset.js ([PR
634](https://github.com/squaremo/amqp.node/pull/634), thank you
@kibertoad and @jimmywarting)
* :warning: Drop CI for node versions below 10 ([PR
631](https://github.com/squaremo/amqp.node/pull/631), thank you
for the review @kibertoad)
* Replace safe-buffer dependency with native buffers ([PR
628](https://github.com/squaremo/amqp.node/pull/628), thank you
@kibertoad and @jimmywarting)

## Changes in v0.8.0

git log v0.7.1..v0.8.0
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ NODEJS_VERSIONS='10.21' '11.15' '12.18' '13.14' '14.5' '15.8'
MOCHA=./node_modules/.bin/mocha
_MOCHA=./node_modules/.bin/_mocha
UGLIFY=./node_modules/.bin/uglifyjs
ISTANBUL=./node_modules/.bin/istanbul
NYC=./node_modules/.bin/nyc

.PHONY: test test-all-nodejs all clean coverage

@@ -25,17 +25,16 @@ lib/defs.js: $(UGLIFY) bin/generate-defs.js bin/amqp-rabbitmq-0.9.1.json
-b 'indent-level=2' 2>&1 | (grep -v 'WARN' || true)

test: lib/defs.js
$(MOCHA) --check-leaks -u tdd test/
$(MOCHA) --check-leaks -u tdd --exit test/

test-all-nodejs: lib/defs.js
for v in $(NODEJS_VERSIONS); \
do echo "-- Node version $$v --"; \
nave use $$v $(MOCHA) -u tdd -R progress test; \
nave use $$v $(MOCHA) -u tdd --exit -R progress test; \
done

coverage: $(ISTANBUL) lib/defs.js
$(ISTANBUL) cover $(_MOCHA) -- -u tdd -R progress test/
$(ISTANBUL) report
coverage: $(NYC) lib/defs.js
$(NYC) --reporter=lcov --reporter=text $(_MOCHA) -u tdd -R progress test/
@echo "HTML report at file://$$(pwd)/coverage/lcov-report/index.html"

bin/amqp-rabbitmq-0.9.1.json:
1 change: 0 additions & 1 deletion bin/generate-defs.js
Original file line number Diff line number Diff line change
@@ -116,7 +116,6 @@ println(
'*/');

println("'use strict';"); nl();
println('var Buffer = require("safe-buffer").Buffer;');
nl()
println('var codec = require("./codec");');
println('var ints = require("buffer-more-ints");');
12 changes: 6 additions & 6 deletions examples/tutorials/README.md
Original file line number Diff line number Diff line change
@@ -85,9 +85,9 @@ some needless object-orientation (in the Python code; you don't get a
choice about needless object-orientation in Java).

[rabbitmq-tutes]: http://github.com/rabbitmq/rabbitmq-tutorials
[tute-one]: http://www.rabbitmq.com/tutorials/tutorial-one-python.html
[tute-two]: http://www.rabbitmq.com/tutorials/tutorial-two-python.html
[tute-three]: http://www.rabbitmq.com/tutorials/tutorial-three-python.html
[tute-four]: http://www.rabbitmq.com/tutorials/tutorial-four-python.html
[tute-five]: http://www.rabbitmq.com/tutorials/tutorial-five-python.html
[tute-six]: http://www.rabbitmq.com/tutorials/tutorial-six-python.html
[tute-one]: http://www.rabbitmq.com/tutorials/tutorial-one-javascript.html
[tute-two]: http://www.rabbitmq.com/tutorials/tutorial-two-javascript.html
[tute-three]: http://www.rabbitmq.com/tutorials/tutorial-three-javascript.html
[tute-four]: http://www.rabbitmq.com/tutorials/tutorial-four-javascript.html
[tute-five]: http://www.rabbitmq.com/tutorials/tutorial-five-javascript.html
[tute-six]: http://www.rabbitmq.com/tutorials/tutorial-six-javascript.html
171 changes: 99 additions & 72 deletions lib/bitset.js
Original file line number Diff line number Diff line change
@@ -2,102 +2,129 @@
//
//

// A bitset implementation, after that in java.util. Yes there
// already exist such things, but none implement next{Clear|Set}Bit or
// equivalent, and none involved me tooling about for an evening.

'use strict';

function BitSet(size) {
if (size) {
var numWords = Math.ceil(size / 32);
this.words = new Array(numWords);
/**
* A bitset implementation, after that in java.util. Yes there
* already exist such things, but none implement next{Clear|Set}Bit or
* equivalent, and none involved me tooling about for an evening.
*/
class BitSet {
/**
* @param {number} [size]
*/
constructor(size) {
if (size) {
const numWords = Math.ceil(size / 32);
this.words = new Array(numWords);
}
else {
this.words = [];
}
this.wordsInUse = 0; // = number, not index
}
else {
this.words = [];

/**
* @param {number} numWords
*/
ensureSize(numWords) {
const wordsPresent = this.words.length;
if (wordsPresent < numWords) {
this.words = this.words.concat(new Array(numWords - wordsPresent));
}
}
this.wordsInUse = 0; // = number, not index
}

var P = BitSet.prototype;
/**
* @param {number} bitIndex
*/
set(bitIndex) {
const w = wordIndex(bitIndex);
if (w >= this.wordsInUse) {
this.ensureSize(w + 1);
this.wordsInUse = w + 1;
}
const bit = 1 << bitIndex;
this.words[w] |= bit;
}

function wordIndex(bitIndex) {
return Math.floor(bitIndex / 32);
}
/**
* @param {number} bitIndex
*/
clear(bitIndex) {
const w = wordIndex(bitIndex);
if (w >= this.wordsInUse) return;
const mask = ~(1 << bitIndex);
this.words[w] &= mask;
}

// Make sure we have at least numWords
P.ensureSize = function(numWords) {
var wordsPresent = this.words.length;
if (wordsPresent < numWords) {
this.words = this.words.concat(new Array(numWords - wordsPresent));
/**
* @param {number} bitIndex
*/
get(bitIndex) {
const w = wordIndex(bitIndex);
if (w >= this.wordsInUse) return false; // >= since index vs size
const bit = 1 << bitIndex;
return !!(this.words[w] & bit);
}
}

P.set = function(bitIndex) {
var w = wordIndex(bitIndex);
if (w >= this.wordsInUse) {
this.ensureSize(w + 1);
this.wordsInUse = w + 1;
/**
* Give the next bit that is set on or after fromIndex, or -1 if no such bit
*
* @param {number} fromIndex
*/
nextSetBit(fromIndex) {
let w = wordIndex(fromIndex);
if (w >= this.wordsInUse) return -1;

// the right-hand side is shifted to only test the bits of the first
// word that are > fromIndex
let word = this.words[w] & (0xffffffff << fromIndex);
while (true) {
if (word) return (w * 32) + trailingZeros(word);
w++;
if (w === this.wordsInUse) return -1;
word = this.words[w];
}
}
var bit = 1 << bitIndex;
this.words[w] |= bit;
};

P.clear = function(bitIndex) {
var w = wordIndex(bitIndex);
if (w >= this.wordsInUse) return;
var mask = ~(1 << bitIndex);
this.words[w] &= mask;
};
/**
* @param {number} fromIndex
*/
nextClearBit(fromIndex) {
let w = wordIndex(fromIndex);
if (w >= this.wordsInUse) return fromIndex;

P.get = function(bitIndex) {
var w = wordIndex(bitIndex);
if (w >= this.wordsInUse) return false; // >= since index vs size
var bit = 1 << bitIndex;
return !!(this.words[w] & bit);
let word = ~(this.words[w]) & (0xffffffff << fromIndex);
while (true) {
if (word) return (w * 32) + trailingZeros(word);
w++;
if (w == this.wordsInUse) return w * 32;
word = ~(this.words[w]);
}
}
}

/**
* @param {number} bitIndex
*/
function wordIndex(bitIndex) {
return Math.floor(bitIndex / 32);
}

/**
* @param {number} i
*/
function trailingZeros(i) {
// From Hacker's Delight, via JDK. Probably far less effective here,
// since bit ops are not necessarily the quick way to do things in
// JS.
if (i === 0) return 32;
var y, n = 31;
let y, n = 31;
y = i << 16; if (y != 0) { n = n -16; i = y; }
y = i << 8; if (y != 0) { n = n - 8; i = y; }
y = i << 4; if (y != 0) { n = n - 4; i = y; }
y = i << 2; if (y != 0) { n = n - 2; i = y; }
return n - ((i << 1) >>> 31);
}

// Give the next bit that's set on or after fromIndex, or -1 if no such
// bit
P.nextSetBit = function(fromIndex) {
var w = wordIndex(fromIndex);
if (w >= this.wordsInUse) return -1;

// the right-hand side is shifted to only test the bits of the first
// word that are > fromIndex
var word = this.words[w] & (0xffffffff << fromIndex);
while (true) {
if (word) return (w * 32) + trailingZeros(word);
w++;
if (w === this.wordsInUse) return -1;
word = this.words[w];
}
};

P.nextClearBit = function(fromIndex) {
var w = wordIndex(fromIndex);
if (w >= this.wordsInUse) return fromIndex;

var word = ~(this.words[w]) & (0xffffffff << fromIndex);
while (true) {
if (word) return (w * 32) + trailingZeros(word);
w++;
if (w == this.wordsInUse) return w * 32;
word = ~(this.words[w]);
}
};

module.exports.BitSet = BitSet;
1 change: 0 additions & 1 deletion lib/channel.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ var EventEmitter = require('events').EventEmitter;
var fmt = require('util').format;
var IllegalOperationError = require('./error').IllegalOperationError;
var stackCapture = require('./error').stackCapture;
var Buffer = require('safe-buffer').Buffer
function Channel(connection) {
EventEmitter.call( this );
this.connection = connection;
Loading