Skip to content

Instantly share code, notes, and snippets.

@alexstrat
Created June 12, 2012 12:28
Show Gist options
  • Save alexstrat/2917220 to your computer and use it in GitHub Desktop.
Save alexstrat/2917220 to your computer and use it in GitHub Desktop.
queried: function(rcp) {
switch(rpc.getMethod()) {
case 'PING':
rpc.resolve();
break;
case 'FIND_NODE':
rpc.resolve(
this.routingTable.getClosePeers(
rpc.getTarget(),
BETA,
rpc.getQuerying()),
false);
break;
case 'APPEND':
var key = SHA1(rpc.getRessource());
this.store
.retrieve(key)
.pipe(function(value) {
if(!Array.isArray(value))
return new Error('not an array');
value.push(rpc.getData());
return value;
}, function() {
//go for resolve..
return [rpc.getData()];
})
.pipe(function(value) {
return this.store.save(key, value, -1)
}, this)
.then(rpc.resolve, rcp.reject, rpc);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment