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

Refactor getBestPublicIp for all valid ips #1132

Merged
merged 5 commits into from
Oct 2, 2024
Merged

Conversation

sgourdas
Copy link
Collaborator

@sgourdas sgourdas commented Sep 12, 2024

This refactors getBestPublicIp(bool) to getBestPublicIps(IpMode) so it can correctly return all attached ips for both protocols ipv4 and ipv6.

Fixes kiwix/kiwix-tools#703
Fixes kiwix/kiwix-tools#709

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 35.71429% with 36 lines in your changes missing coverage. Please review.

Project coverage is 41.42%. Comparing base (bef3ec7) to head (95529d2).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/server/internalServer.cpp 17.85% 12 Missing and 11 partials ⚠️
src/tools/networkTools.cpp 68.42% 1 Missing and 5 partials ⚠️
src/server.cpp 28.57% 3 Missing and 2 partials ⚠️
src/server/internalServer.h 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1132      +/-   ##
==========================================
- Coverage   41.43%   41.42%   -0.02%     
==========================================
  Files          59       59              
  Lines        4245     4268      +23     
  Branches     2323     2336      +13     
==========================================
+ Hits         1759     1768       +9     
- Misses        990      999       +9     
- Partials     1496     1501       +5     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kelson42
Copy link
Collaborator

@sgourdas thx for the PR but can you please fix the code so the CI can pass?

@sgourdas
Copy link
Collaborator Author

@kelson42 ready

Copy link
Collaborator

@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.

Almost good, but

$ kiwix-serve --port=8080 -i 127.0.0.1 /home/kelson/Downloads/wikipedia_en_ray_charles_maxi_2023-12.zim 
The Kiwix server is running and can be accessed in the local network at: http://192.168.0.168:8080 and http://::1:808

Should return only http://127.0.0.1:8080 as kiwix-serve should only listen on this IP

include/server.h Outdated Show resolved Hide resolved
@kelson42
Copy link
Collaborator

Still not working fine:

$ kiwix-serve --port=8081 -i ipv4 /home/kelson/Downloads/wikipedia_fr_climate_change_maxi_2022-05.zim 
The Kiwix server is running and can be accessed in the local network at: http://:8081

@sgourdas Please test all of this completly.

@sgourdas
Copy link
Collaborator Author

Still not working fine:

$ kiwix-serve --port=8081 -i ipv4 /home/kelson/Downloads/wikipedia_fr_climate_change_maxi_2022-05.zim 
The Kiwix server is running and can be accessed in the local network at: http://:8081

@sgourdas Please test all of this completly.

@kelson42 I tested this and it was working fine for me. Tested again and I get:

kiwix-serve --port 8081 -l /home/ubunter/.local/share/kiwix-desktop/library.xml -i ipv4
Loading the library from the following files:
        /home/ubunter/.local/share/kiwix-desktop/library.xml
The library was successfully loaded.
The Kiwix server is running and can be accessed in the local network at: http://172.27.70.65:8081

@sgourdas
Copy link
Collaborator Author

Have you built both new kiwix tools and libkiwix versions?

If yes, can you provide more details like if despite the printed message the server is available in browser?

src/server/internalServer.cpp Outdated Show resolved Hide resolved
include/server.h Outdated Show resolved Hide resolved
include/tools.h Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.h Outdated Show resolved Hide resolved
test/server_testing_tools.h Outdated Show resolved Hide resolved
include/tools.h Outdated Show resolved Hide resolved
@kelson42
Copy link
Collaborator

@sgourdas This will wait tomorrow, I kind of suspect something wrong in my testing because of the renaming of the .pc file done earlier today and not fully rolled-out.

@sgourdas sgourdas force-pushed the feature/best-public-ip branch from b2a7704 to eb3e76a Compare September 18, 2024 14:17
@kelson42 kelson42 force-pushed the feature/best-public-ip branch from 6803fa4 to 1a09276 Compare September 18, 2024 14:56
@kelson42
Copy link
Collaborator

@sgourdas Still wrong! You are "cheating" (taking for IPV4 the localhost instead of the public IP)!

$ kiwix-serve --port=8383 -i ipv4 /home/kelson/Downloads/wikipedia_fr_climate_change_maxi_2022-05.zim 
The Kiwix server is running and can be accessed in the local network at: http://127.0.0.1:8383

@sgourdas sgourdas removed the request for review from veloman-yunkan September 18, 2024 15:16
@sgourdas sgourdas marked this pull request as draft September 18, 2024 15:33
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

I think I started reviewing while the PR was being updated. My feeling is that my feedback doesn't pave the path to this PR being merged on next iteration, it seems like we will have to make at least a couple more back-and-forths.

include/server.h Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
include/server.h Outdated Show resolved Hide resolved
@sgourdas
Copy link
Collaborator Author

I think I started reviewing while the PR was being updated. My feeling is that my feedback doesn't pave the path to this PR being merged on next iteration, it seems like we will have to make at least a couple more back-and-forths.

Sorry for this. This PR is not up to standard and I have to revise all the changes. When it started, I expected it to be more straight forward and it has become very unstructured.

Will try to get back ASAP.

@sgourdas sgourdas force-pushed the feature/best-public-ip branch 4 times, most recently from d87643d to 97ad823 Compare September 19, 2024 08:47
@veloman-yunkan
Copy link
Collaborator

@sgourdas

Those are not blockers.

Looks like @kelson42 has scared you too much with his attempt to expedite the release of 2.4.0 libkiwix.
This is not your last chance of having this PR merged so an extra iteration or two for final polishing is fine.

@sgourdas sgourdas force-pushed the feature/best-public-ip branch 3 times, most recently from 2e89cd3 to 2fe632a Compare October 2, 2024 13:24
@sgourdas
Copy link
Collaborator Author

sgourdas commented Oct 2, 2024

@sgourdas

Those are not blockers.

Looks like @kelson42 has scared you too much with his attempt to expedite the release of 2.4.0 libkiwix. This is not your last chance of having this PR merged so an extra iteration or two for final polishing is fine.

Alright then, lets go for another round 😄

@sgourdas sgourdas force-pushed the feature/best-public-ip branch from 2fe632a to a15415e Compare October 2, 2024 13:32
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

LLIONSPBP

If you wonder what that abbreviation stands for and cannot guess it yourself, than turn for help to an Asian constricting snake and ask it to evaluate the expression 'gnihsilbup erofeb gnihsilop emos sdeen ylno ti ekil skooL'[::-1].

src/server.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
@sgourdas sgourdas force-pushed the feature/best-public-ip branch 2 times, most recently from d71a005 to 6fadb63 Compare October 2, 2024 16:12
@sgourdas
Copy link
Collaborator Author

sgourdas commented Oct 2, 2024

LLIONSPBP

If you wonder what that abbreviation stands for and cannot guess it yourself, than turn for help to an Asian constricting snake and ask it to evaluate the expression 'gnihsilbup erofeb gnihsilop emos sdeen ylno ti ekil skooL'[::-1].

TICIFA

If you want to continue, but do not know what I am saying, you can use this:

{
    0x21, 0x64, 0x65, 0x74, 0x63, 0x69, 0x64, 0x64,
    0x41, 0x20, 0x6C, 0x65, 0x65, 0x46, 0x20, 0x49,
    0x20, 0x2C, 0x6E, 0x61, 0x65, 0x6C, 0x43, 0x20,
    0x73, 0x49, 0x20, 0x73, 0x69, 0x68, 0x54
}

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

There is no limit on how clean code can be. Since you gave me an excuse I will ask for more cleanliness. 😉

src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/tools/networkTools.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Show resolved Hide resolved
@sgourdas sgourdas force-pushed the feature/best-public-ip branch from 6fadb63 to ec22d26 Compare October 2, 2024 17:50
@sgourdas
Copy link
Collaborator Author

sgourdas commented Oct 2, 2024

There is no limit on how clean code can be. Since you gave me an excuse I will ask for more cleanliness. 😉

I will now stop talking, after saying that it looks very nice!

@sgourdas sgourdas force-pushed the feature/best-public-ip branch from ec22d26 to 95529d2 Compare October 2, 2024 17:55
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

@sgourdas Thanks for bearing with the perfectionist side of me! The result of it is that this code can now be safely run in a surgery room.

@kelson42 Despite my above assessment of the quality of the code of this PR, I am reminding that cleanliness is orthogonal to functionality. A hammer can be super-clean and perfectly disinfected however it is not suitable for performing colonoscopy. Though I paid attention to the semantics of the code during the final review I didn't test it and hence don't have 100% confidence against the infamous treacherousness of C++. Please repeat your testing before merging.

@kelson42
Copy link
Collaborator

kelson42 commented Oct 2, 2024

@veloman-yunkan Thx but unable to test, the kiwix-tools PR does not compile!

@sgourdas
Copy link
Collaborator Author

sgourdas commented Oct 2, 2024

@veloman-yunkan Thx but unable to test, the kiwix-tools PR does not compile!

@kelson42 it should be good now.

@kelson42
Copy link
Collaborator

kelson42 commented Oct 2, 2024

LGTM

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