Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

deal with the possibility of not being connected to overlay

  • Loading branch information...
commit 8e05542c21323a2203087d74e754f3b4f9a6e95c 1 parent 1174e8e
@nikhilm authored
Showing with 25 additions and 0 deletions.
  1. +9 −0 lib/knode.js
  2. +16 −0 test/knode-test.js
View
9 lib/knode.js
@@ -258,6 +258,11 @@ exports.KNode.prototype._iterativeFind = function(key, mode, cb) {
var value = null;
var contactsWhichHadValue = [];
closestNode = shortlist[0];
+ if (!closestNode) {
+ // we aren't connected to the overlay network!
+ externalCallback({ message: 'Not connected to overlay network. No peers.'}, mode, null);
+ return;
+ }
closestNodeDistance = util.distance(key, closestNode.nodeID);
function xyz(alphaContacts) {
@@ -422,6 +427,10 @@ exports.KNode.prototype.set = function(key, value, cb) {
'value': value
});
this._iterativeFindNode(util.id(key), _.bind(function(err, type, contacts) {
+ if (err) {
+ callback(err);
+ return;
+ }
async.forEach(contacts, _.bind(function(contact, asyncCb) {
this._rpc.send(contact, message, function() {
// TODO handle error
View
16 test/knode-test.js
@@ -14,6 +14,22 @@ vows.describe('KNode').addBatch({
topic: new knode.KNode({ address: '127.0.0.1', port: 65535 }),
'KNode._self should be frozen': function(topic) {
assert.throws(function() { topic._self.prop = "invalid"; }, TypeError);
+ },
+ },
+
+ 'Storing a value on a disconnected node': {
+ topic: function() {
+ var node = new knode.KNode({ address: '127.0.0.1', port: 65535 });
+ var self = this;
+ node.set('foo', 'bar', function(err) {
+ console.error(err);
+ if (err)
+ self.callback(null);
+ else
+ self.callback({message: "this shouldn't happen!"});
+ });
+ },
+ 'should fail': function(err) {
}
},
Please sign in to comment.
Something went wrong with that request. Please try again.