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 'addressmanager', reorder fetching sources for-external ip #300

Conversation

biryukovmaxim
Copy link
Collaborator

reorder fetching sources for external ip according to:
external ip -> provided local address -> net interfaces -> upnp

The 'addressmanager' component of the codebase has been thoroughly refined for improved readability and maintainability. Firstly, the logic for assigning local network addresses has been streamlined and broken down into smaller methods for more clarity. Old methods 'add_routable_addresses_from_net_interfaces' and 'configured_address' have been replaced by 'routable_addresses_from_net_interfaces', 'local_addresses', and 'upnp'. This also led to the removal of redundant code.

The 'addressmanager' component of the codebase has been thoroughly refined for improved readability and maintainability. Firstly, the logic for assigning local network addresses has been streamlined and broken down into smaller methods for more clarity. Old methods 'add_routable_addresses_from_net_interfaces' and 'configured_address' have been replaced by 'routable_addresses_from_net_interfaces', 'local_addresses', and 'upnp'. This also led to the removal of redundant code.
components/addressmanager/src/lib.rs Outdated Show resolved Hide resolved
components/addressmanager/src/lib.rs Outdated Show resolved Hide resolved
components/addressmanager/src/lib.rs Outdated Show resolved Hide resolved
Introduced thiserror dependency and created UpnpError enum in the addressmanager module. The enum encapsulates possible errors from Universal plug and play (upnp) functionality in idg_next crate, providing a more granular approach to error handling. The upnp function was also refactored to return a Result type - improving code readability and easing error propagation.
Modified log messages in the addressmanager and port_mapping_extender modules to improve readability by including the '[UPnP]' context. The messages were updated in multiple sections where the upnp() function was used, thus helping in easier identification and debugging of UPnP related issues.
Enhanced the port mapping detection functionality in the address manager to handle cases where the default port is already in use by another service. This change allows the gateway to map to a random external port if the default one is already mapped. This is crucial for avoiding port mapping conflicts under UPnP protocol, and hence, improving the robustness of the network setup process.
Refactored the logic used to check whether the default external port is already mapped under UPnP in the address manager. The changes allow the application to handle scenarios where the port is in use by another service more effectively, ultimately enabling the gateway to map to another external port when required. This refinement is critical for averting potential port mapping conflicts, thereby enhancing the reliability of the network initialization process.
Added an additional step to handle the removal of a mapped port in the Universal Plug and Play (UPnP) protocol when stopping a service. Included a warning message if the port removal fails and an informational message upon successful removal. This enhancement improves service lifecycle management by ensuring that resources are appropriately released when a service is stopped, preventing potential port leaking issues.
Updated the address manager component to specifically handle `RequestError` and `SpecifiedArrayIndexInvalid` errors from the `GetGenericPortMappingEntry` method. This change results in improved error logging and handling, improving overall reliability of the UPnP functionality."
This commit simplifies the use of the itertools library in our address manager module to improve readability. Instead of using the full `itertools::Either::` syntax every time, we've destructured `Either::{Left, Right}` at the beginning, allowing for leaner and semantically clearer code.
checks for existing port mappings in the UPnP-enabled Internet Gateway Device (IGD).
The clarification helps developers understand the necessity of this loop, especially
in scenarios where the IGD might not explicitly signal port conflicts.
@someone235 someone235 merged commit 19ea1a6 into kaspanet:master Oct 25, 2023
6 checks passed
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.

None yet

3 participants