Skip to content

-[HTTPServer start:] will no longer fail if it can't bind an IPv6 socket#114

Merged
WilliamDenniss merged 1 commit into
openid:masterfrom
flexibits:no-ipv6
May 19, 2017
Merged

-[HTTPServer start:] will no longer fail if it can't bind an IPv6 socket#114
WilliamDenniss merged 1 commit into
openid:masterfrom
flexibits:no-ipv6

Conversation

@ksuther
Copy link
Copy Markdown
Contributor

@ksuther ksuther commented May 2, 2017

We had a user with IPv6 completely disabled (on Mac), which was causing -[HTTPServer start:] to fail.
Since only the IPv4 loopback address is used, I've made start: succeed even if it can't bind an IPv6 socket.

I also added the option of using the IPv6 loopback address (::1) in the future if iPv6 should be preferred over IPv4.

@codecov-io
Copy link
Copy Markdown

codecov-io commented May 2, 2017

Codecov Report

Merging #114 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #114   +/-   ##
=======================================
  Coverage   77.89%   77.89%           
=======================================
  Files          39       39           
  Lines        2474     2474           
  Branches      124      124           
=======================================
  Hits         1927     1927           
  Misses        484      484           
  Partials       63       63

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9232b82...952a2f4. Read the comment docs.

Copy link
Copy Markdown
Collaborator

@StevenEWright StevenEWright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider IPv6-only as well as IPv4-only?

return YES;
}

- (BOOL)hasIPv4Socket
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency:

- (BOOL)hasIPv4Socket {

return ipv4socket != nil;
}

- (BOOL)hasIPv6Socket
Copy link
Copy Markdown
Collaborator

@StevenEWright StevenEWright May 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency:

- (BOOL)hasIPv6Socket {

- (BOOL)start:(NSError **)error;
- (BOOL)stop;

- (BOOL)hasIPv4Socket;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since start: always returns NO if it can't create an IPv4 socket, why is this necessary?

- (BOOL)start:(NSError **)error;
- (BOOL)stop;

- (BOOL)hasIPv4Socket;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not something like:

@property(nonatomic, readonly) NSURL *preferredLoopbackURL;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that there's much gain to splitting out part of startHTTPListener: into a separate property. The method is only a few lines as is.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was more to do with making life easy for consumers of this class - since the only reason consumers care about these values is in the context of determining which loopback address to use.

}
return nil;
} else {
} else if ([_httpServ hasIPv4Socket]) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of these clauses would cause the library to always use IPv4, since, with your changes, the library always must have an IPv4 socket, but only may have an IPv6 socket, this first test will always pass, leaving no chance for the second test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional, as I didn't want to change the behavior of the library dramatically without any discussion. Handling a potential IPv6-only case is easy enough to do, I'll add it even though it's unlikely to be hit any time soon.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be very(!) much appreciated.

I do know Apple is concerned with IPv6-only networks (see here), so I think the feature may be more valuable than you're giving it credit for. IMHO, the lack of this support is a bug with the existing code.

@StevenEWright StevenEWright self-assigned this May 6, 2017
@ksuther
Copy link
Copy Markdown
Contributor Author

ksuther commented May 6, 2017

start: will now succeed if IPv6 is available but IPv4 isn't. The callback URL still prefers IPv4 over IPv6 if both are available, but that could be changed by swapping the order of the check in OIDRedirectHTTPHandler.

@StevenEWright
Copy link
Copy Markdown
Collaborator

This PR LGTM.

@ksuther Thank you! Were you able to test it, or should I patch it in and try it?

@ksuther
Copy link
Copy Markdown
Contributor Author

ksuther commented May 7, 2017

I tested it by making the IPv4 socket fail, but I didn't actually turn off IPv4 systemwide.

Copy link
Copy Markdown
Member

@WilliamDenniss WilliamDenniss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ksuther
Copy link
Copy Markdown
Contributor Author

ksuther commented May 16, 2017

Does this require anything else from me?

@StevenEWright
Copy link
Copy Markdown
Collaborator

@ksuther no. Thank you very much for this! We're just waiting for william to squash merge the PR, which he said he'd do.

@WilliamDenniss
Copy link
Copy Markdown
Member

WilliamDenniss commented May 19, 2017

@ksuther, do you want to squash the commits into one? I can do this for you but then I'm added as the "committer", so thought I'd give you first option.

…ket (it will only fail if can't bind an IPv4 and IPv6 socket)

This prevents failures if someone is running on a system where IPv6 has been completely disabled.
Added IPv6 loopback support to -[OIDRedirectHTTPHandler startHTTPListener:], but it currently isn't used since -[HTTPServer start:] will fail if it can't bind an iPv4 socket. It has been tested and can be used in the future if necessary.
Future-proofing OIDLoopbackHTTPServer if IPv4 isn't available
@ksuther
Copy link
Copy Markdown
Contributor Author

ksuther commented May 19, 2017

I squashed them, I hope that's what you were expecting.

@WilliamDenniss WilliamDenniss merged commit 6018a6d into openid:master May 19, 2017
@WilliamDenniss
Copy link
Copy Markdown
Member

Perfect, thanks.

@ksuther ksuther deleted the no-ipv6 branch May 19, 2017 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants