Comparing version 1.0.0-alpha.5 to 1.0.0-alpha.6
@@ -7,2 +7,3 @@ # Change Log | ||
- Support sending plain log requests in lib #13 | ||
- Support compression #19 | ||
@@ -9,0 +10,0 @@ ### Changes |
{ | ||
"name": "residue", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-alpha.6", | ||
"description": "Logging client for real-time centralized logging server.", | ||
@@ -5,0 +5,0 @@ "main": "residue.js", |
@@ -10,5 +10,9 @@ بسم الله الرَّحْمَنِ الرَّحِيمِ | ||
## Crypto Module | ||
This library depends on [NodeJS Crypto Module](https://nodejs.org/api/crypto.html). If it is not available, library will fall down to use [Ripe](https://github.com/muflihun/ripe) command-line tool. If none is available, library will not work. | ||
## Native API | ||
This library depends on following native modules, without them library will not work: | ||
* [Crypto Module](https://nodejs.org/api/crypto.html) | ||
* [ZLib Module](https://nodejs.org/api/zlib.html) | ||
* [Net Module](https://nodejs.org/api/net.html) | ||
## API | ||
@@ -15,0 +19,0 @@ #### `connect(params)` |
@@ -13,10 +13,5 @@ // | ||
const net = require('net'); | ||
const zlib = require('zlib'); | ||
const crypto = require('crypto'); | ||
const NodeRSA = require('node-rsa'); | ||
let crypto; | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) { | ||
console.log('crypto module (https://nodejs.org/api/crypto.html) not found.\ | ||
\nThis library will use ripe cli tool. Please make sure it is available.'); | ||
} | ||
@@ -71,3 +66,4 @@ const Params = { | ||
ALLOW_PLAIN_LOG_REQUEST: 8, | ||
ALLOW_BULK_LOG_REQUEST: 16 | ||
ALLOW_BULK_LOG_REQUEST: 16, | ||
COMPRESSION: 512 | ||
}; | ||
@@ -113,3 +109,3 @@ | ||
// the server | ||
sendRequest: function(request, socket, nolock /* = false */, sendPlain /* = false */) { | ||
sendRequest: function(request, socket, nolock /* = false */, sendPlain /* = false */, compress /* = false */) { | ||
if (typeof nolock === 'undefined') { | ||
@@ -121,6 +117,16 @@ nolock = false; | ||
} | ||
if (typeof compress === 'undefined') { | ||
compress = false; | ||
} | ||
if (!nolock && Params.lock) { | ||
Params.back_log.push({r: request, s: socket, plain: sendPlain}); | ||
Params.back_log.push({r: request, s: socket, sendPlain: sendPlain, compress: compress}); | ||
return; | ||
} | ||
if (sendPlain) { | ||
request.client_id = Params.connection.client_id; | ||
} | ||
let finalRequest = JSON.stringify(request); | ||
if (compress) { | ||
finalRequest = new Buffer(zlib.deflateSync(finalRequest)).toString('base64'); | ||
} | ||
let encryptedRequest; | ||
@@ -131,3 +137,3 @@ if (!sendPlain) { | ||
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(Params.connection.key, 'hex'), iv); | ||
encryptedRequest = iv.toString('hex') + ':' + Params.connection.client_id + ':' + cipher.update(JSON.stringify(request), 'utf-8', 'base64') + cipher.final('base64') + PACKET_DELIMITER; | ||
encryptedRequest = iv.toString('hex') + ':' + Params.connection.client_id + ':' + cipher.update(finalRequest, 'utf-8', 'base64') + cipher.final('base64') + PACKET_DELIMITER; | ||
} catch (err) { | ||
@@ -137,4 +143,3 @@ Utils.debugLog(err); | ||
} else { | ||
request.client_id = Params.connection.client_id; | ||
encryptedRequest = JSON.stringify(request) + PACKET_DELIMITER; | ||
encryptedRequest = finalRequest + PACKET_DELIMITER; | ||
} | ||
@@ -151,3 +156,3 @@ Utils.vLog(9, 'Key: ' + Params.connection.key); | ||
const item = Params.back_log.splice(0, 1)[0]; | ||
Utils.sendRequest(item.r, item.s, false, item.plain); | ||
Utils.sendRequest(item.r, item.s, false, item.sendPlain, item.compress); | ||
} | ||
@@ -430,3 +435,3 @@ }, 10); | ||
} | ||
Utils.sendRequest(request, Params.logging_socket, false, Params.options.plain_request && Utils.hasFlag(Flag.ALLOW_PLAIN_LOG_REQUEST)); | ||
Utils.sendRequest(request, Params.logging_socket, false, Params.options.plain_request && Utils.hasFlag(Flag.ALLOW_PLAIN_LOG_REQUEST), Utils.hasFlag(Flag.COMPRESSION)); | ||
} | ||
@@ -433,0 +438,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
21357
515
29