From 6fc0199f0130fa4c17afa80eeb64700263f80d03 Mon Sep 17 00:00:00 2001 From: Brandon Nozaki Miller Date: Sun, 27 Sep 2015 22:00:26 -0700 Subject: [PATCH] added defaults to allow local certs to be used when not specified --- .../basic-local-only/hello-client.js | 42 +++++++++++++++++++ .../basic-local-only/world-server.js | 42 +++++++++++++++++++ lib/socketServer.js | 4 ++ 3 files changed, 88 insertions(+) create mode 100644 example/TLSSocket/basic-local-only/hello-client.js create mode 100644 example/TLSSocket/basic-local-only/world-server.js diff --git a/example/TLSSocket/basic-local-only/hello-client.js b/example/TLSSocket/basic-local-only/hello-client.js new file mode 100644 index 0000000..2712a51 --- /dev/null +++ b/example/TLSSocket/basic-local-only/hello-client.js @@ -0,0 +1,42 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'hello'; +ipc.config.retry= 1500; +ipc.config.tls={ + rejectUnauthorized:false +}; + +ipc.connectToNet( + 'world', + function(){ + ipc.of.world.on( + 'connect', + function(){ + ipc.log('## connected to world ##'.rainbow, ipc.config.delay); + ipc.of.world.emit( + 'message', + 'hello' + ) + } + ); + ipc.of.world.on( + 'disconnect', + function(){ + ipc.log('disconnected from world'.notice); + } + ); + ipc.of.world.on( + 'message', + function(data){ + ipc.log('got a message from world : '.debug, data); + } + ); + } +); diff --git a/example/TLSSocket/basic-local-only/world-server.js b/example/TLSSocket/basic-local-only/world-server.js new file mode 100644 index 0000000..b7b93a2 --- /dev/null +++ b/example/TLSSocket/basic-local-only/world-server.js @@ -0,0 +1,42 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'world'; +ipc.config.retry= 1500; +//node-ipc will default to its local certs +ipc.config.tls={ + rejectUnauthorized:false +} + +ipc.serveNet( + function(){ + ipc.server.on( + 'message', + function(data,socket){ + ipc.log('got a message : '.debug, data); + ipc.server.emit( + socket, + 'message', + data+' world!' + ); + } + ); + + ipc.server.on( + 'socket.disconnected', + function(data,socket){ + console.log(arguments) + } + ); + } +); + +ipc.server.define.listen.message='This event type listens for message strings as value of data key.'; + +ipc.server.start(); diff --git a/lib/socketServer.js b/lib/socketServer.js index ae4330a..b0a84b9 100644 --- a/lib/socketServer.js +++ b/lib/socketServer.js @@ -110,9 +110,13 @@ function init(path,config,log,port){ server.log('starting TLS server'.debug,server.config.tls); if(server.config.tls.private){ server.config.tls.key=fs.readFileSync(server.config.tls.private); + }else{ + server.config.tls.key=fs.readFileSync(__dirname+'/../local-node-ipc-certs/private/server.key'); } if(server.config.tls.public){ server.config.tls.cert=fs.readFileSync(server.config.tls.public); + }else{ + server.config.tls.cert=fs.readFileSync(__dirname+'/../local-node-ipc-certs/server.pub'); } if(server.config.tls.dhparam){ server.config.tls.dhparam=fs.readFileSync(server.config.tls.dhparam);