Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add option to specify bind address when connecting #146

Merged
merged 6 commits into from

5 participants

@revmischa

For machines with multiple IPs or people who want to use IPv6

@revmischa

Eagerly awaiting acceptance of this into upstream.

@martynsmith
Owner

It seems to me this would work with ssl? It looks like you're copying the secure stuff in to connectOpts and using that?

@revmischa

I believe that fixes it so the other options get passed through to tls, which may have fixed a bug. This was a long time ago so I don't really remember.

@revmischa

Sup, need anything else done?

@apeiron
Collaborator

Can you update this so it merges cleanly, and then we can revisit it?

@Trinitas

#241 possible with Webirc

lib/irc.js
((15 lines not shown))
// 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) {
@jirwin Collaborator
jirwin added a note

You'll want to add a hasOwnProperty guard here:

for (var f in creds) {
  if (creds.hasOwnProperty(f)) {
    connectionOpts[f] = creds[f]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jirwin
Collaborator

Looks pretty good to me! add that guard and a rebase and we'll get this merged.

@revmischa

Okay, standby

docs/API.rst
@@ -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
@jirwin Collaborator
jirwin added a note

It looks like you got this working with the secure option. Probably should update this doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jirwin
Collaborator

Actually, this is based against the wrong branch now. I think you may need to re-open this PR against the 0.3.x branch

@revmischa

Commit 5c02ec4 makes rebasing highly problematic

@jirwin
Collaborator

Yeah, this is why I think it will probably be easier to just open a new PR against the 0.3.x branch and add the changes there. Rebasing against that will be a huge pain.

@jirwin
Collaborator

I like this PR a lot.

@apeiron
Collaborator

+1. I have a box with a bunch of IPs so I can test this pretty easily. Will look at doing that today and will merge assuming all goes well.

@apeiron apeiron merged commit dc7d262 into martynsmith:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 10 deletions.
  1. +7 −4 README.md
  2. +3 −0  docs/API.rst
  3. +23 −5 lib/irc.js
  4. +2 −1  package.json
View
11 README.md
@@ -19,7 +19,7 @@ If you want to run the latest version (i.e. later than the version available via
```
Of course, you can just clone this, and manually point at the library itself,
-but I really recommend using [npm](http://github.com/isaacs/npm)!
+but we really recommend using [npm](http://github.com/isaacs/npm)!
## Basic Usage
@@ -105,10 +105,13 @@ client.addListener('error', function(message) {
```
-## Further Documentation
+## Further Support
-Further documentation (including a complete API reference) are available in
+Further documentation (including a complete API reference) is available in
reStructuredText format in the docs/ folder of this project, or online at [Read the Docs](http://readthedocs.org/docs/node-irc/en/latest/).
If you find any issues with the documentation (or the module) please send a pull
-request or file an issue and I'll do my best to accommodate.
+request or file an issue and we'll do our best to accommodate.
+
+You can also visit us on ##node-irc on freenode to discuss issues you're having
+with the library, pull requests, or anything else related to node-irc.
View
3  docs/API.rst
@@ -19,6 +19,7 @@ Client
userName: 'nodebot',
realName: 'nodeJS IRC client',
port: 6667,
+ localAddress: null,
debug: false,
showErrors: false,
autoRejoin: true,
@@ -40,6 +41,8 @@ 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.
+
`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
28 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,
@@ -631,14 +632,31 @@ 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 = {rejectUnauthorized: !self.opt.selfSigned};
+ creds.rejectUnauthorized = !self.opt.selfSigned;
+
+ if (typeof self.opt.secure == 'object') {
+ // copy "secure" opts to options passed to connect()
+ for (var f in self.opt.secure) {
+ if (creds.hasOwnProperty(f))
+ 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 ||
@@ -668,8 +686,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);
View
3  package.json
@@ -9,7 +9,8 @@
},
"contributors": [
"Fionn Kelleher <me@fionn.co>",
- "xAndy <xandy@hackerspace-bamberg.de>"
+ "xAndy <xandy@hackerspace-bamberg.de>",
+ "Mischa Spiegelmock <revmischa@cpan.org>"
],
"repository": {
"type": "git",
Something went wrong with that request. Please try again.