Created
February 2, 2011 12:35
-
-
Save victusfate/807622 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
| socket.sendData = function(message){ console.log(message.toString()); this.send(message, 0, message.length, 42424, "telehash.org"); } | |
| //socket.formatter = function(message){ new Buffer(JSON.stringify({".tap":[{"has":["+key"]}],"_line":ring, "_to":"208.68.163.247:42424"})); | |
| socket.on("message", function(data, rinfo){ | |
| console.log(data.toString()); | |
| telex = JSON.parse(data.toString()); | |
| //console.log("TELEX: " + JSON.stringify(telex)); | |
| if (telex["_ring"]){ | |
| ring = telex["_ring"]; | |
| console.log("LINE: " + ring); | |
| this.line = ring; | |
| var response = new Buffer(JSON.stringify({".tap":[{"has":["+key"]}],"_line":ring, "_to":"208.68.163.247:42424"})); | |
| this.sendData(response); | |
| } | |
| if (telex["+key"]){ | |
| console.log("INCOMING KEY!!!!!!!!"); | |
| var message = telex["+message"]; | |
| var key = telex["+key"]; | |
| //console.log(key); | |
| var signature = telex["+sig"]; | |
| //var verifier = crypto.createVerify('RSA-SHA1'); | |
| //verifier.update(message); | |
| var test = ezcrypto.verify(message, signature, key) | |
| //console.log(message); | |
| //var bool =verifier.verify(key, signature, signature_format='hex'); | |
| //console.log(bool); | |
| if (test){ | |
| console.log("Key validates"); | |
| var timestamp = new Date().toString(); | |
| db.insertTweets = function(){ | |
| db.execute("INSERT INTO tweets (key, message, timestamp) VALUES (?,?,?)", [key, message, timestamp], function(error, rows){ | |
| if (error){ | |
| db.execute("CREATE TABLE tweets (key, message, timestamp)",function(){}); | |
| db.insertTweets(); | |
| } | |
| }); | |
| }; | |
| db.insertTweets(); | |
| } else { | |
| console.log("Key doesn't validate"); | |
| } | |
| } | |
| }); | |
| socket.on("listening", function(){ | |
| console.log("Now listening"); | |
| setTimeout(function(){ socket.send(message, 0, message.length, 42424, "telehash.org"); socket.ping() }, 1000); | |
| }); | |
| socket.bind(12345); | |
| var pingmsg = new Buffer(JSON.stringify({"_line":socket.line, "_to":"208.68.163.247:42424"})); | |
| socket.ping = function(){ setTimeout(function(){ socket.sendData(pingmsg); socket.ping(); },30000) }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment