-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor 'addressmanager', reorder fetching sources for-external ip (#…
…300) * Refactor 'addressmanager' to improve readability and maintainability 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. * clippy fixes * Refactor upnp error handling and add UpnpError enum 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. * Update log messages to include UPnP context 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. * Add UPnP context to existing port mapping detection 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. * Refactor existing port mapping check logic in UPnP 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. * Add cleanup logic for UPnP port removal 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. * found -> Found * "Handle specific port mapping errors in address manager 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." * Remove unused import in address manager component * desciption -> Description * Refactor itertools usage in addressmanager 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. * This commit introduces a documentary comment explaining the loop that 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.
- Loading branch information
1 parent
34df5e6
commit 19ea1a6
Showing
4 changed files
with
176 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters