Skip to content

Instantly share code, notes, and snippets.

@alexstrat
Created August 13, 2012 16:27
Show Gist options
  • Save alexstrat/3342354 to your computer and use it in GitHub Desktop.
Save alexstrat/3342354 to your computer and use it in GitHub Desktop.
Middleware proposal
var MY_ID = "..";
reactor.use({
queried: function (rpc) {
rpc.quering = new Peer(rpc.queryingAddress, rpc.params.id);
rpc.onComplete(function(peers) {
rpc.response = rpc.response || {};
rpc.response.nodes = peers.toRawArray();
rpc.response.id = MY_ID;
});
},
querying: function(rpc) {
rpc.queriedAddress = rpc.queried.getAddress();
rpc.params = rpc.params || {};
rpc.params.id = MY_ID;
rpc.on("response", function(response) {
if(response.id !== rpc.queried.getId()) {
rpc.reject(new Error("bad ID"));
reactor.log.warning("Spoofing attack");
return;
}
rpc.resolve(new PeerArray(response.nodes));
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment