Merge branch 'Dexus-master'
This commit is contained in:
+12
-4
@@ -3,6 +3,7 @@
|
|||||||
var log = require('winston'),
|
var log = require('winston'),
|
||||||
merge = require('utils-merge'),
|
merge = require('utils-merge'),
|
||||||
net = require('net'),
|
net = require('net'),
|
||||||
|
tls = require('tls'),
|
||||||
session = require('./session');
|
session = require('./session');
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
@@ -11,10 +12,10 @@ function login() {
|
|||||||
|
|
||||||
loginPdu = {
|
loginPdu = {
|
||||||
'cmdName': 'bind_transceiver',
|
'cmdName': 'bind_transceiver',
|
||||||
'seqNr': this.ourSeqNr,
|
'seqNr': this.ourSeqNr,
|
||||||
'params': {
|
'params': {
|
||||||
'system_id': this.options.username,
|
'system_id': this.options.username,
|
||||||
'password': this.options.password
|
'password': this.options.password
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ function clientSession(sock, options) {
|
|||||||
* @param func callback(err, session)
|
* @param func callback(err, session)
|
||||||
*/
|
*/
|
||||||
function client(options, callback) {
|
function client(options, callback) {
|
||||||
var sock = new net.Socket();
|
var sock;
|
||||||
|
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
@@ -107,11 +108,18 @@ function client(options, callback) {
|
|||||||
'port': 2775,
|
'port': 2775,
|
||||||
'username': 'user',
|
'username': 'user',
|
||||||
'password': 'pass',
|
'password': 'pass',
|
||||||
|
'tls': false,
|
||||||
'enqLinkTiming': 20000 // 20 sec
|
'enqLinkTiming': 20000 // 20 sec
|
||||||
}, options || {});
|
}, options || {});
|
||||||
|
|
||||||
|
if (options && options.tls && option.tls === true) {
|
||||||
|
sock = new tls.Socket();
|
||||||
|
} else {
|
||||||
|
sock = new net.Socket();
|
||||||
|
}
|
||||||
|
|
||||||
log.debug('larvitsmpp: lib/client.js: client() - Connecting to ' + options.host + ':' + options.port);
|
log.debug('larvitsmpp: lib/client.js: client() - Connecting to ' + options.host + ':' + options.port);
|
||||||
sock.connect(options.port, options.host, function() {
|
sock.connect(options, function() {
|
||||||
var session = clientSession(sock, options);
|
var session = clientSession(sock, options);
|
||||||
|
|
||||||
log.info('larvitsmpp: lib/client.js: client() - Connected to ' + sock.remoteAddress + ':' + sock.remotePort);
|
log.info('larvitsmpp: lib/client.js: client() - Connected to ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||||
|
|||||||
+16
-6
@@ -1,8 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var log = require('winston'),
|
var log = require('winston'),
|
||||||
merge = require('utils-merge'),
|
merge = require('utils-merge'),
|
||||||
net = require('net'),
|
net = require('net'),
|
||||||
|
tls = require('tls'),
|
||||||
session = require('./session'),
|
session = require('./session'),
|
||||||
smppUtils = require('./utils');
|
smppUtils = require('./utils');
|
||||||
|
|
||||||
@@ -117,18 +118,18 @@ function serverSession(sock, options) {
|
|||||||
if (pduObj.cmdName === 'unbind') {
|
if (pduObj.cmdName === 'unbind') {
|
||||||
returnObj.sendReturn(pduObj, 'ESME_ROK', undefined, true);
|
returnObj.sendReturn(pduObj, 'ESME_ROK', undefined, true);
|
||||||
|
|
||||||
// If client is not logged in, always run the login function
|
// If client is not logged in, always run the login function
|
||||||
} else if (returnObj.loggedIn === false) {
|
} else if (returnObj.loggedIn === false) {
|
||||||
log.debug('larvitsmpp: lib/server.js: serverSession() - returnObj.handleIncomingPdu() - Not logged in, running login function');
|
log.debug('larvitsmpp: lib/server.js: serverSession() - returnObj.handleIncomingPdu() - Not logged in, running login function');
|
||||||
returnObj.login(pduObj);
|
returnObj.login(pduObj);
|
||||||
|
|
||||||
// Client is logged in, try to match a handling function
|
// Client is logged in, try to match a handling function
|
||||||
} else if (typeof returnObj.handleCmd[pduObj.cmdName] === 'function') {
|
} else if (typeof returnObj.handleCmd[pduObj.cmdName] === 'function') {
|
||||||
log.debug('larvitsmpp: lib/server.js: serverSession() - returnObj.on(incomingPduObj) - Running cmd handling function returnObj.handleCmd.' + pduObj.cmdName + '()');
|
log.debug('larvitsmpp: lib/server.js: serverSession() - returnObj.on(incomingPduObj) - Running cmd handling function returnObj.handleCmd.' + pduObj.cmdName + '()');
|
||||||
|
|
||||||
returnObj.handleCmd[pduObj.cmdName](pduObj);
|
returnObj.handleCmd[pduObj.cmdName](pduObj);
|
||||||
|
|
||||||
// No command handling function is registered, return error "invalid command"
|
// No command handling function is registered, return error "invalid command"
|
||||||
} else {
|
} else {
|
||||||
log.info('larvitsmpp: lib/server.js: serverSession() - returnObj.on(incomingPduObj) - No handling function found for command: "' + pduObj.cmdName + '"');
|
log.info('larvitsmpp: lib/server.js: serverSession() - returnObj.on(incomingPduObj) - No handling function found for command: "' + pduObj.cmdName + '"');
|
||||||
|
|
||||||
@@ -146,6 +147,8 @@ function serverSession(sock, options) {
|
|||||||
* @param func callback(err, session)
|
* @param func callback(err, session)
|
||||||
*/
|
*/
|
||||||
function server(options, callback) {
|
function server(options, callback) {
|
||||||
|
var tlsOrNet;
|
||||||
|
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
@@ -153,14 +156,21 @@ function server(options, callback) {
|
|||||||
|
|
||||||
// Set default options
|
// Set default options
|
||||||
options = merge({
|
options = merge({
|
||||||
'port': 2775,
|
'port': 2775,
|
||||||
|
'tls': false,
|
||||||
'timeout': 40000 // 40 sec
|
'timeout': 40000 // 40 sec
|
||||||
}, options || {});
|
}, options || {});
|
||||||
|
|
||||||
|
if (options && options.tls && option.tls === true) {
|
||||||
|
tlsOrNet = tls;
|
||||||
|
} else {
|
||||||
|
tlsOrNet = net;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a server instance, and chain the listen function to it
|
// Create a server instance, and chain the listen function to it
|
||||||
// The function passed to net.createServer() becomes the event handler for the 'connection' event
|
// The function passed to net.createServer() becomes the event handler for the 'connection' event
|
||||||
// The sock object the callback function receives UNIQUE for each connection
|
// The sock object the callback function receives UNIQUE for each connection
|
||||||
net.createServer(function(sock) {
|
tlsOrNet.createServer(options, function(sock) {
|
||||||
var returnObj = serverSession(sock, options);
|
var returnObj = serverSession(sock, options);
|
||||||
|
|
||||||
// We have a connection - a socket object is assigned to the connection automatically
|
// We have a connection - a socket object is assigned to the connection automatically
|
||||||
|
|||||||
Reference in New Issue
Block a user