cleaning up format

This commit is contained in:
Brandon Nozaki Miller 2016-01-10 04:57:08 -08:00
parent f176a01d1b
commit 6278fd472b
20 changed files with 971 additions and 951 deletions

View file

@ -38,4 +38,4 @@ ipc.connectToNet(
}
);
console.log(ipc);
console.log(ipc);

View file

@ -1,6 +1,10 @@
'use strict';
const Message = require('js-message');
const parser={
parse : parseDataEvents,
format : formatData,
delimiter : '\f'
};
function formatData(message){
if(!message.data){
@ -20,10 +24,4 @@ function parseDataEvents(data){
return events;
}
const parser={
parse : parseDataEvents,
format : formatData,
delimiter : '\f'
};
module.exports=parser;

View file

@ -1,3 +1,5 @@
'use strict';
const net = require('net'),
tls = require('tls'),
fs = require('fs'),
@ -72,16 +74,16 @@ function init(path,config,log,port){
sockets : [],
emit : emit,
broadcast : broadcast,
onStart : function(socket){
onStart : function onStart(socket){
this.trigger(
'start',
socket
);
},
stop:function(){
stop:function stop(){
server.server.close();
},
start : function(){
start : function start(){
if(!this.path){
server.log('Socket Server Path not specified, refusing to start'.warn);
return;
@ -89,244 +91,240 @@ function init(path,config,log,port){
fs.unlink(
this.path,
(
function(server){
return function () {
server.log('starting server on '.debug,server.path.variable,((server.port)?':'+server.port:'').variable);
function () {
server.log('starting server on '.debug,server.path.variable,((server.port)?':'+server.port:'').variable);
if(!server.udp4 && !server.udp6){
if(!server.config.tls){
server.server=net.createServer(
serverCreated
);
}else{
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);
}
if(server.config.tls.trustedConnections){
if(typeof server.config.tls.trustedConnections === 'string'){
server.config.tls.trustedConnections=[server.config.tls.trustedConnections];
}
server.config.tls.ca=[];
for(let i=0; i<server.config.tls.trustedConnections.length; i++){
server.config.tls.ca.push(
fs.readFileSync(server.config.tls.trustedConnections[i])
);
}
}
server.server=tls.createServer(
server.config.tls,
serverCreated
);
}
}else{
function UDPWrite(message,socket){
let data=new Buffer(message, server.config.encoding);
server.server.send(
data,
0,
data.length,
socket.port,
socket.address,
function(err, bytes) {
if(err){
server.log('error writing data to socket'.warn,err);
server.trigger(
'error',
function(err){
server.trigger('error',err);
}
);
}
}
);
}
server.server=dgram.createSocket(
((server.udp4)? 'udp4':'udp6')
);
server.server.write=UDPWrite;
server.server.on(
'listening',
function () {
serverCreated(server.server);
}
);
}
server.server.on(
'error',
function(err){
server.log('server error'.warn,err);
server.trigger(
'error',
err
);
}
if(!server.udp4 && !server.udp6){
if(!server.config.tls){
server.server=net.createServer(
serverCreated
);
server.server.maxConnections=server.config.maxConnections;
function serverCreated(socket) {
server.sockets.push(socket);
if(socket.setEncoding){
socket.setEncoding(server.config.encoding);
}else{
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);
}
if(server.config.tls.trustedConnections){
if(typeof server.config.tls.trustedConnections === 'string'){
server.config.tls.trustedConnections=[server.config.tls.trustedConnections];
}
server.log('## socket connection to server detected ##'.rainbow);
socket.on(
'close',
function(socket){
server.config.tls.ca=[];
for(let i=0; i<server.config.tls.trustedConnections.length; i++){
server.config.tls.ca.push(
fs.readFileSync(server.config.tls.trustedConnections[i])
);
}
}
server.server=tls.createServer(
server.config.tls,
serverCreated
);
}
}else{
function UDPWrite(message,socket){
let data=new Buffer(message, server.config.encoding);
server.server.send(
data,
0,
data.length,
socket.port,
socket.address,
function(err, bytes) {
if(err){
server.log('error writing data to socket'.warn,err);
server.trigger(
'close',
socket
'error',
function(err){
server.trigger('error',err);
}
);
}
);
}
);
}
socket.on(
'error',
function(err){
server.log('server socket error'.warn,err);
server.server=dgram.createSocket(
((server.udp4)? 'udp4':'udp6')
);
server.server.write=UDPWrite;
server.server.on(
'listening',
function () {
serverCreated(server.server);
}
);
}
server.trigger('error',err);
}
);
server.server.on(
'error',
function(err){
server.log('server error'.warn,err);
socket.on(
'data',
function(data,UDPSocket){
let sock=((server.udp4 || server.udp6)? UDPSocket : socket);
if(server.config.rawBuffer){
data=new Buffer(data,this.encoding);
server.trigger(
'data',
data,
sock
);
return;
}
server.trigger(
'error',
err
);
}
);
if(!this.ipcBuffer){
this.ipcBuffer='';
}
server.server.maxConnections=server.config.maxConnections;
data=(this.ipcBuffer+=data);
function serverCreated(socket) {
server.sockets.push(socket);
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
server.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice);
return;
}
this.ipcBuffer='';
data=eventParser.parse(data);
while(data.length>0){
let message=new Message;
message.load(data.shift());
server.log('received event of : '.debug,message.type.data,message.data);
if(message.data.id)
sock.id=message.data.id;
server.trigger(
message.type,
message.data,
sock
);
}
}
);
socket.on(
'message',
function(msg,rinfo) {
if (!rinfo){
return;
}
server.log('Received UDP message from '.debug, rinfo.address.variable, rinfo.port);
let data;
if(server.config.rawSocket){
data=new Buffer(msg,this.encoding);
}else{
data=msg.toString();
}
socket.emit('data',data,rinfo);
}
);
if(socket.setEncoding){
socket.setEncoding(server.config.encoding);
}
server.log('## socket connection to server detected ##'.rainbow);
socket.on(
'close',
function(socket){
server.trigger(
'connect',
'close',
socket
);
}
);
socket.on(
'error',
function(err){
server.log('server socket error'.warn,err);
server.trigger('error',err);
}
);
socket.on(
'data',
function(data,UDPSocket){
let sock=((server.udp4 || server.udp6)? UDPSocket : socket);
if(server.config.rawBuffer){
data=new Buffer(data,this.encoding);
server.trigger(
'data',
data,
sock
);
return;
}
}
function started(socket){
server.onStart(socket);
}
if(!port){
server.log('starting server as'.debug, 'Unix || Windows Socket'.variable);
if (process.platform ==='win32'){
server.path = server.path.replace(/^\//, '');
server.path = server.path.replace(/\//g, '-');
server.path= '\\\\.\\pipe\\'+server.path;
}
server.server.listen(
server.path,
started
);
return;
}
if(!server.udp4 && !server.udp6){
server.log('starting server as'.debug, (server.config.tls?'TLS':'TCP').variable);
server.server.listen(
server.port,
server.path,
started
);
return;
}
server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable);
server.server.bind(
server.port,
server.path
);
started(
{
address : server.path,
port : server.port
if(!this.ipcBuffer){
this.ipcBuffer='';
}
);
};
data=(this.ipcBuffer+=data);
if(data.slice(-1)!=eventParser.delimiter || data.indexOf(eventParser.delimiter) == -1){
server.log('Implementing larger buffer for this socket message. You may want to consider smaller messages'.notice);
return;
}
this.ipcBuffer='';
data=eventParser.parse(data);
while(data.length>0){
let message=new Message;
message.load(data.shift());
server.log('received event of : '.debug,message.type.data,message.data);
if(message.data.id)
sock.id=message.data.id;
server.trigger(
message.type,
message.data,
sock
);
}
}
);
socket.on(
'message',
function(msg,rinfo) {
if (!rinfo){
return;
}
server.log('Received UDP message from '.debug, rinfo.address.variable, rinfo.port);
let data;
if(server.config.rawSocket){
data=new Buffer(msg,this.encoding);
}else{
data=msg.toString();
}
socket.emit('data',data,rinfo);
}
);
server.trigger(
'connect',
socket
);
if(server.config.rawBuffer){
return;
}
}
)(this)
function started(socket){
server.onStart(socket);
}
if(!port){
server.log('starting server as'.debug, 'Unix || Windows Socket'.variable);
if (process.platform ==='win32'){
server.path = server.path.replace(/^\//, '');
server.path = server.path.replace(/\//g, '-');
server.path= '\\\\.\\pipe\\'+server.path;
}
server.server.listen(
server.path,
started
);
return;
}
if(!server.udp4 && !server.udp6){
server.log('starting server as'.debug, (server.config.tls?'TLS':'TCP').variable);
server.server.listen(
server.port,
server.path,
started
);
return;
}
server.log('starting server as'.debug,((server.udp4)? 'udp4':'udp6').variable);
server.server.bind(
server.port,
server.path
);
started(
{
address : server.path,
port : server.port
}
);
}
);
}
};

View file

@ -106,7 +106,7 @@ function serve(path,callback){
}
if(!callback){
callback=function(){};
callback=emptyCallback;
}
ipc.server=new Server(
@ -121,6 +121,10 @@ function serve(path,callback){
);
}
function emptyCallback(){
//Do Nothing
}
function serveNet(host,port,UDPType,callback){
if(typeof host=='number'){
callback=UDPType;
@ -174,7 +178,7 @@ function serveNet(host,port,UDPType,callback){
}
if(!callback){
callback=function(){};
callback=emptyCallback;
}
ipc.server=new Server(
@ -201,7 +205,7 @@ function connect(id,path,callback){
}
if(!callback){
callback=function(){};
callback=emptyCallback;
}
if(!id){
@ -288,7 +292,7 @@ function connectNet(id,host,port,callback){
callback=false;
}
if(!callback){
callback=function(){};
callback=emptyCallback;
}
if(ipc.of[id]){

File diff suppressed because one or more lines are too long

View file

@ -20,9 +20,9 @@
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">67.65% </span>
<span class="strong">67.49% </span>
<span class="quiet">Statements</span>
<span class='fraction'>274/405</span>
<span class='fraction'>272/403</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">56.37% </span>
@ -30,14 +30,14 @@
<span class='fraction'>115/204</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">81.4% </span>
<span class="strong">80.95% </span>
<span class="quiet">Functions</span>
<span class='fraction'>35/43</span>
<span class='fraction'>34/42</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">67.65% </span>
<span class="strong">67.49% </span>
<span class="quiet">Lines</span>
<span class='fraction'>274/405</span>
<span class='fraction'>272/403</span>
</div>
</div>
</div>
@ -73,15 +73,15 @@
<tr>
<td class="file medium" data-value="node-ipc/lib/"><a href="node-ipc/lib/index.html">node-ipc/lib/</a></td>
<td data-value="68.15" class="pic medium"><div class="chart"><div class="cover-fill" style="width: 68%;"></div><div class="cover-empty" style="width:32%;"></div></div></td>
<td data-value="68.15" class="pct medium">68.15%</td>
<td data-value="270" class="abs medium">184/270</td>
<td data-value="67.91" class="pic medium"><div class="chart"><div class="cover-fill" style="width: 67%;"></div><div class="cover-empty" style="width:33%;"></div></div></td>
<td data-value="67.91" class="pct medium">67.91%</td>
<td data-value="268" class="abs medium">182/268</td>
<td data-value="54.55" class="pct medium">54.55%</td>
<td data-value="132" class="abs medium">72/132</td>
<td data-value="87.88" class="pct high">87.88%</td>
<td data-value="33" class="abs high">29/33</td>
<td data-value="68.15" class="pct medium">68.15%</td>
<td data-value="270" class="abs medium">184/270</td>
<td data-value="87.5" class="pct high">87.5%</td>
<td data-value="32" class="abs high">28/32</td>
<td data-value="67.91" class="pct medium">67.91%</td>
<td data-value="268" class="abs medium">182/268</td>
</tr>
</tbody>
@ -90,7 +90,7 @@
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="prettify.js"></script>

View file

@ -77,7 +77,7 @@
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="../prettify.js"></script>

View file

@ -20,9 +20,9 @@
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">73.08% </span>
<span class="strong">72.82% </span>
<span class="quiet">Statements</span>
<span class='fraction'>76/104</span>
<span class='fraction'>75/103</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">52.38% </span>
@ -32,12 +32,12 @@
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>11/11</span>
<span class='fraction'>10/10</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">73.08% </span>
<span class="strong">72.82% </span>
<span class="quiet">Lines</span>
<span class='fraction'>76/104</span>
<span class='fraction'>75/103</span>
</div>
</div>
</div>
@ -278,7 +278,10 @@
233
234
235
236</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
236
237</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
@ -296,6 +299,7 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
@ -439,8 +443,6 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">6×</span>
@ -456,7 +458,6 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
@ -481,6 +482,7 @@
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
@ -513,16 +515,18 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var net = require('net'),
tls = require('tls'),
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
&nbsp;
const net = require('net'),
tls = require('tls'),
eventParser = require('../lib/eventParser.js'),
pubsub = require('event-pubsub'),
Message = require('js-message'),
fs = require('fs'),
Queue = require('js-queue');
Pubsub = require('event-pubsub'),
Message = require('js-message'),
fs = require('fs'),
Queue = require('js-queue');
&nbsp;
function init(config,log){
var client={
let client={
config : config,
queue : new Queue,
socket : false,
@ -530,8 +534,9 @@ function init(config,log){
emit : emit,
log : log,
retriesRemaining:config.maxRetries||<span class="branch-1 cbranch-no" title="branch not covered" >0</span>
}
new pubsub(client);
};
&nbsp;
new Pubsub(client);
&nbsp;
return client;
}
@ -539,7 +544,7 @@ function init(config,log){
function emit(type,data){
this.log('dispatching event to '.debug, this.id.variable, this.path.variable,' : ', type.data,',', data);
&nbsp;
var message=new Message;
let message=new Message;
message.type=type;
message.data=data;
&nbsp;
@ -557,7 +562,7 @@ function emit(type,data){
this.queue.add(
syncEmit.bind(this,message)
);
};
}
&nbsp;
function syncEmit(message){
this.log('dispatching event to '.debug, this.id.variable, this.path.variable,' : ', message.data);
@ -566,7 +571,7 @@ function syncEmit(message){
&nbsp;
function connect(){
//init client object for scope persistance especially inside of socket events.
var client=this;
let client=this;
&nbsp;
client.log('requested connection to '.debug, client.id.variable, client.path.variable);
<span class="missing-if-branch" title="if path not taken" >I</span>if(!this.path){
@ -577,7 +582,7 @@ function connect(){
if(!client.port){
client.log('Connecting client on Unix Socket :'.debug, client.path.variable);
&nbsp;
var path = client.path;
let path = client.path;
&nbsp;
<span class="missing-if-branch" title="if path not taken" >I</span>if (process.platform ==='win32' &amp;&amp; <span class="branch-1 cbranch-no" title="branch not covered" >!client.path.startsWith('\\\\.\\pipe\\'))</span>{
<span class="cstat-no" title="statement not covered" > path = path.replace(/^\//, '');</span>
@ -611,7 +616,7 @@ function connect(){
<span class="cstat-no" title="statement not covered" > client.config.tls.trustedConnections=[client.config.tls.trustedConnections];</span>
}
<span class="cstat-no" title="statement not covered" > client.config.tls.ca=[];</span>
<span class="cstat-no" title="statement not covered" > for(var i=0; i&lt;client.config.tls.trustedConnections.length; i++){</span>
<span class="cstat-no" title="statement not covered" > for(let i=0; i&lt;client.config.tls.trustedConnections.length; i++){</span>
<span class="cstat-no" title="statement not covered" > client.config.tls.ca.push(</span>
fs.readFileSync(client.config.tls.trustedConnections[i])
);
@ -640,7 +645,7 @@ function connect(){
&nbsp;
client.socket.on(
'connect',
function(){
function connectionMade(){
client.trigger('connect');
client.retriesRemaining=client.config.maxRetries;
client.log('retrying reset');
@ -649,7 +654,7 @@ function connect(){
&nbsp;
client.socket.on(
'close',
function(){
function connectionClosed(){
client.log('connection closed'.notice ,client.id.variable , client.path.variable, client.retriesRemaining+' tries remaining of '+client.config.maxRetries);
&nbsp;
if(
@ -660,7 +665,7 @@ function connect(){
client.log(
client.config.id.variable,
'exceeded connection rety amount of'.warn,
" or stopRetrying flag set."
' or stopRetrying flag set.'
);
&nbsp;
client.socket.destroy();
@ -673,22 +678,19 @@ function connect(){
client.isRetrying=true;
&nbsp;
setTimeout(
(
function(client){
return function(){
client.retriesRemaining--;
client.isRetrying=false;
client.connect();
setTimeout(
function(){
if(!client.isRetrying)
client.retriesRemaining=client.config.maxRetries;
},
100
)
}
}
)(client),
function retryTimeout(){
client.retriesRemaining--;
client.isRetrying=false;
client.connect();
setTimeout(
function resetRetriesCheck(){
if(!client.isRetrying){
client.retriesRemaining=client.config.maxRetries;
}
},
100
);
}.bind(null,client),
client.config.retry
);
&nbsp;
@ -713,8 +715,9 @@ function connect(){
<span class="cstat-no" title="statement not covered" > return;</span>
}
&nbsp;
<span class="missing-if-branch" title="else path not taken" >E</span>if(!this.ipcBuffer)
<span class="missing-if-branch" title="else path not taken" >E</span>if(!this.ipcBuffer){
this.ipcBuffer='';
}
&nbsp;
data=(this.ipcBuffer+=data);
&nbsp;
@ -725,13 +728,13 @@ function connect(){
&nbsp;
this.ipcBuffer='';
&nbsp;
var events = eventParser.parse(data);
var eCount = events.length;
for(var i=0; i&lt;eCount; i++){
var message=new Message;
const events = eventParser.parse(data);
const eCount = events.length;
for(let i=0; i&lt;eCount; i++){
let message=new Message;
message.load(events[i]);
&nbsp;
client.log('detected event of type '.debug, message.type.data, message.data);
client.log('detected event of type '.debug, message.type.data, message.data);
client.trigger(
message.type,
message.data
@ -754,7 +757,7 @@ module.exports=init;
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="../../prettify.js"></script>

View file

@ -20,9 +20,9 @@
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">85.71% </span>
<span class="strong">84.62% </span>
<span class="quiet">Statements</span>
<span class='fraction'>12/14</span>
<span class='fraction'>11/13</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">50% </span>
@ -35,9 +35,9 @@
<span class='fraction'>2/2</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">85.71% </span>
<span class="strong">84.62% </span>
<span class="quiet">Lines</span>
<span class='fraction'>12/14</span>
<span class='fraction'>11/13</span>
</div>
</div>
</div>
@ -70,7 +70,13 @@
25
26
27
28</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
28</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">9×</span>
@ -91,13 +97,13 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var Message = require('js-message');
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
&nbsp;
const parser={
parse : parseDataEvents,
format : formatData,
delimiter : '\f'
};
&nbsp;
function formatData(message){
<span class="missing-if-branch" title="if path not taken" >I</span>if(!message.data){
@ -109,18 +115,12 @@ function formatData(message){
&nbsp;
message=message.JSON+parser.delimiter;
return message;
};
&nbsp;
function parseDataEvents(data){
var events=data.split(parser.delimiter);
events.pop();
return events;
}
&nbsp;
var parser={
parse : parseDataEvents,
format : formatData,
delimiter : '\f'
function parseDataEvents(data){
let events=data.split(parser.delimiter);
events.pop();
return events;
}
&nbsp;
module.exports=parser;
@ -130,7 +130,7 @@ module.exports=parser;
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="../../prettify.js"></script>

View file

@ -20,9 +20,9 @@
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">68.15% </span>
<span class="strong">67.91% </span>
<span class="quiet">Statements</span>
<span class='fraction'>184/270</span>
<span class='fraction'>182/268</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">54.55% </span>
@ -30,14 +30,14 @@
<span class='fraction'>72/132</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">87.88% </span>
<span class="strong">87.5% </span>
<span class="quiet">Functions</span>
<span class='fraction'>29/33</span>
<span class='fraction'>28/32</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">68.15% </span>
<span class="strong">67.91% </span>
<span class="quiet">Lines</span>
<span class='fraction'>184/270</span>
<span class='fraction'>182/268</span>
</div>
</div>
</div>
@ -60,28 +60,28 @@
</thead>
<tbody><tr>
<td class="file medium" data-value="client.js"><a href="client.js.html">client.js</a></td>
<td data-value="73.08" class="pic medium"><div class="chart"><div class="cover-fill" style="width: 73%;"></div><div class="cover-empty" style="width:27%;"></div></div></td>
<td data-value="73.08" class="pct medium">73.08%</td>
<td data-value="104" class="abs medium">76/104</td>
<td data-value="72.82" class="pic medium"><div class="chart"><div class="cover-fill" style="width: 72%;"></div><div class="cover-empty" style="width:28%;"></div></div></td>
<td data-value="72.82" class="pct medium">72.82%</td>
<td data-value="103" class="abs medium">75/103</td>
<td data-value="52.38" class="pct medium">52.38%</td>
<td data-value="42" class="abs medium">22/42</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="11" class="abs high">11/11</td>
<td data-value="73.08" class="pct medium">73.08%</td>
<td data-value="104" class="abs medium">76/104</td>
<td data-value="10" class="abs high">10/10</td>
<td data-value="72.82" class="pct medium">72.82%</td>
<td data-value="103" class="abs medium">75/103</td>
</tr>
<tr>
<td class="file high" data-value="eventParser.js"><a href="eventParser.js.html">eventParser.js</a></td>
<td data-value="85.71" class="pic high"><div class="chart"><div class="cover-fill" style="width: 85%;"></div><div class="cover-empty" style="width:15%;"></div></div></td>
<td data-value="85.71" class="pct high">85.71%</td>
<td data-value="14" class="abs high">12/14</td>
<td data-value="84.62" class="pic high"><div class="chart"><div class="cover-fill" style="width: 84%;"></div><div class="cover-empty" style="width:16%;"></div></div></td>
<td data-value="84.62" class="pct high">84.62%</td>
<td data-value="13" class="abs high">11/13</td>
<td data-value="50" class="pct medium">50%</td>
<td data-value="4" class="abs medium">2/4</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="2" class="abs high">2/2</td>
<td data-value="85.71" class="pct high">85.71%</td>
<td data-value="14" class="abs high">12/14</td>
<td data-value="84.62" class="pct high">84.62%</td>
<td data-value="13" class="abs high">11/13</td>
</tr>
<tr>
@ -103,7 +103,7 @@
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="../../prettify.js"></script>

View file

@ -410,7 +410,15 @@
365
366
367
368</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
368
369
370
371
372
373
374</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
@ -597,6 +605,7 @@
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
@ -634,6 +643,7 @@
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
@ -668,6 +678,8 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
@ -777,18 +789,20 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var net = require('net'),
tls = require('tls'),
fs = require('fs'),
dgram = require('dgram'),
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
&nbsp;
const net = require('net'),
tls = require('tls'),
fs = require('fs'),
dgram = require('dgram'),
eventParser = require('../lib/eventParser.js'),
pubsub = require('event-pubsub'),
Pubsub = require('event-pubsub'),
Message = require('js-message');
&nbsp;
function emit(socket, type, data){
this.log('dispatching event to socket'.debug, ' : ', type.data, data);
&nbsp;
var message=new Message;
let message=new Message;
message.type=type;
message.data=data;
&nbsp;
@ -811,14 +825,14 @@ function emit(socket, type, data){
socket
);
return;
};
}
&nbsp;
<span class="cstat-no" title="statement not covered" > socket.write(message);</span>
};
}
&nbsp;
<span class="fstat-no" title="function not covered" >function broadcast(type,data){</span>
<span class="cstat-no" title="statement not covered" > this.log('broadcasting event to all known sockets listening to '.debug, this.path.variable,' : ', ((this.port)?this.port:''), type, data);</span>
<span class="cstat-no" title="statement not covered" > var message=new Message;</span>
<span class="cstat-no" title="statement not covered" > this.log('broadcasting event to all known sockets listening to '.debug, this.path.variable,' : ', ((this.port)?this.port:''), type, data);</span>
<span class="cstat-no" title="statement not covered" > let message=new Message;</span>
<span class="cstat-no" title="statement not covered" > message.type=type;</span>
<span class="cstat-no" title="statement not covered" > message.data=data;</span>
&nbsp;
@ -829,18 +843,18 @@ function emit(socket, type, data){
}
&nbsp;
<span class="cstat-no" title="statement not covered" > if(this.udp4 || this.udp6){</span>
<span class="cstat-no" title="statement not covered" > for(var i=1, count=this.sockets.length; i&lt;count; i++){</span>
<span class="cstat-no" title="statement not covered" > for(let i=1, count=this.sockets.length; i&lt;count; i++){</span>
<span class="cstat-no" title="statement not covered" > this.server.write(message,this.sockets[i]);</span>
}
}else{
<span class="cstat-no" title="statement not covered" > for(var i=0, count=this.sockets.length; i&lt;count; i++){</span>
<span class="cstat-no" title="statement not covered" > for(let i=0, count=this.sockets.length; i&lt;count; i++){</span>
<span class="cstat-no" title="statement not covered" > this.sockets[i].write(message);</span>
}
}
};
}
&nbsp;
function init(path,config,log,port){
var server={
let server={
config : config,
path : path,
port : port,
@ -898,7 +912,7 @@ function init(path,config,log,port){
<span class="cstat-no" title="statement not covered" > server.config.tls.trustedConnections=[server.config.tls.trustedConnections];</span>
}
<span class="cstat-no" title="statement not covered" > server.config.tls.ca=[];</span>
<span class="cstat-no" title="statement not covered" > for(var i=0; i&lt;server.config.tls.trustedConnections.length; i++){</span>
<span class="cstat-no" title="statement not covered" > for(let i=0; i&lt;server.config.tls.trustedConnections.length; i++){</span>
<span class="cstat-no" title="statement not covered" > server.config.tls.ca.push(</span>
fs.readFileSync(server.config.tls.trustedConnections[i])
);
@ -911,7 +925,7 @@ function init(path,config,log,port){
}
}else{
function UDPWrite(message,socket){
var data=new Buffer(message, server.config.encoding);
let data=new Buffer(message, server.config.encoding);
server.server.send(
data,
0,
@ -939,7 +953,7 @@ function init(path,config,log,port){
server.server.on(
'listening',
function () {
serverCreated(server.server)
serverCreated(server.server);
}
);
}
@ -952,7 +966,7 @@ function init(path,config,log,port){
<span class="cstat-no" title="statement not covered" > server.trigger(</span>
'error',
err
)
);
}
);
&nbsp;
@ -961,8 +975,9 @@ function init(path,config,log,port){
function serverCreated(socket) {
server.sockets.push(socket);
&nbsp;
if(socket.setEncoding)
if(socket.setEncoding){
socket.setEncoding(server.config.encoding);
}
&nbsp;
server.log('## socket connection to server detected ##'.rainbow);
socket.on(
@ -987,7 +1002,7 @@ function init(path,config,log,port){
socket.on(
'data',
function(data,UDPSocket){
var sock=((server.udp4 || server.udp6)? UDPSocket : <span class="branch-1 cbranch-no" title="branch not covered" >socket)</span>;
let sock=((server.udp4 || server.udp6)? UDPSocket : <span class="branch-1 cbranch-no" title="branch not covered" >socket)</span>;
<span class="missing-if-branch" title="if path not taken" >I</span>if(server.config.rawBuffer){
<span class="cstat-no" title="statement not covered" > data=new Buffer(data,this.encoding);</span>
<span class="cstat-no" title="statement not covered" > server.trigger(</span>
@ -998,8 +1013,9 @@ function init(path,config,log,port){
<span class="cstat-no" title="statement not covered" > return;</span>
}
&nbsp;
<span class="missing-if-branch" title="else path not taken" >E</span>if(!this.ipcBuffer)
<span class="missing-if-branch" title="else path not taken" >E</span>if(!this.ipcBuffer){
this.ipcBuffer='';
}
&nbsp;
data=(this.ipcBuffer+=data);
&nbsp;
@ -1013,7 +1029,7 @@ function init(path,config,log,port){
data=eventParser.parse(data);
&nbsp;
while(data.length&gt;0){
var message=new Message;
let message=new Message;
message.load(data.shift());
&nbsp;
server.log('received event of : '.debug,message.type.data,message.data);
@ -1033,10 +1049,12 @@ function init(path,config,log,port){
socket.on(
'message',
function(msg,rinfo) {
<span class="missing-if-branch" title="if path not taken" >I</span>if (!rinfo)
<span class="missing-if-branch" title="if path not taken" >I</span>if (!rinfo){
<span class="cstat-no" title="statement not covered" > return;</span>
}
&nbsp;
server.log('Received UDP message from '.debug, rinfo.address.variable, rinfo.port);
var data;
let data;
&nbsp;
<span class="missing-if-branch" title="if path not taken" >I</span>if(server.config.rawSocket){
<span class="cstat-no" title="statement not covered" > data=new Buffer(msg,this.encoding);</span>
@ -1058,16 +1076,16 @@ function init(path,config,log,port){
}
&nbsp;
function started(socket){
server.onStart(socket)
server.onStart(socket);
}
&nbsp;
if(!port){
server.log('starting server as'.debug, 'Unix || Windows Socket'.variable);
<span class="missing-if-branch" title="if path not taken" >I</span>if (process.platform ==='win32'){
<span class="cstat-no" title="statement not covered" > server.path = server.path.replace(/^\//, '');</span>
<span class="cstat-no" title="statement not covered" > server.path = server.path.replace(/\//g, '-');</span>
<span class="cstat-no" title="statement not covered" > server.path= '\\\\.\\pipe\\'+server.path;</span>
}
<span class="cstat-no" title="statement not covered" > server.path = server.path.replace(/^\//, '');</span>
<span class="cstat-no" title="statement not covered" > server.path = server.path.replace(/\//g, '-');</span>
<span class="cstat-no" title="statement not covered" > server.path= '\\\\.\\pipe\\'+server.path;</span>
}
&nbsp;
server.server.listen(
server.path,
@ -1099,21 +1117,21 @@ function init(path,config,log,port){
port : server.port
}
);
}
};
}
)(this)
);
}
};
&nbsp;
new pubsub(server);
new Pubsub(server);
&nbsp;
server.on(
'close',
function(){
for(var i=0, count=server.sockets.length; i&lt;count; i++){
var socket=server.sockets[i];
var destroyedSocketId=false;
for(let i=0, count=server.sockets.length; i&lt;count; i++){
let socket=server.sockets[i];
let destroyedSocketId=false;
&nbsp;
<span class="missing-if-branch" title="else path not taken" >E</span>if(socket){
<span class="missing-if-branch" title="if path not taken" >I</span>if(socket.readable){
@ -1122,7 +1140,7 @@ function init(path,config,log,port){
}
&nbsp;
<span class="missing-if-branch" title="if path not taken" >I</span>if(socket.id){
<span class="cstat-no" title="statement not covered" > destroyedSocketId=socket.id;</span>
<span class="cstat-no" title="statement not covered" > destroyedSocketId=socket.id;</span>
}
&nbsp;
server.log('socket disconnected'.notice,' '+destroyedSocketId.variable);
@ -1150,7 +1168,7 @@ module.exports=init;
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="../../prettify.js"></script>

View file

@ -359,8 +359,10 @@
314
315
316
317</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
317
318</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
@ -675,14 +677,15 @@
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var os = require('os'),
dns = require('dns'),
util = require('util'),
colors = require('colors'),
pubsub = require('event-pubsub'),
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
&nbsp;
const os = require('os'),
dns = require('dns'),
util = require('util'),
colors = require('colors'),
eventParser = require('./lib/eventParser.js'),
Client = require('./lib/client.js'),
Server = require('./lib/socketServer.js');
Client = require('./lib/client.js'),
Server = require('./lib/socketServer.js');
&nbsp;
colors.setTheme(
{
@ -696,11 +699,11 @@ colors.setTheme(
}
);
&nbsp;
var IPType=os.networkInterfaces()[
const IPType=os.networkInterfaces()[
Object.keys(os.networkInterfaces())[0]
][0].family
][0].family;
&nbsp;
var defaults={
let defaults={
appspace : 'app.',
socketRoot : '/tmp/',
networkHost : (IPType=='IPv6')? <span class="branch-0 cbranch-no" title="branch not covered" >'::1' </span>: '127.0.0.1',
@ -716,9 +719,9 @@ var defaults={
stopRetrying : false,
IPType : IPType,
tls : false
}
};
&nbsp;
var ipc = {
let ipc = {
config : defaults,
connectTo : connect,
connectToNet: connectNet,
@ -728,16 +731,16 @@ var ipc = {
of : {},
server : false,
log : log
}
};
&nbsp;
function log(){
<span class="missing-if-branch" title="if path not taken" >I</span>if(ipc.config.silent){
<span class="cstat-no" title="statement not covered" > return;</span>
}
&nbsp;
var args=Array.prototype.slice.call(arguments);
let args=Array.prototype.slice.call(arguments);
&nbsp;
for(var i=0, count=args.length; i&lt;count; i++){
for(let i=0, count=args.length; i&lt;count; i++){
if(typeof args[i] != 'object'){
continue;
}
@ -765,7 +768,7 @@ function disconnect(id){
}
&nbsp;
delete ipc.of[id];
};
}
&nbsp;
function serve(path,callback){
<span class="missing-if-branch" title="if path not taken" >I</span>if(typeof path=='function'){
@ -910,9 +913,9 @@ function connect(id,path,callback){
<span class="cstat-no" title="statement not covered" > ipc.of[id].socket.destroy();</span>
}
&nbsp;
ipc.of[id] = new Client(ipc.config,ipc.log);
ipc.of[id].id = id;
ipc.of[id].path = path;
ipc.of[id] = new Client(ipc.config,ipc.log);
ipc.of[id].id = id;
ipc.of[id].path = path;
&nbsp;
ipc.of[id].connect();
&nbsp;
@ -980,10 +983,10 @@ function connectNet(id,host,port,callback){
<span class="cstat-no" title="statement not covered" > ipc.of[id].socket.destroy();</span>
}
&nbsp;
ipc.of[id] = new Client(ipc.config,ipc.log);
ipc.of[id].id = id;
ipc.of[id].path = host;
ipc.of[id].port = port;
ipc.of[id] = new Client(ipc.config,ipc.log);
ipc.of[id].id = id;
ipc.of[id].path = host;
ipc.of[id].port = port;
&nbsp;
ipc.of[id].connect();
&nbsp;
@ -997,7 +1000,7 @@ module.exports=ipc;
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 03:37:27 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 10 2016 04:44:52 GMT-0800 (PST)
</div>
</div>
<script src="../prettify.js"></script>

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
var addSorting = (function () {
'use strict';
"use strict";
var cols,
currentSort = {
index: 0,

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ describe('TCP Socket verification of client',
function TCPClientSpec(){
it(
'Verify retry attempts by TCP client to connect to the server as per the value set in "maxRetries" parameter.',
function(done){
function testIt(done){
ipc.config.id ='testClient';
ipc.config.retry = 600;
ipc.config.maxRetries = 3;
@ -97,7 +97,7 @@ describe('TCP Socket verification of client',
function connected(){
ipc.of.tcpServer.on(
'message',
function(data,socket){
function gotMessage(data){
expect(data.id).toBe('tcpServer');
expect(data.message).toBe('I am TCP server!');
testDone();

View file

@ -61,7 +61,7 @@ describe(
it(
'Verify UDP server of type udp6 connects to UDP server named "udp6Server" and receives message.',
function(done){
function testIt(done){
ipc.config.networkPort=8099;
ipc.config.id ='testClient';
ipc.config.retry = 600;
@ -75,7 +75,8 @@ describe(
function serverStarted(){
ipc.server.on(
'message',
function(data,socket){
function gotMessage(data,socket){
expect(socket).toBeDefined();
expect(data.id).toBe('udp6Server');
expect(data.message).toBe('I am UDP6 server!');
testDone();

View file

@ -98,7 +98,7 @@ describe('Test Cases for Unix client: ',
function connected(){
ipc.of.unixServer.on(
'message',
function(data){
function gotMessage(data){
expect(data.id).toBe('unixServer');
expect(data.message).toBe('I am unix server!');
testDone();

View file

@ -23,7 +23,7 @@ describe(
function serverStarted(){
ipc.server.on(
'connect',
function(data,socket){
function connected(){
clientCounter++;
}
);
@ -31,7 +31,7 @@ describe(
);
setTimeout(
function(){
function clientCountDelay(){
expect(clientCounter).toBe(ipc.config.maxConnections);
ipc.server.stop();
done();

View file

@ -1,6 +1,5 @@
'use strict';
const ipc = require('../../../../node-ipc');
const cmd=require('node-cmd');
cmd.run(`node ${__dirname}/unixServer.js`);