Permalink
Browse files

parsing tracker response

  • Loading branch information...
1 parent 7bf4560 commit 84825ae56f7c37789bd8c07a98afb9777499a56d @usoban committed Sep 4, 2011
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/peer.js
View
@@ -0,0 +1,18 @@
+module.exports = Peer;
+
+function Peer(nbo, port){
+ this.host = this._ntohl(nbo);
+
+ console.log(this.host);
+}
+
+/**
+ * 4-byte nbo to host
+ * @param {Buffer} nbo
+ */
+Peer.prototype._ntohl = function(nbo){
+ return (
+ ((0xff & nbo[0]) << 24) | ((0xff & nbo[1]) << 16) |
+ ((0xff & nbo[2]) << 8) | (0xff & nbo[3])
+ );
+};

0 comments on commit 84825ae

Please sign in to comment.