Last active
December 20, 2015 23:48
-
-
Save robinmonjo/6214729 to your computer and use it in GitHub Desktop.
This file contains 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
tls = require 'tls' | |
fs = require 'fs' | |
Connection = require('./connection').Connection | |
class Rendezvous | |
@unPairedConnections = [] | |
connectionFindOutSecret: (connection, cb) => | |
#check if a connection with the same secret exists in the unPairedConnections list | |
for co in @unPairedConnections | |
if co.secret == connection.secret | |
cb co #telling connection we have found his peer | |
#remove co and connection from the array they both have met | |
return | |
#Launch server | |
options = | |
key: fs.readFileSync 'private-key.pem' | |
cert: fs.readFileSync 'public-cert.pem' | |
server = tls.createServer options, (socket) -> | |
#new connection incoming, creating the object and adding it to the list of un paired connection | |
connection = new Connection socket, this | |
unPairedConnections.push connection | |
server.listen 1237, () -> | |
console.log "Listening on 1237" | |
module.exports.Rendezvous = Rendezvous |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment