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

smpp

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smpp - npm Package Compare versions

Comparing version 0.6.0-rc.3 to 0.6.0-rc.4

92

lib/smpp.js

@@ -39,6 +39,13 @@ var net = require('net'),

this._prevBytesRead = 0;
this.rootSocket = (function() {
if (self.socket._parent) return self.socket._parent;
return self.socket;
});
if (options.socket) {
// server mode
// server mode / socket is already connected.
this._mode = "server";
this.socket = options.socket;
this.remoteAddress = self.rootSocket().remoteAddress || self.remoteAddress;
this.remotePort = this.rootSocket().remotePort;
this.proxyProtocolProxy = this.rootSocket().proxyAddress ? { address: this.rootSocket().proxyAddress, port: this.rootSocket().proxyPort } : false;
} else {

@@ -64,6 +71,7 @@ // client mode

clearTimeout(connectTimeout);
self.remoteAddress = self.rootSocket().remoteAddress;
self.remotePort = self.rootSocket().remotePort;
self.remoteAddress = self.rootSocket().remoteAddress || self.remoteAddress;
self.remotePort = self.rootSocket().remotePort || self.remoteAddress;
self.debug("server.connected", "connected to server", {secure: options.tls});
self.emit('connect'); // @todo should emmit the session, but it would break BC
self.emitMetric("server.connected", 1);
self.emit('connect'); // @todo should emit the session, but it would break BC
if(self.options.auto_enquire_link_period) {

@@ -76,9 +84,11 @@ self._interval = setInterval(function() {

this.socket.on('secureConnect', (function() {
self.emit('secureConnect'); // @todo should emmit the session, but it would break BC
self.emit('secureConnect'); // @todo should emit the session, but it would break BC
}).bind(this));
}
this.socket.on('readable', function() {
if ( (self.socket.bytesRead - self._prevBytesRead) > 0 ) {
var bytesRead = self.socket.bytesRead - self._prevBytesRead;
if ( bytesRead > 0 ) {
// on disconnections the readable event receives 0 bytes, we do not want to debug that
self.debug("socket.data.in", null, {bytes: self.socket.bytesRead - self._prevBytesRead});
self.debug("socket.data.in", null, {bytes: bytesRead});
self.emitMetric("socket.data.in", bytesRead, {bytes: bytesRead});
self._prevBytesRead = self.socket.bytesRead;

@@ -93,4 +103,6 @@ }

self.debug("client.disconnected", "client has disconnected");
self.emitMetric("client.disconnected", 1);
} else {
self.debug("server.disconnected", "disconnected from server");
self.emitMetric("server.disconnected", 1);
}

@@ -105,3 +117,2 @@ self.emit('close');

clearTimeout(connectTimeout);
self.debug("socket.error", e.message, e);
if (self._interval) {

@@ -111,11 +122,6 @@ clearInterval(self._interval);

}
self.debug("socket.error", e.message, e);
self.emitMetric("socket.error", 1, {error: e});
self.emit('error', e); // Emitted errors will kill the program if they're not captured.
});
this.rootSocket = (function() {
if (self.socket._parent) return self.socket._parent;
return self.socket;
});
this.remoteAddress = this.rootSocket().remoteAddress;
this.remotePort = this.rootSocket().remotePort;
this.proxyProtocolProxy = this.rootSocket().proxyAddress ? { address: this.rootSocket().proxyAddress, port: this.rootSocket().proxyPort } : false;
}

@@ -125,2 +131,13 @@

Session.prototype.emitMetric = function(event, value, payload) {
this.emit('metrics', event || null, value || null, payload || {}, {
mode: this._mode || null,
remoteAddress: this.remoteAddress || null,
remotePort: this.remotePort || null,
remoteTls: this.options.tls || false,
sessionId: this._id || null,
session: this
});
}
Session.prototype.debug = function(type, msg, payload) {

@@ -139,3 +156,7 @@ if (type === undefined) type = null;

"pdu.command.out": "\x1b[32m",
"socket.error": "\x1b[41m\x1b[30m"
"pdu.command.error": "\x1b[41m\x1b[30m",
"socket.error": "\x1b[41m\x1b[30m",
"socket.data.in": "\x1b[2m",
"socket.data.out": "\x1b[2m",
"metrics": "\x1b[2m",
}

@@ -184,4 +205,6 @@ var now = new Date();

this.debug("pdu.command.in", pdu.command, pdu);
this.emitMetric("pdu.command.in", 1, pdu);
} catch (e) {
this.debug("pdu.command.error", e.message, e);
this.emitMetric("pdu.command.error", 1, {error: e});
this.emit('error', e);

@@ -203,3 +226,8 @@ return;

if (!this.socket.writable) {
this.debug('socket.data.error', null, {error: 'Socket is not writable'});
var errorObject = {
error: 'Socket is not writable',
errorType: 'socket_not_writable'
}
this.debug('socket.data.error', null, errorObject);
this.emitMetric("socket.data.error", 1, errorObject);
if (failureCallback) {

@@ -228,6 +256,15 @@ pdu.command_status = defs.errors.ESME_RSUBMITFAIL;

this.debug('pdu.command.out', pdu.command, pdu);
this.emitMetric("pdu.command.out", 1, pdu);
var buffer = pdu.toBuffer();
this.socket.write(buffer, (function(err) {
if (err) {
this.debug('socket.data.error', null, {error:'Cannot write command ' + pdu.command + ' to socket'});
this.debug('socket.data.error', null, {
error:'Cannot write command ' + pdu.command + ' to socket',
errorType: 'socket_write_error'
});
this.emitMetric("socket.data.error", 1, {
error: err,
errorType: 'socket_write_error',
pdu: pdu
});
if (!pdu.isResponse() && this._callbacks[pdu.sequence_number]) {

@@ -238,12 +275,12 @@ delete this._callbacks[pdu.sequence_number];

pdu.command_status = defs.errors.ESME_RSUBMITFAIL;
failureCallback(pdu);
failureCallback(pdu, err);
}
return;
} else {
this.debug("socket.data.out", null, {bytes: buffer.length, error: err});
this.emitMetric("socket.data.out", buffer.length, {bytes: buffer.length});
this.emit('send', pdu);
if (sendCallback) {
sendCallback(pdu);
}
}
this.debug("socket.data.out", null, {bytes: buffer.length});
this.emit('send', pdu);
if (sendCallback) {
sendCallback(pdu);
}
}).bind(this));

@@ -359,2 +396,3 @@ return true;

self.emit('session', session);
session.emitMetric("client.connected", 1);
});

@@ -450,3 +488,3 @@

}
if (clientOptions.tls && !clientOptions.hasOwnProperty("rejectUnauthorized")) {
if (clientOptions.tls && !clientOptions.hasOwnProperty("rejectUnauthorized")) {
clientOptions.rejectUnauthorized = false; // Allow self signed certificates by default

@@ -453,0 +491,0 @@ }

{
"name": "smpp",
"version": "0.6.0-rc.3",
"version": "0.6.0-rc.4",
"description": "SMPP client and server implementation in node.js",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/farhadi/node-smpp",

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