-
Notifications
You must be signed in to change notification settings - Fork 96
Add default session listen host option #6661
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
Add default session listen host option #6661
Conversation
This PR makes it possible to specify the default IP listening host (`ip:port`) for Session sockets (for IP forwarding) in the `session_ip_forwarding` section (via `default_entry_listen_host`) The `listen_host` argument for the `POST session/udp and tcp` REST API now allows partial specification of the listening host. All the following value for `listen_host` are valid: 1) `0.0.0.0:0` 2) `1.2.3.4:1234` 3) `:0` 4) `0.0.0.0` 5) `1.2.3.4` 6) `:1234` In cases 3-4 the corresponding missing part is replaced by the value from `default_entry_listen_host` (when specified). The default value for `default_entry_listen_host` if unspecified is `127.0.0.1:0`. The configuration code was refactored for clarity.
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the 📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces significant modifications to the configuration and management of session handling within the HOPR protocol. Key changes include the renaming and restructuring of configuration sections, the introduction of new parameters for session IP forwarding, and updates to several Rust source files to accommodate these changes. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crate version bumps missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (14)
hoprd/hoprd/src/exit.rs (1)
Line range hint
1-186
: Architecture Review: Robust Session ManagementThe refactoring maintains strong architectural principles:
- Clear separation of concerns between configuration and reactor logic
- Robust error handling for both UDP and TCP sessions
- Proper resource management with metrics
- Secure validation of target addresses
However, consider adding structured logging for configuration changes to aid in debugging and monitoring.
Consider adding debug logs when initializing the reactor with new configuration:
pub fn new(keypair: HoprOffchainKeypair, cfg: SessionIpForwardingConfig) -> Self { + tracing::debug!(?cfg, "Initializing HoprServerIpForwardingReactor"); Self { keypair, cfg } }
hoprd/hoprd/example_cfg.yaml (2)
324-328
: Consider adding parameter validation rangesThe TCP retry configuration parameters need bounds validation to prevent potential issues:
max_tcp_target_retries
: Should have a reasonable upper limit to prevent infinite retry loopstcp_target_retry_delay
: Should have minimum and maximum values to prevent too aggressive retries or excessive delaysConsider adding validation comments in the example configuration:
# max_tcp_target_retries: 10 # Valid range: 1-20 # tcp_target_retry_delay: 2 # Valid range: 1-30 seconds
329-333
: Enhance documentation with examples of partial specificationsThe
default_entry_listen_host
configuration would benefit from examples of valid partial specifications mentioned in the PR objectives.Consider adding examples in the comments:
# default_entry_listen_host: 127.0.0.1:0 # # Examples of valid partial specifications that will use the default: # - ":0" -> uses default IP # - "0.0.0.0" -> uses default port # - ":1234" -> uses default IP # # Examples of complete specifications: # - "0.0.0.0:0" # - "1.2.3.4:1234"hoprd/rest-api/src/lib.rs (2)
202-202
: Consider consistent naming across structs.The field name
default_session_listen_host
differs fromdefault_listen_host
inInternalState
. Consider using consistent naming to avoid confusion.Apply this change for consistency:
- pub default_session_listen_host: std::net::SocketAddr, + pub default_listen_host: std::net::SocketAddr,
245-245
: Consider refactoring to reduce function parameters.The function now has 9 parameters, which makes it harder to maintain and use correctly. Consider introducing a builder pattern or a dedicated parameters struct to improve maintainability.
Example refactor:
struct ApiBuilder { hoprd_cfg: String, cfg: crate::config::Api, hopr: Arc<hopr_lib::Hopr>, inbox: Arc<RwLock<hoprd_inbox::Inbox>>, hoprd_db: Arc<hoprd_db_api::db::HoprdDb>, open_listeners: ListenerJoinHandles, websocket_rx: async_broadcast::InactiveReceiver<ApplicationData>, msg_encoder: Option<MessageEncoder>, default_listen_host: std::net::SocketAddr, } impl ApiBuilder { fn new(hoprd_cfg: String, cfg: crate::config::Api) -> Self { // Initialize with required parameters } fn with_hopr(mut self, hopr: Arc<hopr_lib::Hopr>) -> Self { self.hopr = hopr; self } // Add other builder methods... async fn build(self) -> Router { // Current build_api implementation } }Also applies to: 257-257
hoprd/hoprd/src/config.rs (3)
26-27
: Clarify the purpose ofvalidate_file_path
functionThe
validate_file_path
function currently returnsOk(())
without performing any validation, and the actual validation code is commented out. If the intention is to bypass validation temporarily, consider adding a comment to explain this, or remove the function if it's no longer needed.Apply this diff to clarify the function's purpose:
// Validate that the path is a valid UTF-8 path. // -// Also used to perform the identity file existence check on the -// specified path, which is now circumvented but could -// return in the future workflows of setting up a node. +// Note: The identity file existence check is currently bypassed. +// This function may be reactivated in future node setup workflows. fn validate_file_path(_s: &str) -> Result<(), ValidationError> { Ok(()) // if std::path::Path::new(_s).is_file() { // Ok(()) // } else { // Err(ValidationError::new( // "Invalid file path specified, the file does not exist or is not a file", // )) // } }
364-366
: Avoid usingunwrap()
to prevent potential panicsUsing
.unwrap()
can cause a panic if parsing fails. Although unlikely with a hardcoded string, it's safer to handle the error explicitly.Consider using
.expect()
with a clear error message:fn default_entry_listen_host() -> SocketAddr { - "127.0.0.1:0".parse().unwrap() + "127.0.0.1:0".parse().expect("Failed to parse default entry listen host") }
368-370
: Avoid usingunwrap()
indefault_max_tcp_target_retries
While this function currently doesn't use
unwrap()
, ensure consistency by handling potential errors gracefully in all default functions.No immediate changes are necessary, but keep error handling consistent across the codebase.
hoprd/rest-api/src/messages.rs (4)
Line range hint
74-79
: Inconsistent Error Handling: MixingOk
andErr
for Error ResponsesIn the
send_message
function, error responses are sometimes returned usingOk((StatusCode, ApiError).into_response())
and other times withErr((StatusCode, ApiError).into_response())
. For consistency and to align with Rust conventions, consider standardizing the error handling by uniformly returningErr
when an error occurs.Apply this diff to standardize error handling:
let destination = if let Some(destination) = args.destination { destination } else if let Some(peer_id) = args.peer_id { PeerOrAddress::PeerId(peer_id) } else { - return Ok((StatusCode::BAD_REQUEST, ApiErrorStatus::InvalidInput).into_response()); + return Err((StatusCode::BAD_REQUEST, ApiErrorStatus::InvalidInput).into_response()); };
Line range hint
299-302
: Potential Data Loss: Discarding Messages with Invalid UTF-8 EncodingIn
to_api_message
, messages that fail UTF-8 decoding are discarded with an error. This may lead to data loss if messages contain binary data or are intentionally not UTF-8 encoded. Consider handling non-UTF-8 messages appropriately or returning the raw bytes.Apply this diff to handle non-UTF-8 messages:
fn to_api_message(data: hopr_lib::ApplicationData, received_at: Duration) -> Result<MessagePopResponse, String> { if let Some(tag) = data.application_tag { - match std::str::from_utf8(&data.plain_text) { - Ok(data_str) => Ok(MessagePopResponse { - tag, - body: data_str.into(), + let body = if let Ok(data_str) = std::str::from_utf8(&data.plain_text) { + data_str.into() + } else { + base64::encode(&data.plain_text) + }; + Ok(MessagePopResponse { + tag, + body, received_at, }) } else { Err("No application tag was present despite picking from a tagged inbox".into()) } }This change encodes non-UTF-8 messages using Base64, preserving the message content.
Line range hint
237-240
: Error Handling: Lack of Feedback for WebSocket Message Parsing ErrorsIn
handle_send_message
, errors fromserde_json::from_str
are converted to a generic error message. Providing more detailed error information could help clients debug issues.Apply this diff to improve error messages:
async fn handle_send_message(input: &str, state: Arc<InternalState>) -> Result<(), String> { match serde_json::from_str::<WebSocketSendMsg>(input) { Ok(msg) => { // Existing code } Err(e) => Err(format!("Failed to parse WebSocket message: {}", e)), } }This provides the specific parsing error back to the client.
Line range hint
277-282
: Resource Cleanup: Ensure WebSocket Connections are Properly ClosedIn
websocket_connection
, when an error occurs while receiving a message, the connection is broken out of the loop but not explicitly closed. Consider ensuring the WebSocket connection is properly closed upon errors to free resources.Apply this diff to close the connection:
Err(e) => { error!(error = %e, "Failed to get a valid websocket message, closing connection"); + if let Err(e) = sender.close().await { + error!(error = %e, "Failed to close websocket connection"); + } break; }hoprd/rest-api/src/session.rs (2)
302-317
: Update documentation to reflectdestination
can be an addressThe
destination
field is of typePeerOrAddress
, which can be either aPeerId
or anAddress
. However, the documentation currently states "Peer ID of the Exit node," which may be misleading.Consider updating the documentation to:
-/// Peer ID of the Exit node. +/// Peer ID or address of the Exit node.
949-970
: Good addition of unit tests forbuild_binding_host
The
test_build_binding_address
function effectively covers various input scenarios forbuild_binding_host
, ensuring it behaves as expected with different inputs.Consider adding tests for invalid inputs
While current tests cover valid and partially valid inputs, consider adding test cases for completely invalid inputs (e.g., non-IP strings), to ensure the function handles them gracefully.
Example:
let result = build_binding_host(Some("invalid_ip"), default); assert_eq!(result, default); let result = build_binding_host(Some("invalid_ip:port"), default); assert_eq!(result, default);
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
📒 Files selected for processing (8)
hoprd/hoprd/example_cfg.yaml
(1 hunks)hoprd/hoprd/src/config.rs
(5 hunks)hoprd/hoprd/src/exit.rs
(2 hunks)hoprd/hoprd/src/main.rs
(1 hunks)hoprd/rest-api/Cargo.toml
(1 hunks)hoprd/rest-api/src/lib.rs
(6 hunks)hoprd/rest-api/src/messages.rs
(1 hunks)hoprd/rest-api/src/session.rs
(4 hunks)
✅ Files skipped from review due to trivial changes (1)
- hoprd/rest-api/Cargo.toml
🔇 Additional comments (16)
hoprd/hoprd/src/exit.rs (3)
7-8
: LGTM: Clean import update
The import change cleanly reflects the configuration refactoring from IpForwardingReactorConfig
to SessionIpForwardingConfig
.
24-24
: LGTM: Configuration type updates
The struct field and constructor updates correctly implement the configuration refactoring while maintaining the same behavioral contract.
Also applies to: 28-30
Line range hint 33-39
: Verify target address validation remains secure
The all_ips_allowed
implementation maintains proper security checks for target addresses. However, let's verify that the new SessionIpForwardingConfig
structure properly initializes the target_allow_list
.
✅ Verification successful
Target address validation is properly secured
The verification shows that SessionIpForwardingConfig
is properly implemented with secure defaults:
- The struct is derived using
SmartDefault
and has proper serde attributes - The
target_allow_list
field is documented to default toNone
, which maintains the secure behavior of allowing configuration of restricted targets when needed - The field is properly used in
HoprServerIpForwardingReactor
for validation checks - The configuration is properly integrated into the main
HoprdConfig
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the initialization and usage of target_allow_list in the new config
# Check the config structure definition
rg -A 10 "struct SessionIpForwardingConfig"
# Check for target_allow_list initialization
rg "target_allow_list.*=.*"
Length of output: 807
Script:
#!/bin/bash
# Let's check for the initialization and usage patterns more thoroughly
# Check for any test cases or initialization patterns
rg -B 2 -A 4 "SessionIpForwardingConfig"
# Look for any code that constructs or modifies this config
ast-grep --pattern 'SessionIpForwardingConfig { $$ }'
# Check for any Default implementation
rg -B 2 -A 4 "impl.*Default.*SessionIpForwardingConfig"
# Check for any config file examples or documentation
fd -e toml -e yaml | xargs rg "target_allow_list"
Length of output: 2161
hoprd/hoprd/example_cfg.yaml (2)
313-315
: LGTM! Clear and descriptive section naming
The renaming from "Session Exit configuration" to "Session Entry/Exit IP forwarding configuration" better reflects the dual nature of the configuration. The section key change from exit
to session_ip_forwarding
is consistent with the new functionality.
316-323
: Verify security implications of target allow list
The configuration provides good security guidance by recommending the use of target_allow_list
in production. However, the default behavior of allowing all targets if the list is not set could pose security risks.
Consider adding a warning message in logs when running in production mode without a target_allow_list
configured.
Consider implementing additional security measures:
- Default to a restrictive allowlist (e.g., localhost only) in production mode
- Add support for CIDR notation for more flexible IP range configurations
- Consider adding a separate denylist for explicitly blocked targets
hoprd/rest-api/src/lib.rs (3)
84-84
: LGTM: Well-structured addition of default listen host.
The new field uses appropriate type and naming convention, aligning with the PR's objective to support default listening host configuration.
217-217
: LGTM: Clean parameter handling in serve_api.
The new parameter is correctly extracted and passed through to build_api, maintaining the existing code structure.
Also applies to: 229-229
84-84
: Verify integration with session handling code.
Let's ensure that the session module correctly utilizes the new default listening host configuration.
Also applies to: 202-202, 245-245
✅ Verification successful
Integration with session handling is properly implemented
The session module correctly utilizes the new default_listen_host
configuration:
- The
build_binding_host
function properly handles the default listening host, combining it with user-provided values - Comprehensive test cases verify the correct behavior with various host/port combinations
- The session creation endpoints correctly use the configured default host through
build_binding_host
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if the session module uses the default_listen_host
# Look for usage of default_listen_host in session-related code
rg -l "default_listen_host" --type rust
# Check for socket address parsing in session module
ast-grep --pattern 'SocketAddr::from_str($_)'
# Look for session creation logic
ast-grep --pattern 'fn create_client($$$)'
Length of output: 282
Script:
#!/bin/bash
# Let's examine the session.rs file to understand how default_listen_host is used
rg "default_listen_host" hoprd/rest-api/src/session.rs -B 2 -A 2
# Check for any socket address related code in session.rs
rg "SocketAddr" hoprd/rest-api/src/session.rs -B 2 -A 2
# Look for client creation or connection code in session.rs
rg "create|connect" hoprd/rest-api/src/session.rs -B 2 -A 2
Length of output: 9123
hoprd/hoprd/src/main.rs (1)
310-310
: Verify configuration validation for default_session_listen_host
The PR objectives mention several valid formats for the listen host. Ensure that proper validation is implemented for these formats to prevent runtime issues.
Let's check the validation implementation:
✅ Verification successful
Configuration validation is properly implemented for default_entry_listen_host
Based on the code analysis, the default_entry_listen_host
is properly validated through Rust's type system:
- It's defined with type
SocketAddr
which ensures valid socket address format - The default value is set through
default_entry_listen_host()
function which parses "127.0.0.1:0" - The
SessionIpForwardingConfig
struct usesserde_as(as = "serde_with::DisplayFromStr")
for parsing the value - The struct implements
Validate
trait for validation
The implementation ensures that:
- Only valid socket addresses are accepted
- Invalid formats will fail during deserialization
- A safe default of "127.0.0.1:0" is provided
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for validation of default_entry_listen_host in the codebase
rg -A 5 "default_entry_listen_host.*validate|validate.*default_entry_listen_host"
# Search for the configuration struct definition
ast-grep --pattern 'struct $name {
$$$
default_entry_listen_host: $_,
$$$
}'
Length of output: 307
Script:
#!/bin/bash
# Let's try a different approach to find the configuration structure and validation
# First, find files containing default_entry_listen_host
rg -l "default_entry_listen_host"
# Then search for struct definitions containing session_ip_forwarding
ast-grep --pattern 'struct SessionIpForwarding {
$$$
}'
# Also search for any validation or parsing logic
rg -A 5 "impl.*SessionIpForwarding|impl.*Config"
Length of output: 311
Script:
#!/bin/bash
# Let's examine the config.rs file which likely contains the validation logic
cat hoprd/hoprd/src/config.rs
# Also check the example config to understand the expected format
cat hoprd/hoprd/example_cfg.yaml
Length of output: 35840
hoprd/hoprd/src/config.rs (3)
372-409
: SessionIpForwardingConfig
is well-defined with appropriate defaults
The new SessionIpForwardingConfig
struct is properly defined with sensible defaults, validation rules, and serialization attributes using serde_with
. This enhances the configuration flexibility for session IP forwarding.
400-401
: Validate minimum value for max_tcp_target_retries
The #[validate(range(min = 1))]
attribute ensures that max_tcp_target_retries
cannot be less than 1. This is appropriate to prevent infinite retry loops or immediate failure without retries.
384-385
: Confirm correct serialization for target_allow_list
The use of serde_with::DisplayFromStr
for the target_allow_list
ensures proper serialization and deserialization of SocketAddr
within a HashSet
. Ensure that all SocketAddr
values conform to the expected format.
Run the following script to verify that all SocketAddr
entries are correctly formatted:
✅ Verification successful
Let me gather more context about the usage and serialization of target_allow_list
to ensure it's properly handled.
Let me check for any serialization tests specifically for this configuration.
Let me check for any test cases specifically related to the serialization of target_allow_list
.
Based on the gathered information, I can now provide a final response:
target_allow_list
serialization is correctly implemented
The implementation uses serde_with::DisplayFromStr
which is the appropriate serialization adapter for SocketAddr
within a HashSet
. The example configuration and usage show proper handling:
- Example config demonstrates correct format:
target_allow_list: ["127.0.0.1:8080"]
- The field is properly marked as optional with
Option<HashSet<_>>
- Usage in
exit.rs
shows correct deserialization and contains-check functionality
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the format of `SocketAddr` entries in the configuration files.
# Test: Search for `target_allow_list` entries and validate their format.
# Expect: All entries should be valid `SocketAddr` strings.
rg 'target_allow_list' -A 5 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]+'
Length of output: 90
Script:
#!/bin/bash
# Check for test cases and actual usage of target_allow_list
rg "target_allow_list" -B 2 -A 2
# Look for any serialization/deserialization tests
ast-grep --pattern 'fn $test_name() {
$$$
target_allow_list
$$$
}'
# Check if there are any config file examples
fd -e toml -e yaml -e json | xargs rg "target_allow_list"
Length of output: 1445
Script:
#!/bin/bash
# Look for test modules and serialization tests
rg "mod test" -A 10 hoprd/hoprd/src/config.rs
# Check for actual config examples with target_allow_list
rg -U "target_allow_list.*\[.*\]" hoprd/hoprd/example_cfg.yaml
# Look for any serialization/deserialization implementation
ast-grep --pattern 'impl $_ for Config {
$$$
}'
Length of output: 46830
Script:
#!/bin/bash
# Look for test cases in config.rs
rg "mod tests" -A 50 hoprd/hoprd/src/config.rs
# Check for any actual usage of target_allow_list in tests
ast-grep --pattern 'fn $test_name() {
$$$
assert
$$$
target_allow_list
$$$
}'
Length of output: 3047
hoprd/rest-api/src/messages.rs (3)
Line range hint 322-324
: Good Addition: Handle Missing Application Tag
Adding an error return when application_tag
is None
enhances robustness by properly handling unexpected cases where a message lacks an application tag in a tagged inbox.
172-173
:
Syntax Error: Misplaced Parenthesis
The closing parenthesis in the return Err
statement is misplaced, leading to a syntax error. The parenthesis should encapsulate the entire error tuple before calling .into_response()
.
Apply this diff to fix the syntax error:
#[cfg(not(feature = "explicit-path"))]
if args.path.is_some() {
return Err((
StatusCode::UNPROCESSABLE_ENTITY,
ApiErrorStatus::InvalidPath("explicit paths are not allowed".into()),
- )
- .into_response());
+ ))
+ .into_response());
}
Likely invalid or redundant comment.
Line range hint 279-282
: Concurrency Concern: Potential for Unhandled Exceptions
Exceptions within the asynchronous context of websocket_connection
may not be handled explicitly, potentially leading to unexpected behavior. Ensure that all asynchronous operations are properly awaited and errors are handled.
Run the following script to check for .await
usages without error handling:
hoprd/rest-api/src/session.rs (1)
443-443
: Verify default_listen_host
is properly initialized
Ensure that state.default_listen_host
is correctly set before it's used in build_binding_host
. An uninitialized or incorrect default could lead to unexpected binding addresses.
Run the following script to check the initialization:
✅ Verification successful
default_listen_host
is properly initialized with safe defaults
The verification shows that default_listen_host
is properly initialized:
- It's passed through the router construction in
lib.rs
from the configuration - The actual value comes from
cfg.session_ip_forwarding.default_entry_listen_host
inhoprd/src/main.rs
- This setting has a safe default implementation in
hoprd/src/config.rs
through thedefault_entry_listen_host()
function which returns"127.0.0.1:0"
(localhost with a random port) - The
build_binding_host
function properly handles all cases with appropriate logging:- Using the requested host if valid
- Falling back to default with debug logging
- Handling partial specifications by combining with defaults
The initialization chain is complete and has appropriate fallback mechanisms.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that `default_listen_host` is set correctly in the codebase.
# Search for the initialization of `default_listen_host`
rg "default_listen_host\s*=\s*.*" -A 3 -g "*.rs"
Length of output: 50
Script:
#!/bin/bash
# Let's try a broader search for default_listen_host
rg "default_listen_host" -g "*.rs"
# Also search for the struct definition that might contain this field
ast-grep --pattern 'struct $_ {
$$$
default_listen_host: $_,
$$$
}'
# Let's also check the build_binding_host function implementation
ast-grep --pattern 'fn build_binding_host($_: $_, $_: $_) -> $_ {
$$$
}'
Length of output: 602
Script:
#!/bin/bash
# Let's examine the lib.rs file more closely to understand the initialization
rg -B 5 -A 5 "default_listen_host" hoprd/rest-api/src/lib.rs
# Also check the build_binding_host function implementation
rg -B 2 -A 5 "fn build_binding_host" hoprd/rest-api/src/session.rs
Length of output: 1687
Script:
#!/bin/bash
# Let's find where the default_listen_host is actually initialized with a value
rg -B 10 -A 2 "InternalState\s*{" hoprd/rest-api/src/lib.rs
# Also check if there are any tests that might show the initialization
rg "default_listen_host" -g "*test*.rs"
Length of output: 199
Script:
#!/bin/bash
# Let's try a different approach to find the initialization
rg "let.*InternalState" -B 5 -A 10 hoprd/rest-api/src/lib.rs
# Also look for any configuration or setup related to the listen host
rg "listen.*host" -g "*.rs" -B 2 -A 2
Length of output: 16784
…nd a corresponding env variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
hoprd/hoprd/src/cli.rs (1)
120-126
: Enhance help text to document valid formats and default valueThe implementation looks good, but the help text could be more descriptive to better guide users. Consider updating it to document the supported formats and default value.
#[arg( long, env = "HOPRD_DEFAULT_SESSION_LISTEN_HOST", - help = "Default Session listening host for Session IP forwarding", + help = "Default Session listening host for Session IP forwarding. Valid formats: '<ip>:<port>' (e.g. '0.0.0.0:0'), '<ip>' (e.g. '1.2.3.4'), or ':<port>' (e.g. ':1234'). Defaults to '127.0.0.1:0' if not specified.", value_parser = ValueParser::new(parse_host), )] pub default_session_listen_host: Option<HostConfig>,hoprd/hoprd/src/config.rs (2)
369-379
: Document rationale for default valuesThe default values for retry delay, max retries, and entry listen host should be documented with explanations of why these specific values were chosen. This helps maintainers understand the reasoning behind these choices and evaluate if they need adjustment in the future.
154-161
: Improve error messages for better user experienceThe error messages could be more descriptive to help users understand what went wrong and how to fix it. Consider:
- For invalid IP: Include the actual value that was invalid
- For domain name: Explain that only IP addresses are supported and provide an example
- .map_err(|_| HoprdError::ConfigError("invalid default session listen IP address".into())), - HostType::Domain(_) => Err(HoprdError::ConfigError("default session listen must be an IP".into())), + .map_err(|_| HoprdError::ConfigError(format!("Invalid IP address '{}'. Expected format: '1.2.3.4'", addr))), + HostType::Domain(domain) => Err(HoprdError::ConfigError( + format!("Domain '{}' is not supported. Please use an IP address (e.g., '127.0.0.1')", domain) + )),
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
hoprd/hoprd/src/cli.rs
(1 hunks)hoprd/hoprd/src/config.rs
(5 hunks)transport/api/src/config.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- transport/api/src/config.rs
🔇 Additional comments (3)
hoprd/hoprd/src/cli.rs (1)
Line range hint 15-23
: Verify host parsing logic for all valid formats
The parse_host
function may not handle all the valid formats mentioned in the PR objectives, particularly the :port
format (e.g., :0
, :1234
). The current implementation would reject these as invalid hosts.
Let's verify the implementation of HostConfig::from_str
to ensure it handles all valid formats:
If the verification confirms that these formats are not supported, consider updating the host parsing logic to handle them correctly:
- When the host part is empty (
:port
format), use a default host - When the port part is missing, use a default port
hoprd/hoprd/src/config.rs (2)
381-418
: 🛠️ Refactor suggestion
Add environment variable support for configuration
As noted in a previous review, environment variable support is needed for Kubernetes deployments where dynamic values like IPs are configured via environment. Consider adding environment variable mappings for these configuration fields, especially for default_entry_listen_host
.
Line range hint 533-535
: Address TODO and ignored test
The test test_config_is_extractable_from_the_cli_arguments
is currently ignored and has a TODO comment about incorrect deserialization in the native build. This should be addressed to ensure proper test coverage of the configuration functionality.
This PR makes it possible to specify the default IP listening host (
ip:port
) for Session sockets (for IP forwarding) in thesession_ip_forwarding
section (viadefault_entry_listen_host
)The
listen_host
argument for thePOST session/udp and tcp
REST API now allows partial specification of the listening host. All the following values forlisten_host
are valid:0.0.0.0:0
1.2.3.4:1234
:0
0.0.0.0
1.2.3.4
:1234
In cases 3-4 the corresponding missing part is replaced by the value from
default_entry_listen_host
(when specified).The default value for
default_entry_listen_host
if unspecified is127.0.0.1:0
.The configuration code was refactored for clarity.