-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for multiple peer addresses in remote bootnode argument #98
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 support for multiple peer addresses in remote bootnode argument #98
Conversation
…figuration Add support for connecting to multiple peers via the --remote-bootnode argument to improve network resilience and connectivity options. Key changes: - Add parse_multiple_multiaddrs() function to handle various multiaddress formats - Support concatenated format: /ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678 - Support comma-separated format: /ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678 - Support space-separated format: /ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678 - Maintain backward compatibility with single peer addresses - Handle connection failures gracefully with warning-level logging - Add comprehensive test suite covering all supported formats The network handler now attempts to connect to all specified peers sequentially, logging each attempt and continuing even if some peers are unreachable. Example usage: --remote-bootnode "/ip4/10.38.1.103/tcp/55444/ip4/10.38.1.105/tcp/55444" Fixes: AN-268
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.
Pull Request Overview
This PR adds support for parsing and dialing multiple bootnode addresses in the network handler, allowing for more flexible peer discovery and connection redundancy.
- Introduces a new
parse_multiple_multiaddrsfunction that can handle comma-separated, space-separated, and concatenated multiaddress formats - Updates the network handler to dial multiple bootnodes with improved error handling
- Adds comprehensive unit tests for the new parsing functionality
app/src/network/mod.rs
Outdated
| } | ||
|
|
||
| if addresses.is_empty() { | ||
| return Err(Error::MultiaddrError(libp2p::multiaddr::Error::InvalidMultiaddr)); |
Copilot
AI
Aug 1, 2025
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.
The error message for empty addresses is not descriptive. Consider using a more specific error message like 'No valid multiaddresses found in input' to help with debugging.
| return Err(Error::MultiaddrError(libp2p::multiaddr::Error::InvalidMultiaddr)); | |
| return Err(Error::NoValidMultiaddrsFound("No valid multiaddresses found in input".to_string())); |
| /// Parse multiple multiaddresses from a string. | ||
| /// Supports the following formats: | ||
| /// - Comma-separated: "/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678" | ||
| /// - Space-separated: "/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678" | ||
| /// - Concatenated: "/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678" |
Copilot
AI
Aug 1, 2025
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.
The function lacks proper documentation. Consider adding a docstring that explains the parsing logic, error conditions, and provides examples of the supported formats.
| /// Parse multiple multiaddresses from a string. | |
| /// Supports the following formats: | |
| /// - Comma-separated: "/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678" | |
| /// - Space-separated: "/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678" | |
| /// - Concatenated: "/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678" | |
| /// Parses multiple multiaddresses from a string input. | |
| /// | |
| /// # Supported formats | |
| /// - **Comma-separated:** `"/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678"` | |
| /// - **Space-separated:** `"/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678"` | |
| /// - **Concatenated:** `"/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678"` | |
| /// | |
| /// The function attempts to parse the input string as a list of multiaddresses using the following logic: | |
| /// 1. If the input contains commas, it is split by commas and each part is parsed as a separate multiaddress. | |
| /// 2. If the input contains spaces, it is split by whitespace and each part is parsed as a separate multiaddress. | |
| /// 3. Otherwise, the input is parsed as a single multiaddress, or as concatenated multiaddresses if supported. | |
| /// | |
| /// # Error conditions | |
| /// - If any substring fails to parse as a valid `Multiaddr`, the function returns an error. | |
| /// - The error is propagated from `Multiaddr::from_str`. | |
| /// | |
| /// # Examples | |
| /// ``` | |
| /// // Comma-separated | |
| /// let input = "/ip4/1.2.3.4/tcp/1234,/ip4/5.6.7.8/tcp/5678"; | |
| /// let addrs = parse_multiple_multiaddrs(input)?; | |
| /// | |
| /// // Space-separated | |
| /// let input = "/ip4/1.2.3.4/tcp/1234 /ip4/5.6.7.8/tcp/5678"; | |
| /// let addrs = parse_multiple_multiaddrs(input)?; | |
| /// | |
| /// // Concatenated | |
| /// let input = "/ip4/1.2.3.4/tcp/1234/ip4/5.6.7.8/tcp/5678"; | |
| /// let addrs = parse_multiple_multiaddrs(input)?; | |
| /// ``` |
| for (i, address) in addresses.iter().enumerate() { | ||
| trace!("Dialing bootnode {}: {}", i + 1, address); | ||
| if let Err(e) = client.dial(address.clone()).await { | ||
| warn!("Failed to dial bootnode {} ({}): {}", i + 1, address, e); |
Copilot
AI
Aug 1, 2025
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.
Consider tracking and returning information about failed dial attempts to the caller, as silently continuing after failures might mask important connectivity issues.
…larity and maintainability of the multiaddress parsing logic.
This pull request introduces a new utility function for parsing multiple multiaddresses from a string and updates the network handler to support dialing multiple bootnodes. The changes improve flexibility in handling multiaddress formats and enhance error handling for dialing operations.
Parsing multiple multiaddresses:
parse_multiple_multiaddrsfunction inapp/src/network/mod.rsto parse multiaddresses from strings in various formats: comma-separated, space-separated, or concatenated. It includes logic to identify and split concatenated multiaddresses at protocol boundaries.parse_multiple_multiaddrsfunction to ensure correctness across different input formats, including valid, invalid, and empty inputs.Enhancements to network handler:
spawn_network_handlerfunction inapp/src/network/mod.rsto use the newparse_multiple_multiaddrsfunction for parsing theremote_bootnodeparameter. This allows dialing multiple bootnodes instead of a single one.spawn_network_handlerby logging warnings for individual bootnode dialing failures, ensuring the process continues for other addresses.