typespeed 2.0.21 → 2.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.decorator.js +1 -30
- package/dist/default/default-authentication.class.js +25 -0
- package/dist/default/express-server.class.js +11 -4
- package/dist/default/log-default.class.js +0 -6
- package/dist/factory/authentication-factory.class.js +11 -0
- package/dist/factory/log-factory.class.js +9 -0
- package/dist/route.decorator.js +92 -2
- package/dist/typespeed.d.ts +25 -3
- package/dist/typespeed.js +3 -1
- package/package.json +1 -1
- package/src/core.decorator.ts +1 -29
- package/src/default/default-authentication.class.ts +10 -0
- package/src/default/express-server.class.ts +12 -5
- package/src/default/log-default.class.ts +0 -10
- package/src/factory/authentication-factory.class.ts +9 -0
- package/src/factory/log-factory.class.ts +9 -2
- package/src/route.decorator.ts +91 -3
- package/src/typespeed.d.ts +25 -3
- package/src/typespeed.ts +1 -0
- package/test/node_modules/.package-lock.json +65 -101
- package/test/node_modules/@types/body-parser/LICENSE +21 -0
- package/test/node_modules/@types/body-parser/README.md +16 -0
- package/test/node_modules/@types/body-parser/index.d.ts +107 -0
- package/test/node_modules/@types/body-parser/package.json +58 -0
- package/test/node_modules/@types/connect/LICENSE +21 -0
- package/test/node_modules/@types/connect/README.md +16 -0
- package/test/node_modules/@types/connect/index.d.ts +93 -0
- package/test/node_modules/@types/connect/package.json +32 -0
- package/test/node_modules/@types/express/LICENSE +21 -0
- package/test/node_modules/@types/express/README.md +16 -0
- package/test/node_modules/@types/express/index.d.ts +136 -0
- package/test/node_modules/@types/express/package.json +45 -0
- package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
- package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
- package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
- package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
- package/test/node_modules/@types/mime/LICENSE +21 -0
- package/test/node_modules/@types/mime/Mime.d.ts +10 -0
- package/test/node_modules/@types/mime/README.md +16 -0
- package/test/node_modules/@types/mime/index.d.ts +35 -0
- package/test/node_modules/@types/mime/lite.d.ts +7 -0
- package/test/node_modules/@types/mime/package.json +29 -0
- package/test/node_modules/@types/qs/LICENSE +21 -0
- package/test/node_modules/@types/qs/README.md +16 -0
- package/test/node_modules/@types/qs/index.d.ts +62 -0
- package/test/node_modules/@types/qs/package.json +65 -0
- package/test/node_modules/@types/range-parser/LICENSE +21 -0
- package/test/node_modules/@types/range-parser/README.md +55 -0
- package/test/node_modules/@types/range-parser/index.d.ts +35 -0
- package/test/node_modules/@types/range-parser/package.json +25 -0
- package/test/node_modules/@types/send/LICENSE +21 -0
- package/test/node_modules/@types/send/README.md +16 -0
- package/test/node_modules/@types/send/index.d.ts +231 -0
- package/test/node_modules/@types/send/package.json +33 -0
- package/test/node_modules/@types/serve-static/LICENSE +21 -0
- package/test/node_modules/@types/serve-static/README.md +16 -0
- package/test/node_modules/@types/serve-static/index.d.ts +113 -0
- package/test/node_modules/@types/serve-static/package.json +38 -0
- package/test/src/config.json +5 -0
- package/test/src/custom-log.class.ts +6 -0
- package/test/src/jwt-authentication.class.ts +29 -0
- package/test/src/test-request.class.ts +36 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
- package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
- package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
- package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
- package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
- package/test/node_modules/amqplib/CHANGELOG.md +0 -430
- package/test/node_modules/amqplib/LICENSE +0 -6
- package/test/node_modules/amqplib/LICENSE-MIT +0 -21
- package/test/node_modules/amqplib/Makefile +0 -47
- package/test/node_modules/amqplib/README.md +0 -157
- package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
- package/test/node_modules/amqplib/callback_api.js +0 -22
- package/test/node_modules/amqplib/channel_api.js +0 -16
- package/test/node_modules/amqplib/examples/headers.js +0 -42
- package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
- package/test/node_modules/amqplib/examples/send_generators.js +0 -42
- package/test/node_modules/amqplib/examples/ssl.js +0 -64
- package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
- package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
- package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
- package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
- package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
- package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
- package/test/node_modules/amqplib/lib/api_args.js +0 -314
- package/test/node_modules/amqplib/lib/bitset.js +0 -130
- package/test/node_modules/amqplib/lib/callback_model.js +0 -327
- package/test/node_modules/amqplib/lib/channel.js +0 -499
- package/test/node_modules/amqplib/lib/channel_model.js +0 -302
- package/test/node_modules/amqplib/lib/codec.js +0 -321
- package/test/node_modules/amqplib/lib/connect.js +0 -189
- package/test/node_modules/amqplib/lib/connection.js +0 -663
- package/test/node_modules/amqplib/lib/credentials.js +0 -42
- package/test/node_modules/amqplib/lib/defs.js +0 -4966
- package/test/node_modules/amqplib/lib/error.js +0 -24
- package/test/node_modules/amqplib/lib/format.js +0 -40
- package/test/node_modules/amqplib/lib/frame.js +0 -113
- package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
- package/test/node_modules/amqplib/lib/mux.js +0 -129
- package/test/node_modules/amqplib/package.json +0 -37
- package/test/node_modules/amqplib/test/bitset.js +0 -69
- package/test/node_modules/amqplib/test/callback_api.js +0 -312
- package/test/node_modules/amqplib/test/channel.js +0 -621
- package/test/node_modules/amqplib/test/channel_api.js +0 -596
- package/test/node_modules/amqplib/test/codec.js +0 -237
- package/test/node_modules/amqplib/test/connect.js +0 -197
- package/test/node_modules/amqplib/test/connection.js +0 -390
- package/test/node_modules/amqplib/test/data.js +0 -254
- package/test/node_modules/amqplib/test/frame.js +0 -198
- package/test/node_modules/amqplib/test/mux.js +0 -204
- package/test/node_modules/amqplib/test/util.js +0 -219
- package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
- package/test/node_modules/buffer-more-ints/LICENSE +0 -19
- package/test/node_modules/buffer-more-ints/README.md +0 -69
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
- package/test/node_modules/buffer-more-ints/package.json +0 -19
- package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
- package/test/node_modules/core-util-is/LICENSE +0 -19
- package/test/node_modules/core-util-is/README.md +0 -3
- package/test/node_modules/core-util-is/lib/util.js +0 -107
- package/test/node_modules/core-util-is/package.json +0 -38
- package/test/node_modules/debug/LICENSE +0 -20
- package/test/node_modules/debug/README.md +0 -481
- package/test/node_modules/debug/package.json +0 -59
- package/test/node_modules/debug/src/browser.js +0 -269
- package/test/node_modules/debug/src/common.js +0 -274
- package/test/node_modules/debug/src/index.js +0 -10
- package/test/node_modules/debug/src/node.js +0 -263
- package/test/node_modules/inherits/LICENSE +0 -16
- package/test/node_modules/inherits/README.md +0 -42
- package/test/node_modules/inherits/inherits.js +0 -9
- package/test/node_modules/inherits/inherits_browser.js +0 -27
- package/test/node_modules/inherits/package.json +0 -29
- package/test/node_modules/isarray/README.md +0 -54
- package/test/node_modules/isarray/build/build.js +0 -209
- package/test/node_modules/isarray/component.json +0 -19
- package/test/node_modules/isarray/index.js +0 -3
- package/test/node_modules/isarray/package.json +0 -25
- package/test/node_modules/ms/index.js +0 -162
- package/test/node_modules/ms/license.md +0 -21
- package/test/node_modules/ms/package.json +0 -37
- package/test/node_modules/ms/readme.md +0 -60
- package/test/node_modules/querystringify/LICENSE +0 -22
- package/test/node_modules/querystringify/README.md +0 -61
- package/test/node_modules/querystringify/index.js +0 -118
- package/test/node_modules/querystringify/package.json +0 -38
- package/test/node_modules/readable-stream/LICENSE +0 -18
- package/test/node_modules/readable-stream/README.md +0 -15
- package/test/node_modules/readable-stream/duplex.js +0 -1
- package/test/node_modules/readable-stream/float.patch +0 -923
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
- package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
- package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
- package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
- package/test/node_modules/readable-stream/package.json +0 -32
- package/test/node_modules/readable-stream/passthrough.js +0 -1
- package/test/node_modules/readable-stream/readable.js +0 -10
- package/test/node_modules/readable-stream/transform.js +0 -1
- package/test/node_modules/readable-stream/writable.js +0 -1
- package/test/node_modules/requires-port/.travis.yml +0 -19
- package/test/node_modules/requires-port/LICENSE +0 -22
- package/test/node_modules/requires-port/README.md +0 -47
- package/test/node_modules/requires-port/index.js +0 -38
- package/test/node_modules/requires-port/package.json +0 -47
- package/test/node_modules/requires-port/test.js +0 -98
- package/test/node_modules/safe-buffer/LICENSE +0 -21
- package/test/node_modules/safe-buffer/README.md +0 -584
- package/test/node_modules/safe-buffer/index.d.ts +0 -187
- package/test/node_modules/safe-buffer/index.js +0 -62
- package/test/node_modules/safe-buffer/package.json +0 -37
- package/test/node_modules/string_decoder/LICENSE +0 -20
- package/test/node_modules/string_decoder/README.md +0 -7
- package/test/node_modules/string_decoder/index.js +0 -221
- package/test/node_modules/string_decoder/package.json +0 -25
- package/test/node_modules/url-parse/LICENSE +0 -22
- package/test/node_modules/url-parse/README.md +0 -153
- package/test/node_modules/url-parse/dist/url-parse.js +0 -755
- package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
- package/test/node_modules/url-parse/index.js +0 -589
- package/test/node_modules/url-parse/package.json +0 -49
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
var defs = require('./defs');
|
|
8
|
-
var constants = defs.constants;
|
|
9
|
-
var frame = require('./frame');
|
|
10
|
-
var HEARTBEAT = frame.HEARTBEAT;
|
|
11
|
-
var Mux = require('./mux').Mux;
|
|
12
|
-
|
|
13
|
-
var Duplex =
|
|
14
|
-
require('stream').Duplex ||
|
|
15
|
-
require('readable-stream/duplex');
|
|
16
|
-
var EventEmitter = require('events').EventEmitter;
|
|
17
|
-
var Heart = require('./heartbeat').Heart;
|
|
18
|
-
|
|
19
|
-
var methodName = require('./format').methodName;
|
|
20
|
-
var closeMsg = require('./format').closeMessage;
|
|
21
|
-
var inspect = require('./format').inspect;
|
|
22
|
-
|
|
23
|
-
var BitSet = require('./bitset').BitSet;
|
|
24
|
-
var inherits = require('util').inherits;
|
|
25
|
-
var fmt = require('util').format;
|
|
26
|
-
var PassThrough = require('stream').PassThrough ||
|
|
27
|
-
require('readable-stream/passthrough');
|
|
28
|
-
var IllegalOperationError = require('./error').IllegalOperationError;
|
|
29
|
-
var stackCapture = require('./error').stackCapture;
|
|
30
|
-
|
|
31
|
-
// High-water mark for channel write buffers, in 'objects' (which are
|
|
32
|
-
// encoded frames as buffers).
|
|
33
|
-
var DEFAULT_WRITE_HWM = 1024;
|
|
34
|
-
// If all the frames of a message (method, properties, content) total
|
|
35
|
-
// to less than this, copy them into a single buffer and write it all
|
|
36
|
-
// at once. Note that this is less than the minimum frame size: if it
|
|
37
|
-
// was greater, we might have to fragment the content.
|
|
38
|
-
var SINGLE_CHUNK_THRESHOLD = 2048;
|
|
39
|
-
|
|
40
|
-
function Connection(underlying) {
|
|
41
|
-
EventEmitter.call( this );
|
|
42
|
-
var stream = this.stream = wrapStream(underlying);
|
|
43
|
-
this.muxer = new Mux(stream);
|
|
44
|
-
|
|
45
|
-
// frames
|
|
46
|
-
this.rest = Buffer.alloc(0);
|
|
47
|
-
this.frameMax = constants.FRAME_MIN_SIZE;
|
|
48
|
-
this.sentSinceLastCheck = false;
|
|
49
|
-
this.recvSinceLastCheck = false;
|
|
50
|
-
|
|
51
|
-
this.expectSocketClose = false;
|
|
52
|
-
this.freeChannels = new BitSet();
|
|
53
|
-
this.channels = [{channel: {accept: channel0(this)},
|
|
54
|
-
buffer: underlying}];
|
|
55
|
-
}
|
|
56
|
-
inherits(Connection, EventEmitter);
|
|
57
|
-
|
|
58
|
-
var C = Connection.prototype;
|
|
59
|
-
|
|
60
|
-
// Usual frame accept mode
|
|
61
|
-
function mainAccept(frame) {
|
|
62
|
-
var rec = this.channels[frame.channel];
|
|
63
|
-
if (rec) { return rec.channel.accept(frame); }
|
|
64
|
-
// NB CHANNEL_ERROR may not be right, but I don't know what is ..
|
|
65
|
-
else
|
|
66
|
-
this.closeWithError(
|
|
67
|
-
fmt('Frame on unknown channel %d', frame.channel),
|
|
68
|
-
constants.CHANNEL_ERROR,
|
|
69
|
-
new Error(fmt("Frame on unknown channel: %s",
|
|
70
|
-
inspect(frame, false))));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Handle anything that comes through on channel 0, that's the
|
|
74
|
-
// connection control channel. This is only used once mainAccept is
|
|
75
|
-
// installed as the frame handler, after the opening handshake.
|
|
76
|
-
function channel0(connection) {
|
|
77
|
-
return function(f) {
|
|
78
|
-
// Once we get a 'close', we know 1. we'll get no more frames, and
|
|
79
|
-
// 2. anything we send except close, or close-ok, will be
|
|
80
|
-
// ignored. If we already sent 'close', this won't be invoked since
|
|
81
|
-
// we're already in closing mode; if we didn't well we're not going
|
|
82
|
-
// to send it now are we.
|
|
83
|
-
if (f === HEARTBEAT); // ignore; it's already counted as activity
|
|
84
|
-
// on the socket, which is its purpose
|
|
85
|
-
else if (f.id === defs.ConnectionClose) {
|
|
86
|
-
// Oh. OK. I guess we're done here then.
|
|
87
|
-
connection.sendMethod(0, defs.ConnectionCloseOk, {});
|
|
88
|
-
var emsg = fmt('Connection closed: %s', closeMsg(f));
|
|
89
|
-
var s = stackCapture(emsg);
|
|
90
|
-
var e = new Error(emsg);
|
|
91
|
-
e.code = f.fields.replyCode;
|
|
92
|
-
if (isFatalError(e)) {
|
|
93
|
-
connection.emit('error', e);
|
|
94
|
-
}
|
|
95
|
-
connection.toClosed(s, e);
|
|
96
|
-
}
|
|
97
|
-
else if (f.id === defs.ConnectionBlocked) {
|
|
98
|
-
connection.emit('blocked', f.fields.reason);
|
|
99
|
-
}
|
|
100
|
-
else if (f.id === defs.ConnectionUnblocked) {
|
|
101
|
-
connection.emit('unblocked');
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
connection.closeWithError(
|
|
105
|
-
fmt("Unexpected frame on channel 0"),
|
|
106
|
-
constants.UNEXPECTED_FRAME,
|
|
107
|
-
new Error(fmt("Unexpected frame on channel 0: %s",
|
|
108
|
-
inspect(f, false))));
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// This changed between versions, as did the codec, methods, etc. AMQP
|
|
114
|
-
// 0-9-1 is fairly similar to 0.8, but better, and nothing implements
|
|
115
|
-
// 0.8 that doesn't implement 0-9-1. In other words, it doesn't make
|
|
116
|
-
// much sense to generalise here.
|
|
117
|
-
C.sendProtocolHeader = function() {
|
|
118
|
-
this.sendBytes(frame.PROTOCOL_HEADER);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/*
|
|
122
|
-
The frighteningly complicated opening protocol (spec section 2.2.4):
|
|
123
|
-
|
|
124
|
-
Client -> Server
|
|
125
|
-
|
|
126
|
-
protocol header ->
|
|
127
|
-
<- start
|
|
128
|
-
start-ok ->
|
|
129
|
-
.. next two zero or more times ..
|
|
130
|
-
<- secure
|
|
131
|
-
secure-ok ->
|
|
132
|
-
<- tune
|
|
133
|
-
tune-ok ->
|
|
134
|
-
open ->
|
|
135
|
-
<- open-ok
|
|
136
|
-
|
|
137
|
-
If I'm only supporting SASL's PLAIN mechanism (which I am for the time
|
|
138
|
-
being), it gets a bit easier since the server won't in general send
|
|
139
|
-
back a `secure`, it'll just send `tune` after the `start-ok`.
|
|
140
|
-
(SASL PLAIN: http://tools.ietf.org/html/rfc4616)
|
|
141
|
-
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
C.open = function(allFields, openCallback0) {
|
|
145
|
-
var self = this;
|
|
146
|
-
var openCallback = openCallback0 || function() {};
|
|
147
|
-
|
|
148
|
-
// This is where we'll put our negotiated values
|
|
149
|
-
var tunedOptions = Object.create(allFields);
|
|
150
|
-
|
|
151
|
-
function wait(k) {
|
|
152
|
-
self.step(function(err, frame) {
|
|
153
|
-
if (err !== null) bail(err);
|
|
154
|
-
else if (frame.channel !== 0) {
|
|
155
|
-
bail(new Error(
|
|
156
|
-
fmt("Frame on channel != 0 during handshake: %s",
|
|
157
|
-
inspect(frame, false))));
|
|
158
|
-
}
|
|
159
|
-
else k(frame);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function expect(Method, k) {
|
|
164
|
-
wait(function(frame) {
|
|
165
|
-
if (frame.id === Method) k(frame);
|
|
166
|
-
else {
|
|
167
|
-
bail(new Error(
|
|
168
|
-
fmt("Expected %s; got %s",
|
|
169
|
-
methodName(Method), inspect(frame, false))));
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function bail(err) {
|
|
175
|
-
openCallback(err);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function send(Method) {
|
|
179
|
-
// This can throw an exception if there's some problem with the
|
|
180
|
-
// options; e.g., something is a string instead of a number.
|
|
181
|
-
self.sendMethod(0, Method, tunedOptions);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function negotiate(server, desired) {
|
|
185
|
-
// We get sent values for channelMax, frameMax and heartbeat,
|
|
186
|
-
// which we may accept or lower (subject to a minimum for
|
|
187
|
-
// frameMax, but we'll leave that to the server to enforce). In
|
|
188
|
-
// all cases, `0` really means "no limit", or rather the highest
|
|
189
|
-
// value in the encoding, e.g., unsigned short for channelMax.
|
|
190
|
-
if (server === 0 || desired === 0) {
|
|
191
|
-
// i.e., whichever places a limit, if either
|
|
192
|
-
return Math.max(server, desired);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
return Math.min(server, desired);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function onStart(start) {
|
|
200
|
-
var mechanisms = start.fields.mechanisms.toString().split(' ');
|
|
201
|
-
if (mechanisms.indexOf(allFields.mechanism) < 0) {
|
|
202
|
-
bail(new Error(fmt('SASL mechanism %s is not provided by the server',
|
|
203
|
-
allFields.mechanism)));
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
self.serverProperties = start.fields.serverProperties;
|
|
207
|
-
try {
|
|
208
|
-
send(defs.ConnectionStartOk);
|
|
209
|
-
} catch (err) {
|
|
210
|
-
bail(err);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
wait(afterStartOk);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function afterStartOk(reply) {
|
|
217
|
-
switch (reply.id) {
|
|
218
|
-
case defs.ConnectionSecure:
|
|
219
|
-
bail(new Error(
|
|
220
|
-
"Wasn't expecting to have to go through secure"));
|
|
221
|
-
break;
|
|
222
|
-
case defs.ConnectionClose:
|
|
223
|
-
bail(new Error(fmt("Handshake terminated by server: %s",
|
|
224
|
-
closeMsg(reply))));
|
|
225
|
-
break;
|
|
226
|
-
case defs.ConnectionTune:
|
|
227
|
-
var fields = reply.fields;
|
|
228
|
-
tunedOptions.frameMax =
|
|
229
|
-
negotiate(fields.frameMax, allFields.frameMax);
|
|
230
|
-
tunedOptions.channelMax =
|
|
231
|
-
negotiate(fields.channelMax, allFields.channelMax);
|
|
232
|
-
tunedOptions.heartbeat =
|
|
233
|
-
negotiate(fields.heartbeat, allFields.heartbeat);
|
|
234
|
-
try {
|
|
235
|
-
send(defs.ConnectionTuneOk);
|
|
236
|
-
send(defs.ConnectionOpen);
|
|
237
|
-
} catch (err) {
|
|
238
|
-
bail(err);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
expect(defs.ConnectionOpenOk, onOpenOk);
|
|
242
|
-
break;
|
|
243
|
-
default:
|
|
244
|
-
bail(new Error(
|
|
245
|
-
fmt("Expected connection.secure, connection.close, " +
|
|
246
|
-
"or connection.tune during handshake; got %s",
|
|
247
|
-
inspect(reply, false))));
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function onOpenOk(openOk) {
|
|
253
|
-
// Impose the maximum of the encoded value, if the negotiated
|
|
254
|
-
// value is zero, meaning "no, no limits"
|
|
255
|
-
self.channelMax = tunedOptions.channelMax || 0xffff;
|
|
256
|
-
self.frameMax = tunedOptions.frameMax || 0xffffffff;
|
|
257
|
-
// 0 means "no heartbeat", rather than "maximum period of
|
|
258
|
-
// heartbeating"
|
|
259
|
-
self.heartbeat = tunedOptions.heartbeat;
|
|
260
|
-
self.heartbeater = self.startHeartbeater();
|
|
261
|
-
self.accept = mainAccept;
|
|
262
|
-
succeed(openOk);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// If the server closes the connection, it's probably because of
|
|
266
|
-
// something we did
|
|
267
|
-
function endWhileOpening(err) {
|
|
268
|
-
bail(err || new Error('Socket closed abruptly ' +
|
|
269
|
-
'during opening handshake'));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
this.stream.on('end', endWhileOpening);
|
|
273
|
-
this.stream.on('error', endWhileOpening);
|
|
274
|
-
|
|
275
|
-
function succeed(ok) {
|
|
276
|
-
self.stream.removeListener('end', endWhileOpening);
|
|
277
|
-
self.stream.removeListener('error', endWhileOpening);
|
|
278
|
-
self.stream.on('error', self.onSocketError.bind(self));
|
|
279
|
-
self.stream.on('end', self.onSocketError.bind(
|
|
280
|
-
self, new Error('Unexpected close')));
|
|
281
|
-
self.on('frameError', self.onSocketError.bind(self));
|
|
282
|
-
self.acceptLoop();
|
|
283
|
-
openCallback(null, ok);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Now kick off the handshake by prompting the server
|
|
287
|
-
this.sendProtocolHeader();
|
|
288
|
-
expect(defs.ConnectionStart, onStart);
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// Closing things: AMQP has a closing handshake that applies to
|
|
292
|
-
// closing both connects and channels. As the initiating party, I send
|
|
293
|
-
// Close, then ignore all frames until I see either CloseOK --
|
|
294
|
-
// which signifies that the other party has seen the Close and shut
|
|
295
|
-
// the connection or channel down, so it's fine to free resources; or
|
|
296
|
-
// Close, which means the other party also wanted to close the
|
|
297
|
-
// whatever, and I should send CloseOk so it can free resources,
|
|
298
|
-
// then go back to waiting for the CloseOk. If I receive a Close
|
|
299
|
-
// out of the blue, I should throw away any unsent frames (they will
|
|
300
|
-
// be ignored anyway) and send CloseOk, then clean up resources. In
|
|
301
|
-
// general, Close out of the blue signals an error (or a forced
|
|
302
|
-
// closure, which may as well be an error).
|
|
303
|
-
//
|
|
304
|
-
// RUNNING [1] --- send Close ---> Closing [2] ---> recv Close --+
|
|
305
|
-
// | | [3]
|
|
306
|
-
// | +------ send CloseOk ------+
|
|
307
|
-
// recv Close recv CloseOk
|
|
308
|
-
// | |
|
|
309
|
-
// V V
|
|
310
|
-
// Ended [4] ---- send CloseOk ---> Closed [5]
|
|
311
|
-
//
|
|
312
|
-
// [1] All frames accepted; getting a Close frame from the server
|
|
313
|
-
// moves to Ended; client may initiate a close by sending Close
|
|
314
|
-
// itself.
|
|
315
|
-
// [2] Client has initiated a close; only CloseOk or (simulataneously
|
|
316
|
-
// sent) Close is accepted.
|
|
317
|
-
// [3] Simultaneous close
|
|
318
|
-
// [4] Server won't send any more frames; accept no more frames, send
|
|
319
|
-
// CloseOk.
|
|
320
|
-
// [5] Fully closed, client will send no more, server will send no
|
|
321
|
-
// more. Signal 'close' or 'error'.
|
|
322
|
-
//
|
|
323
|
-
// There are two signalling mechanisms used in the API. The first is
|
|
324
|
-
// that calling `close` will return a promise, that will either
|
|
325
|
-
// resolve once the connection or channel is cleanly shut down, or
|
|
326
|
-
// will reject if the shutdown times out.
|
|
327
|
-
//
|
|
328
|
-
// The second is the 'close' and 'error' events. These are
|
|
329
|
-
// emitted as above. The events will fire *before* promises are
|
|
330
|
-
// resolved.
|
|
331
|
-
|
|
332
|
-
// Close the connection without even giving a reason. Typical.
|
|
333
|
-
C.close = function(closeCallback) {
|
|
334
|
-
var k = closeCallback && function() { closeCallback(null); };
|
|
335
|
-
this.closeBecause("Cheers, thanks", constants.REPLY_SUCCESS, k);
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
// Close with a reason and a 'code'. I'm pretty sure RabbitMQ totally
|
|
339
|
-
// ignores these; maybe it logs them. The continuation will be invoked
|
|
340
|
-
// when the CloseOk has been received, and before the 'close' event.
|
|
341
|
-
C.closeBecause = function(reason, code, k) {
|
|
342
|
-
this.sendMethod(0, defs.ConnectionClose, {
|
|
343
|
-
replyText: reason,
|
|
344
|
-
replyCode: code,
|
|
345
|
-
methodId: 0, classId: 0
|
|
346
|
-
});
|
|
347
|
-
var s = stackCapture('closeBecause called: ' + reason);
|
|
348
|
-
this.toClosing(s, k);
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
C.closeWithError = function(reason, code, error) {
|
|
352
|
-
this.emit('error', error);
|
|
353
|
-
this.closeBecause(reason, code);
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
C.onSocketError = function(err) {
|
|
357
|
-
if (!this.expectSocketClose) {
|
|
358
|
-
// forestall any more calls to onSocketError, since we're signed
|
|
359
|
-
// up for `'error'` *and* `'end'`
|
|
360
|
-
this.expectSocketClose = true;
|
|
361
|
-
this.emit('error', err);
|
|
362
|
-
var s = stackCapture('Socket error');
|
|
363
|
-
this.toClosed(s, err);
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
function invalidOp(msg, stack) {
|
|
368
|
-
return function() {
|
|
369
|
-
throw new IllegalOperationError(msg, stack);
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function invalidateSend(conn, msg, stack) {
|
|
374
|
-
conn.sendMethod = conn.sendContent = conn.sendMessage =
|
|
375
|
-
invalidOp(msg, stack);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// A close has been initiated. Repeat: a close has been initiated.
|
|
379
|
-
// This means we should not send more frames, anyway they will be
|
|
380
|
-
// ignored. We also have to shut down all the channels.
|
|
381
|
-
C.toClosing = function(capturedStack, k) {
|
|
382
|
-
var send = this.sendMethod.bind(this);
|
|
383
|
-
|
|
384
|
-
this.accept = function(f) {
|
|
385
|
-
if (f.id === defs.ConnectionCloseOk) {
|
|
386
|
-
if (k) k();
|
|
387
|
-
var s = stackCapture('ConnectionCloseOk received');
|
|
388
|
-
this.toClosed(s, undefined);
|
|
389
|
-
}
|
|
390
|
-
else if (f.id === defs.ConnectionClose) {
|
|
391
|
-
send(0, defs.ConnectionCloseOk, {});
|
|
392
|
-
}
|
|
393
|
-
// else ignore frame
|
|
394
|
-
};
|
|
395
|
-
invalidateSend(this, 'Connection closing', capturedStack);
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
C._closeChannels = function(capturedStack) {
|
|
399
|
-
for (var i = 1; i < this.channels.length; i++) {
|
|
400
|
-
var ch = this.channels[i];
|
|
401
|
-
if (ch !== null) {
|
|
402
|
-
ch.channel.toClosed(capturedStack); // %%% or with an error? not clear
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
// A close has been confirmed. Cease all communication.
|
|
408
|
-
C.toClosed = function(capturedStack, maybeErr) {
|
|
409
|
-
this._closeChannels(capturedStack);
|
|
410
|
-
var info = fmt('Connection closed (%s)',
|
|
411
|
-
(maybeErr) ? maybeErr.toString() : 'by client');
|
|
412
|
-
// Tidy up, invalidate enverything, dynamite the bridges.
|
|
413
|
-
invalidateSend(this, info, capturedStack);
|
|
414
|
-
this.accept = invalidOp(info, capturedStack);
|
|
415
|
-
this.close = function(cb) {
|
|
416
|
-
cb && cb(new IllegalOperationError(info, capturedStack));
|
|
417
|
-
};
|
|
418
|
-
if (this.heartbeater) this.heartbeater.clear();
|
|
419
|
-
// This is certainly true now, if it wasn't before
|
|
420
|
-
this.expectSocketClose = true;
|
|
421
|
-
this.stream.end();
|
|
422
|
-
this.emit('close', maybeErr);
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
// ===
|
|
426
|
-
|
|
427
|
-
C.startHeartbeater = function() {
|
|
428
|
-
if (this.heartbeat === 0) return null;
|
|
429
|
-
else {
|
|
430
|
-
var self = this;
|
|
431
|
-
var hb = new Heart(this.heartbeat,
|
|
432
|
-
this.checkSend.bind(this),
|
|
433
|
-
this.checkRecv.bind(this));
|
|
434
|
-
hb.on('timeout', function() {
|
|
435
|
-
var hberr = new Error("Heartbeat timeout");
|
|
436
|
-
self.emit('error', hberr);
|
|
437
|
-
var s = stackCapture('Heartbeat timeout');
|
|
438
|
-
self.toClosed(s, hberr);
|
|
439
|
-
});
|
|
440
|
-
hb.on('beat', function() {
|
|
441
|
-
self.sendHeartbeat();
|
|
442
|
-
});
|
|
443
|
-
return hb;
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
// I use an array to keep track of the channels, rather than an
|
|
448
|
-
// object. The channel identifiers are numbers, and allocated by the
|
|
449
|
-
// connection. If I try to allocate low numbers when they are
|
|
450
|
-
// available (which I do, by looking from the start of the bitset),
|
|
451
|
-
// this ought to keep the array small, and out of 'sparse array
|
|
452
|
-
// storage'. I also set entries to null, rather than deleting them, in
|
|
453
|
-
// the expectation that the next channel allocation will fill the slot
|
|
454
|
-
// again rather than growing the array. See
|
|
455
|
-
// http://www.html5rocks.com/en/tutorials/speed/v8/
|
|
456
|
-
C.freshChannel = function(channel, options) {
|
|
457
|
-
var next = this.freeChannels.nextClearBit(1);
|
|
458
|
-
if (next < 0 || next > this.channelMax)
|
|
459
|
-
throw new Error("No channels left to allocate");
|
|
460
|
-
this.freeChannels.set(next);
|
|
461
|
-
|
|
462
|
-
var hwm = (options && options.highWaterMark) || DEFAULT_WRITE_HWM;
|
|
463
|
-
var writeBuffer = new PassThrough({
|
|
464
|
-
objectMode: true, highWaterMark: hwm
|
|
465
|
-
});
|
|
466
|
-
this.channels[next] = {channel: channel, buffer: writeBuffer};
|
|
467
|
-
writeBuffer.on('drain', function() {
|
|
468
|
-
channel.onBufferDrain();
|
|
469
|
-
});
|
|
470
|
-
this.muxer.pipeFrom(writeBuffer);
|
|
471
|
-
return next;
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
C.releaseChannel = function(channel) {
|
|
475
|
-
this.freeChannels.clear(channel);
|
|
476
|
-
var buffer = this.channels[channel].buffer;
|
|
477
|
-
buffer.end(); // will also cause it to be unpiped
|
|
478
|
-
this.channels[channel] = null;
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
C.acceptLoop = function() {
|
|
482
|
-
var self = this;
|
|
483
|
-
|
|
484
|
-
function go() {
|
|
485
|
-
try {
|
|
486
|
-
var f; while (f = self.recvFrame()) self.accept(f);
|
|
487
|
-
}
|
|
488
|
-
catch (e) {
|
|
489
|
-
self.emit('frameError', e);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
self.stream.on('readable', go);
|
|
493
|
-
go();
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
C.step = function(cb) {
|
|
497
|
-
var self = this;
|
|
498
|
-
function recv() {
|
|
499
|
-
var f;
|
|
500
|
-
try {
|
|
501
|
-
f = self.recvFrame();
|
|
502
|
-
}
|
|
503
|
-
catch (e) {
|
|
504
|
-
cb(e, null);
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
if (f) cb(null, f);
|
|
508
|
-
else self.stream.once('readable', recv);
|
|
509
|
-
}
|
|
510
|
-
recv();
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
C.checkSend = function() {
|
|
514
|
-
var check = this.sentSinceLastCheck;
|
|
515
|
-
this.sentSinceLastCheck = false;
|
|
516
|
-
return check;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
C.checkRecv = function() {
|
|
520
|
-
var check = this.recvSinceLastCheck;
|
|
521
|
-
this.recvSinceLastCheck = false;
|
|
522
|
-
return check;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
C.sendBytes = function(bytes) {
|
|
526
|
-
this.sentSinceLastCheck = true;
|
|
527
|
-
this.stream.write(bytes);
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
C.sendHeartbeat = function() {
|
|
531
|
-
return this.sendBytes(frame.HEARTBEAT_BUF);
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
var encodeMethod = defs.encodeMethod;
|
|
535
|
-
var encodeProperties = defs.encodeProperties;
|
|
536
|
-
|
|
537
|
-
C.sendMethod = function(channel, Method, fields) {
|
|
538
|
-
var frame = encodeMethod(Method, channel, fields);
|
|
539
|
-
this.sentSinceLastCheck = true;
|
|
540
|
-
var buffer = this.channels[channel].buffer;
|
|
541
|
-
return buffer.write(frame);
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
C.sendMessage = function(channel,
|
|
545
|
-
Method, fields,
|
|
546
|
-
Properties, props,
|
|
547
|
-
content) {
|
|
548
|
-
if (!Buffer.isBuffer(content))
|
|
549
|
-
throw new TypeError('content is not a buffer');
|
|
550
|
-
|
|
551
|
-
var mframe = encodeMethod(Method, channel, fields);
|
|
552
|
-
var pframe = encodeProperties(Properties, channel,
|
|
553
|
-
content.length, props);
|
|
554
|
-
var buffer = this.channels[channel].buffer;
|
|
555
|
-
this.sentSinceLastCheck = true;
|
|
556
|
-
|
|
557
|
-
var methodHeaderLen = mframe.length + pframe.length;
|
|
558
|
-
var bodyLen = (content.length > 0) ?
|
|
559
|
-
content.length + FRAME_OVERHEAD : 0;
|
|
560
|
-
var allLen = methodHeaderLen + bodyLen;
|
|
561
|
-
|
|
562
|
-
if (allLen < SINGLE_CHUNK_THRESHOLD) {
|
|
563
|
-
// Use `allocUnsafe` to avoid excessive allocations and CPU usage
|
|
564
|
-
// from zeroing. The returned Buffer is not zeroed and so must be
|
|
565
|
-
// completely filled to be used safely.
|
|
566
|
-
// See https://github.com/amqp-node/amqplib/pull/695
|
|
567
|
-
var all = Buffer.allocUnsafe(allLen);
|
|
568
|
-
var offset = mframe.copy(all, 0);
|
|
569
|
-
offset += pframe.copy(all, offset);
|
|
570
|
-
|
|
571
|
-
if (bodyLen > 0)
|
|
572
|
-
makeBodyFrame(channel, content).copy(all, offset);
|
|
573
|
-
return buffer.write(all);
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
if (methodHeaderLen < SINGLE_CHUNK_THRESHOLD) {
|
|
577
|
-
// Use `allocUnsafe` to avoid excessive allocations and CPU usage
|
|
578
|
-
// from zeroing. The returned Buffer is not zeroed and so must be
|
|
579
|
-
// completely filled to be used safely.
|
|
580
|
-
// See https://github.com/amqp-node/amqplib/pull/695
|
|
581
|
-
var both = Buffer.allocUnsafe(methodHeaderLen);
|
|
582
|
-
var offset = mframe.copy(both, 0);
|
|
583
|
-
pframe.copy(both, offset);
|
|
584
|
-
buffer.write(both);
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
buffer.write(mframe);
|
|
588
|
-
buffer.write(pframe);
|
|
589
|
-
}
|
|
590
|
-
return this.sendContent(channel, content);
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
var FRAME_OVERHEAD = defs.FRAME_OVERHEAD;
|
|
595
|
-
var makeBodyFrame = frame.makeBodyFrame;
|
|
596
|
-
|
|
597
|
-
C.sendContent = function(channel, body) {
|
|
598
|
-
if (!Buffer.isBuffer(body)) {
|
|
599
|
-
throw new TypeError(fmt("Expected buffer; got %s", body));
|
|
600
|
-
}
|
|
601
|
-
var writeResult = true;
|
|
602
|
-
var buffer = this.channels[channel].buffer;
|
|
603
|
-
|
|
604
|
-
var maxBody = this.frameMax - FRAME_OVERHEAD;
|
|
605
|
-
|
|
606
|
-
for (var offset = 0; offset < body.length; offset += maxBody) {
|
|
607
|
-
var end = offset + maxBody;
|
|
608
|
-
var slice = (end > body.length) ? body.slice(offset) : body.slice(offset, end);
|
|
609
|
-
var bodyFrame = makeBodyFrame(channel, slice);
|
|
610
|
-
writeResult = buffer.write(bodyFrame);
|
|
611
|
-
}
|
|
612
|
-
this.sentSinceLastCheck = true;
|
|
613
|
-
return writeResult;
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
var parseFrame = frame.parseFrame;
|
|
617
|
-
var decodeFrame = frame.decodeFrame;
|
|
618
|
-
|
|
619
|
-
C.recvFrame = function() {
|
|
620
|
-
// %%% identifying invariants might help here?
|
|
621
|
-
var frame = parseFrame(this.rest, this.frameMax);
|
|
622
|
-
|
|
623
|
-
if (!frame) {
|
|
624
|
-
var incoming = this.stream.read();
|
|
625
|
-
if (incoming === null) {
|
|
626
|
-
return false;
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
this.recvSinceLastCheck = true;
|
|
630
|
-
this.rest = Buffer.concat([this.rest, incoming]);
|
|
631
|
-
return this.recvFrame();
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
else {
|
|
635
|
-
this.rest = frame.rest;
|
|
636
|
-
return decodeFrame(frame);
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
function wrapStream(s) {
|
|
641
|
-
if (s instanceof Duplex) return s;
|
|
642
|
-
else {
|
|
643
|
-
var ws = new Duplex();
|
|
644
|
-
ws.wrap(s); //wraps the readable side of things
|
|
645
|
-
ws._write = function(chunk, encoding, callback) {
|
|
646
|
-
return s.write(chunk, encoding, callback);
|
|
647
|
-
};
|
|
648
|
-
return ws;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
function isFatalError(error) {
|
|
653
|
-
switch (error && error.code) {
|
|
654
|
-
case defs.constants.CONNECTION_FORCED:
|
|
655
|
-
case defs.constants.REPLY_SUCCESS:
|
|
656
|
-
return false;
|
|
657
|
-
default:
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
module.exports.Connection = Connection;
|
|
663
|
-
module.exports.isFatalError = isFatalError;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Different kind of credentials that can be supplied when opening a
|
|
6
|
-
// connection, corresponding to SASL mechanisms There's only two
|
|
7
|
-
// useful mechanisms that RabbitMQ implements:
|
|
8
|
-
// * PLAIN (send username and password in the plain)
|
|
9
|
-
// * EXTERNAL (assume the server will figure out who you are from
|
|
10
|
-
// context, i.e., your SSL certificate)
|
|
11
|
-
var codec = require('./codec')
|
|
12
|
-
|
|
13
|
-
module.exports.plain = function(user, passwd) {
|
|
14
|
-
return {
|
|
15
|
-
mechanism: 'PLAIN',
|
|
16
|
-
response: function() {
|
|
17
|
-
return Buffer.from(['', user, passwd].join(String.fromCharCode(0)))
|
|
18
|
-
},
|
|
19
|
-
username: user,
|
|
20
|
-
password: passwd
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports.amqplain = function(user, passwd) {
|
|
25
|
-
return {
|
|
26
|
-
mechanism: 'AMQPLAIN',
|
|
27
|
-
response: function() {
|
|
28
|
-
const buffer = Buffer.alloc(16384);
|
|
29
|
-
const size = codec.encodeTable(buffer, { LOGIN: user, PASSWORD: passwd}, 0);
|
|
30
|
-
return buffer.slice(4, size);
|
|
31
|
-
},
|
|
32
|
-
username: user,
|
|
33
|
-
password: passwd
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports.external = function() {
|
|
38
|
-
return {
|
|
39
|
-
mechanism: 'EXTERNAL',
|
|
40
|
-
response: function() { return Buffer.from(''); }
|
|
41
|
-
}
|
|
42
|
-
}
|