Add TLS Support
This commit is contained in:
+9
-2
@@ -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() {
|
||||||
@@ -94,7 +95,6 @@ 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();
|
|
||||||
|
|
||||||
// Set default options
|
// Set default options
|
||||||
options = merge({
|
options = merge({
|
||||||
@@ -102,11 +102,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){
|
||||||
|
var sock = new tls.Socket();
|
||||||
|
} else {
|
||||||
|
var 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);
|
||||||
|
|||||||
+9
-1
@@ -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'),
|
||||||
smppUtils = require('./utils');
|
smppUtils = require('./utils');
|
||||||
|
|
||||||
@@ -154,13 +155,20 @@ 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){
|
||||||
|
var tls_or_net = tls;
|
||||||
|
} else {
|
||||||
|
var tls_or_net = 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) {
|
tls_or_net.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