Comparing version 0.1.0 to 0.2.0
module.exports = require('./src/net-msg.js'); | ||
module.exports = require('./src/synapsis.js'); |
{ | ||
"name": "synapsis", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "./node_modules/.bin/mocha test/*.mocha.js --exit" | ||
}, | ||
@@ -15,4 +15,11 @@ "dependencies": { | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
"devDependencies": { | ||
"mocha": "*" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/Unitech/synapsis.git" | ||
}, | ||
"author": "Alexandre Strzelewicz @Unitech", | ||
"license": "MIT" | ||
} |
@@ -9,2 +9,4 @@ | ||
Instanciate new peer: | ||
```javascript | ||
@@ -22,4 +24,7 @@ var Synapsis = require('synapsis'); | ||
}); | ||
``` | ||
// Router | ||
Now expose actions that can be triggered by other peers: | ||
```javascript | ||
synapse.router('command:restart', () => { | ||
@@ -36,3 +41,22 @@ console.log('Got Restart'); | ||
}); | ||
``` | ||
To send actions to other peers: | ||
```javascript | ||
// Broadcast a message to all nodes (w/o current) and do not wait for response | ||
synapse.broadcast('command:restart'); | ||
// Broadcast a message + data to all nodes (w/o current) and do not wait for response | ||
synapse.broadcast('command:restart', { some : 'data' }); | ||
// Broadcast a message to all nodes (w/o current) and receive messages from each (RPC like) | ||
synapse.broadcast('command:sync_db', { my : { db : true } }, function(err, response) { | ||
console.log(err, response); | ||
}); | ||
``` | ||
Extra: | ||
```javascript | ||
// Events | ||
@@ -43,4 +67,4 @@ synapse.on('peer:connected', function(socket) { | ||
synapse.on('peer:disconnected', function(err) { | ||
console.error(err); | ||
synapse.on('peer:disconnected', function(identity) { | ||
console.error(identity); | ||
}); | ||
@@ -53,12 +77,3 @@ | ||
synapse.on('ready', function() { | ||
// Broadcast a message to all nodes (w/o current) and do not wait for response | ||
synapse.broadcast('command:restart'); | ||
// Broadcast a message + data to all nodes (w/o current) and do not wait for response | ||
synapse.broadcast('command:restart', { some : 'data' }); | ||
// Broadcast a message to all nodes (w/o current) and receive messages from each (RPC like) | ||
synapse.broadcast('command:sync_db', { my : { db : true } }, function(err, response) { | ||
console.log(err, response); | ||
}); | ||
// Ready | ||
}); | ||
@@ -65,0 +80,0 @@ ``` |
@@ -17,3 +17,3 @@ 'use strict'; | ||
* 1/ Exchange diffie hellman keys | ||
* 2/ TODO: Send password | ||
* 2/ Send password | ||
* 3/ Send Identity | ||
@@ -34,3 +34,3 @@ * | ||
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity) | ||
debug('peer %s errored', this._socket_pool[peer.id].identity.public_ip); | ||
debug('peer %s errored', this._socket_pool[peer.id].identity.name); | ||
socket.destroy(); | ||
@@ -42,9 +42,8 @@ //this.emit('error', err); | ||
socket.on('close', () => { | ||
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity) | ||
debug('peer %s left', this._socket_pool[peer.id].identity.public_ip); | ||
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity) { | ||
debug('peer %s left', this._socket_pool[peer.id].identity.name); | ||
this.emit('disconnected', this._socket_pool[peer.id].identity); | ||
} | ||
socket.destroy(); | ||
if (this._socket_pool[peer.id] && this._socket_pool[peer.id].identity) | ||
this.emit('disconnected', JSON.parse(JSON.stringify(this._socket_pool[peer.id].identity))); | ||
delete this._socket_pool[peer.id]; | ||
@@ -187,11 +186,6 @@ }); | ||
SocketPool.prototype.sendToId = function(id) { | ||
var ret = []; | ||
var that = this; | ||
Object.keys(this._socket_pool).forEach(function(key) { | ||
ret.push(that._socket_pool[key]); | ||
}); | ||
return ret; | ||
SocketPool.prototype.sendToId = function(id, route, data, cb) { | ||
if (data) | ||
return this._socket_pool[id].send(route, data, cb); | ||
return this._socket_pool[id].send(route, cb); | ||
}; | ||
@@ -198,0 +192,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
19934
11
634
2
2
80
0
1