Created
August 13, 2012 16:27
-
-
Save alexstrat/3342354 to your computer and use it in GitHub Desktop.
Middleware proposal
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
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