proxy binding to local interfaces
authorDarren <darren@darrenwhitlen.com>
Fri, 24 Jan 2014 11:50:23 +0000 (11:50 +0000)
committerDarren <darren@darrenwhitlen.com>
Fri, 24 Jan 2014 11:50:23 +0000 (11:50 +0000)
server/irc/connection.js
server/proxy.js

index 2458c541c83f17bdc050e6928da3ebc5753957ab..c0ca216c0ce0d69980b35402e9d698a912e43876 100644 (file)
@@ -220,6 +220,7 @@ IrcConnection.prototype.connect = function () {
         } else if (that.proxy) {
             that.socket = new Proxy.ProxySocket(that.proxy.port, host, {
                 username: that.username,
+                interface: that.proxy.interface
             }, {ssl: that.proxy.ssl});
 
             if (that.ssl) {
index fae5c584656a493a6c4a43b16ab3033211dd8663..1dfaa9b205ddc9fc01589b13a7da3118e9bb6adc 100644 (file)
@@ -171,15 +171,25 @@ ProxyPipe.prototype.kiwiSocketOnReadable = function() {
 
 ProxyPipe.prototype.makeIrcConnection = function() {
     debug('[KiwiProxy] Opening proxied connection to: ' + this.meta.host + ':' + this.meta.port.toString());
+
+    var local_address = this.meta.interface ?
+        this.meta.interface :
+        '0.0.0.0';
+
     if (this.meta.ssl) {
         this.irc_socket = tls.connect({
             port: parseInt(this.meta.port, 10),
             host: this.meta.host,
             rejectUnauthorized: global.config.reject_unauthorised_certificates,
+            localAddress: local_address
         }, this._onSocketConnect.bind(this));
 
     } else {
-        this.irc_socket = net.connect(parseInt(this.meta.port, 10), this.meta.host, this._onSocketConnect.bind(this));
+        this.irc_socket = net.connect({
+            port: parseInt(this.meta.port, 10),
+            host: this.meta.host,
+            localAddress: local_address
+        }, this._onSocketConnect.bind(this));
     }
 
     this.irc_socket.setTimeout(10000);
@@ -268,7 +278,8 @@ function ProxySocket(proxy_port, proxy_addr, meta, proxy_opts) {
     this.proxy_addr   = proxy_addr;
     this.proxy_port   = proxy_port;
     this.proxy_opts   = proxy_opts || {};
-    this.meta         = meta || {};
+
+    this.setMeta(meta || {});
 
     this.state = 'disconnected';
 }