a partially connected mesh network with messaging and discovery
A partially connected mesh network with messaging and discovery.
There are many solutions for service discovery for Node. Solidipes provides node discovery and low latency message routing to serve as a foundation for distributed service discovery.
Run any of the following:
$ mocha$ npm test$ make test
Note: remember to
$ npm install solidipes
Solidipes exports a Network constructor.
var Network = require'solidipes';var id = require'crypto'randomBytes16toString'hex';var net =// auto-generated if not includedid: id// listen on port 3000, defaults to a random open portport: 3000;
Create a new network instance.
var net =// defaults to an auto-generated 32-digit hex string, provide this if usefulid: 'a94312d853e585bc41c1ff990f120b1b'// the interval on which to garbage collect the seen messages structurecleanup: 10000 // default// the host to bind the server to, finds an external address if not providedhost: 'localhost'// the port to listen on, defaults to a random open portport: 3000// number of neighbor nodes to keep in contact withlocals: 8 // default;
Returns the formatted transport connection info.
Seed the network with transport info, which can be retrieved back calling
// get the transport infovar info = network.info;// broadcast the info to another process somehow// seed the network with the remote transport infonetseedinfo;
Gets the size of the network in number of nodes.
netsize; // => 0
Specifies the recipient and options of an event emit. If target is null, designates a global broadcast.
// broadcast to everybody! (realistically just do .emit)nettoemit;// unicast to the specified nodenetto'a94312d853e585bc41c1ff990f120b1b'emit;// multicast to two nodesnetto'a94312d853e585bc41c1ff990f120b1b' '783513fc00eb8b0962afb8a0a83fb1b6'emit;// direct-unicast to the specified node (must be a neighbor node)netto'a94312d853e585bc41c1ff990f120b1b' direct: trueemit// err would be "no routable nodes" if there is no direct connection;// the redundant option specifies how much the message should be replicated// higher numbers mean the message has a high likelyhood of reaching its destination// lower numbers mean fewer wasted packetsnetto'a94312d853e585bc41c1ff990f120b1b' redundant: 16emit;
Broadcast an event to all nodes in the network.
netemit'hello' these: 'are' 'useful' 'arguments'// handle errors;
Emitted when a node is added to the network, either manually or through node discovery.
neton'add'// please do not modify node!node:id: 'a94312d853e585bc41c1ff990f120b1b'transport: 'tcp://127.0.0.1:4035';
Emitted when a node is removed from the network.
neton'remove'// please do not modify node!node:id: 'a94312d853e585bc41c1ff990f120b1b'transport: 'tcp://127.0.0.1:4036';
Emitted as message records are cleaned up on the provided interval.
neton'garbage'// count is the number of messages garbage-collected;
General error event, usually emitted during parse. Make sure you also add an error listener on the transport.
neton'error'// emitted when an error occurred// make sure to listen for this so the event loop isn't destroyed;
Emitted when solidipes receives a valid but unknown packet.
neton'unknown'// emitted when a packet is correctly parsed but cannot be acted upon;
Emit an event to the represented Target (returned by
nettoemit'new-service'// arbitrary datatype: 'converter'info:host: 'localhost'port: 7777priority: 17// this callback just gives an indication as to whether the message was sent// not very good guarantees right now;
Okay. Many flaws fixed, still no roadmap.
The MIT License (MIT)
Copyright © 2014 GlobeSherpa
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.