Permalink
Browse files

add localAddress connection option to specify socket bind address whe…

…n connecting
  • Loading branch information...
1 parent d3d9ba7 commit 75c9099ad8752dfb552463f44e0df946140d2508 @revmischa committed Feb 3, 2013
Showing with 24 additions and 5 deletions.
  1. +4 −0 docs/API.rst
  2. +20 −5 lib/irc.js
View
4 docs/API.rst
@@ -19,6 +19,7 @@ Client
userName: 'nodebot',
realName: 'nodeJS IRC client',
port: 6667,
+ localAddress: null,
debug: false,
showErrors: false,
autoRejoin: true,
@@ -39,6 +40,9 @@ Client
If you set `selfSigned` to true SSL accepts certificates from a non trusted CA.
If you set `certExpired` to true, the bot connects even if the ssl cert has expired.
+ `localAddress` is the address to bind to when connecting. Not
+ supported with `secure` option.
+
`floodProtection` queues all your messages and slowly unpacks it to make sure
that we won't get kicked out because for Excess Flood. You can also use
`Client.activateFloodProtection()` to activate flood protection after
View
25 lib/irc.js
@@ -36,6 +36,7 @@ function Client(server, nick, opt) {
userName: 'nodebot',
realName: 'nodeJS IRC client',
port: 6667,
+ localAddress: null,
debug: false,
showErrors: false,
autoRejoin: true,
@@ -573,14 +574,28 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
}
var self = this;
self.chans = {};
+
+ // socket opts
+ var connectionOpts = {
+ 'host': self.opt.server,
+ 'port': self.opt.port,
+ };
+
+ // local address to bind to
+ if (self.opt.localAddress)
+ connectionOpts.localAddress = self.opt.localAddress;
+
// try to connect to the server
if (self.opt.secure) {
var creds = self.opt.secure;
- if (typeof self.opt.secure !== 'object') {
- creds = {};
+ if (typeof self.opt.secure == 'object') {
+ // copy "secure" opts to options passed to connect()
+ for (var f in self.opt.secure) {
+ connectionOpts[f] = creds[f];
+ }
}
- self.conn = tls.connect(self.opt.port, self.opt.server, creds, function() {
+ self.conn = tls.connect(connectionOpts, function() {
// callback called only after successful socket connection
self.conn.connected = true;
if (self.conn.authorized ||
@@ -608,8 +623,8 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
util.log(self.conn.authorizationError);
}
});
- }else {
- self.conn = net.createConnection(self.opt.port, self.opt.server);
+ } else {
+ self.conn = net.createConnection(connectionOpts);
}
self.conn.requestedDisconnect = false;
self.conn.setTimeout(0);

0 comments on commit 75c9099

Please sign in to comment.