Havvy/simple-irc-socket — pull request #1 by rickihastings (2013-12-03 14:24:11+00:00)
Title: Added SSL support

Ok so the first 3 commits are bug fixes and there is an error in the README which says to use .start() not .connect().

The other commits implement SSL support, you might want to refine it, I've tried to make it as clean as I could but node's `tls` module gives me no help, the API is a little different from the `net` module.

Firstly I've had to move all the events out of the constructor into a seperate function called `setupEvents()` which is defined in the constructor, it's called during `connect()` when secure is enabled, if not it's called in the constructor. The reason for doing this is that if we chose to use a secure connection we have to throw `genericSocket` away and redefine it in the connect command because the `tls` module only provides us with `tls.connect()` which returns a `CleartextStream` object, not a socket. I tried upgrading the `genericSocket` using https://groups.google.com/forum/#!msg/nodejs/IB0Uw9eqoEM/LhMFjeUa0EUJ but it got me all sorts of SSL related errors, I think it would mean creating a certificate and using `tls.createSecurePair()`.

I've also moved the connect event to it's own closure where we determine if we're using secure mode or not because the events emitted are different `secureConnect` and `connect`.

The original `network` object is also accessible via `socket.network` now because we need to access `network.nick` etc in `setupEvents()`.

Have a look over and see what you think. I also made changes so the tests continued to work in the final commit, although was having problems with testing a secure connection. The reason being is we're creating a new `genericSocket` with `tls.connect()` in `connect()`. I've tried a few methods but can't get anything to work and get the tests to run with secure enabled.