Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kiwix-serve displays both protocol attached ips #704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sgourdas
Copy link
Collaborator

@sgourdas sgourdas commented Sep 12, 2024

This changes the logic to use the refactored getBestPublicIps so kiwix-serve can display all attached ips based on the protocol that was requested by the user.

Fixes #703

Relies on kiwix/libkiwix#1132

Copy link
Contributor

@kelson42 kelson42 left a comment

Choose a reason for hiding this comment

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

LGTM from a user perspective. Ready for code review.

@veloman-yunkan
Copy link
Collaborator

Ready for code review.

Not yet. Comments from my previous review have not been addressed.

Comment on lines 327 to 329
kiwix::IpMode ipMode = (address == "all") ? kiwix::IpMode::all :
(address == "ipv6") ? kiwix::IpMode::ipv6 :
kiwix::IpMode::ipv4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

"all", "ipv6", & "ipv4" are special values for the --address option which can take a concrete IP address. If an IPv6 address (e.g. 2606:2800:21f:cb07:6820:80da:af6b:8b2c) is passed then this new logic will set ipMode to kiwix::IpMode::ipv4 which is wrong for downstream code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Essentially the logic remains the same as before. How it is setup is that the InternalServer::start is going to set the m_ipMode as ipv6 (previously all) if a valid v6 ip has been provided by the user.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe. But codewise it appears flawed. I think that the interaction of Server::setIpMode() and Server::setAddress() should be defined in such a way that the former takes precedence. In other words, if an IPv4 mode is requested then only IPv4 addresses should be accepted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So essentially we should:

  • Remove all server mode handling and move it to kiwix-serve (removing also kiwix-serve.cpp:381).
  • Set default mode (no mode through -i provided) to all (also, server.h:84 should be changed).

Correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Remove all server mode handling and move it to kiwix-serve

I don't know what is covered by this so cannot answer

  • Set default mode (no mode through -i provided) to all

It will work, but IMHO it's better to add an extra enum member IpMode::auto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would IpMode::auto have any use case other than IpMode::all's?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or just an easier way for kiwix-serve to understand that no ip mode has been supplied?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would IpMode::auto have any use case other than IpMode::all's?

It was included in my original proposal for enhancing the kiwix-serve CLI with support for IPv6, but did not make way into implementation. Whatever the reason for that (you can find it in the ensuing discussion) it has a comeback at least in the C++ code.

Or just an easier way for kiwix-serve to understand that no ip mode has been supplied?

Mostly yes, but with some potential to find other uses later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, I see how it can be useful in future scenarios. I will add it and make it the default mode for when an address is provided or no -i at all.

P.S. auto is not allowed as a name. Will use flex.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be honest it is a bit complicated with the current implementation to really put it in use, but I will wait for your next review after committing to discuss further.

src/server/kiwix-serve.cpp Outdated Show resolved Hide resolved
@veloman-yunkan
Copy link
Collaborator

Ready for code review.

Not yet. Comments from my previous review have not been addressed.

Oops! It turns out that I failed to publish my review - it was in pending state since last Wednesday :(

Comment on lines +334 to +335
if (address.find(':') != std::string::npos) ipMode = kiwix::IpMode::ipv6;
else ipMode = kiwix::IpMode::ipv4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you handle IpMode::flex in libkiwix?

Comment on lines +392 to +393
bool validMode4 = (ipMode == kiwix::IpMode::ipv4 || ipMode == kiwix::IpMode::all); // Mode is valid to support ipv4
bool validMode6 = (ipMode == kiwix::IpMode::ipv6 || ipMode == kiwix::IpMode::all); // Mode is valid to support ipv6
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why you need these. I think that Server::getAddress() must return only the addresses actually in use by the server. If it doesn't work that way - fix it in libkiwix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REGRESSION] kiwix-serve URL helper does not display iPv4 URL anymore
3 participants