diff --git a/.gitignore b/.gitignore index 45d62d8..54ba1b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.sw? +node_modules diff --git a/README.md b/README.md index 2fdf315..f79dfcd 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Check out the the scripts in the simulations/ directory for some examples. Gossiper methods: - allPeeers() + allPeers() livePeers() deadPeers() peerValue(peer, key) diff --git a/index.js b/index.js new file mode 100644 index 0000000..f0027b6 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// This file is just added for convenience so this repository can be +// directly checked out (submodule) into a project +module.exports = require('./lib/gossiper'); diff --git a/lib/gossiper.js b/lib/gossiper.js index 68e458c..d4318a1 100644 --- a/lib/gossiper.js +++ b/lib/gossiper.js @@ -1,24 +1,25 @@ -var PeerState = require('peer_state').PeerState, - Scuttle = require('scuttle').Scuttle, - EventEmitter = require('events').EventEmitter, - net = require('net'), - sys = require('sys'), +var PeerState = require('./peer_state').PeerState, + Scuttle = require('./scuttle').Scuttle, + EventEmitter = require('events').EventEmitter, + net = require('net'), + util = require('util'), child_process = require('child_process'), - dns = require('dns'), - msgpack = require('msgpack'); + dns = require('dns'), + msgpack = require('msgpack'); var Gossiper = exports.Gossiper = function(port, seeds, ip_to_bind) { EventEmitter.call(this); this.peers = {}; this.ip_to_bind = ip_to_bind; this.port = port; + this.seeds = seeds; this.my_state = new PeerState(); this.scuttle = new Scuttle(this.peers, this.my_state); this.handleNewPeers(seeds); } -sys.inherits(Gossiper, EventEmitter); +util.inherits(Gossiper, EventEmitter); Gossiper.prototype.start = function(callback) { var self = this; @@ -63,12 +64,12 @@ Gossiper.prototype.stop = function() { } -// The method of choosing whice peer(s) to gossip to is borrowed from Cassandra. +// The method of choosing which peer(s) to gossip to is borrowed from Cassandra. // They seemed to have worked out all of the edge cases // http://wiki.apache.org/cassandra/ArchitectureGossip Gossiper.prototype.gossip = function() { // Find a live peer to gossip to - if(this.livePeers() > 0) { + if(this.livePeers().length > 0) { var live_peer = this.chooseRandom(this.livePeers()); this.gossipToPeer(live_peer); } @@ -112,7 +113,7 @@ Gossiper.prototype.gossipToPeer = function(peer) { mp_stream.send(self.requestMessage()); }); gosipee.on('error', function(exception) { -// console.log(self.peer_name + " received " + sys.inspect(exception)); +// console.log(self.peer_name + " received " + util.inspect(exception)); }); } @@ -219,12 +220,12 @@ Gossiper.prototype.allPeers = function() { Gossiper.prototype.livePeers = function() { var keys = []; - for(var k in this.peers) { if(k.alive) { keys.push(k)} }; + for(var k in this.peers) { if(this.peers[k].alive) { keys.push(k)} }; return keys; } Gossiper.prototype.deadPeers = function() { var keys = []; - for(var k in this.peers) { if(!k.alive) { keys.push(k) } }; + for(var k in this.peers) { if(!this.peers[k].alive) { keys.push(k) } }; return keys; } diff --git a/lib/peer_state.js b/lib/peer_state.js index 19aa16f..b5e6705 100644 --- a/lib/peer_state.js +++ b/lib/peer_state.js @@ -1,6 +1,6 @@ -var AccrualFailureDetector = require('./accrual_failure_detector').AccrualFailureDetector, - EventEmitter = require('events').EventEmitter, - sys = require('sys'); +var AccrualFailureDetector = require('./accrual_failure_detector').AccrualFailureDetector, + EventEmitter = require('events').EventEmitter, + util = require('util'); var PeerState = exports.PeerState = function(name) { EventEmitter.call(this); @@ -13,7 +13,7 @@ var PeerState = exports.PeerState = function(name) { this.name = name; }; -sys.inherits(PeerState, EventEmitter); +util.inherits(PeerState, EventEmitter); PeerState.prototype.updateWithDelta = function(k,v,n) { // It's possibly to get the same updates more than once if we're gossiping with multiple peers at once diff --git a/package.json b/package.json new file mode 100644 index 0000000..1dd8192 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "gossiper", + "description": "node-gossip implements a gossip protocol", + "version": "0.0.3", + "author": "Bob Potter ", + "contributors": [ + { + "name": "Christopher Mooney", + "email": "chris@dod.net" + } + ], + "repository": { + "type" : "git", + "url" : "git://github.com/bpot/node-gossip.git" + }, + "keywords": ["gossip"], + "dependencies": { + "msgpack" : ">= 0.0.0" + }, + "main": "index.js", + "scripts": { "test": "expresso -I lib test/*" }, + "engines": { "node": "0.4.x || 0.5.x || 0.6.x || 0.7.x || 0.8.x || 0.9.x" } +} diff --git a/simulation/s3.js b/simulation/s3.js index 9a7e2a8..56888b3 100644 --- a/simulation/s3.js +++ b/simulation/s3.js @@ -1,5 +1,4 @@ var Gossiper = require('gossiper').Gossiper; -var sys = require('sys'); var seed1 = new Gossiper(9000, []); seed1.start();