that.socket = new Proxy.ProxySocket(that.proxy.port, host, {
username: that.username,
});
- that.socket.connect(that.irc_host.port, that.irc_host.hostname);
+
+ if (that.ssl) {
+ that.socket.connectTls(that.irc_host.port, that.irc_host.hostname);
+ } else {
+ that.socket.connect(that.irc_host.port, that.irc_host.hostname);
+ }
} else {
// No socks connection, connect directly to the IRCd
console.log('Kiwi proxy listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without'));
});
- serv.on('connection_open', function(pipe) {
+ serv.on('socket_connected', function(pipe) {
pipe.identd_pair = pipe.irc_socket.localPort.toString() + '_' + pipe.irc_socket.remotePort.toString();
console.log('[IDENTD] opened ' + pipe.identd_pair);
global.clients.port_pairs[pipe.identd_pair] = pipe.meta;
this.irc_socket.setTimeout(10000);
this.irc_socket.on('error', this._onSocketError.bind(this));
this.irc_socket.on('timeout', this._onSocketTimeout.bind(this));
+
+ // We need the raw socket connect event, not after any SSL handshakes or anything
+ if (this.irc_socket.socket) {
+ this.irc_socket.socket.on('connect', this._onRawSocketConnect.bind(this));
+ } else {
+ this.irc_socket.on('connect', this._onRawSocketConnect.bind(this));
+ }
+};
+
+
+ProxyPipe.prototype._onRawSocketConnect = function() {
+ this.proxy_server.emit('socket_connected', this);
};
};
+ProxySocket.prototype.connectTls = function() {
+ this.meta.ssl = true;
+ return this.connect.apply(this, arguments);
+};
+
+
ProxySocket.prototype.connect = function(dest_port, dest_addr, connected_fn) {
this.meta.host = dest_addr;
this.meta.port = dest_port;
this.socket = this.proxy_opts.ssl ?
tls.connect(this.proxy_port, this.proxy_addr, this._onSocketConnect.bind(this)) :
net.connect(this.proxy_port, this.proxy_addr, this._onSocketConnect.bind(this));
- this.socket.setTimeout(10000);
+ this.socket.setTimeout(10000);
this.socket.on('data', this._onSocketData.bind(this));
this.socket.on('close', this._onSocketClose.bind(this));
this.socket.on('error', this._onSocketError.bind(this));