Created
June 12, 2012 12:28
-
-
Save alexstrat/2917220 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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