Repository navigation
Add IPv6 support to URN system endpoint parsing - #115
Conversation
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
|
@copilot weiter |
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive IPv6 support to ThemisDB's URN system endpoint parsing, enabling deployment in modern IPv6-only and dual-stack networks. The implementation is RFC 3986 compliant and maintains full backward compatibility with existing IPv4 and hostname-based endpoints.
Key Changes:
- Enhanced
MTLSClient::parseEndpoint()to detect and correctly parse IPv6 addresses with bracket notation - Added multi-colon detection for bare IPv6 addresses without ports
- Made
parseEndpoint()public API with comprehensive documentation
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/sharding/mtls_client.cpp |
Core IPv6 parsing logic with bracket detection and multi-colon handling |
include/sharding/mtls_client.h |
Public API exposure with documented examples for IPv6, IPv4, and hostname formats |
tests/test_mtls_client.cpp |
20+ comprehensive test cases covering IPv6 with/without brackets, edge cases, and backward compatibility |
docs/sharding/ipv6_support.md |
Complete deployment guide with configuration examples, best practices, and troubleshooting |
docs/sharding/README.md |
Updated version to 1.2.0 and added IPv6 support highlights with quick reference |
docs/sharding/IPv6_IMPLEMENTATION_SUMMARY.md |
Implementation summary documenting the problem, solution, and testing results |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else { | ||
| // Single colon - IPv4/hostname with port | ||
| host = url.substr(0, colon_pos); | ||
| port = url.substr(colon_pos + 1); |
There was a problem hiding this comment.
The function doesn't validate the extracted port string. Malformed input like "192.168.1.1:abc" or "example.com:99999" would be accepted without validation. Consider adding validation to ensure the port is a valid integer in the range 1-65535.
| // =========================================================================== | ||
| // IPv6 Endpoint Parsing Tests | ||
| // =========================================================================== | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv4_WithPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("192.168.1.1:8080"); | ||
| EXPECT_EQ(host, "192.168.1.1"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv4_WithoutPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("192.168.1.1"); | ||
| EXPECT_EQ(host, "192.168.1.1"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv4_WithProtocol) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("https://192.168.1.1:9090"); | ||
| EXPECT_EQ(host, "192.168.1.1"); | ||
| EXPECT_EQ(port, "9090"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_WithBracketsAndPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[2001:db8::1]:8080"); | ||
| EXPECT_EQ(host, "2001:db8::1"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_WithBracketsWithoutPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[2001:db8::1]"); | ||
| EXPECT_EQ(host, "2001:db8::1"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_WithoutBracketsWithoutPort) { | ||
| // IPv6 without brackets and without port (multiple colons) | ||
| auto [host, port] = MTLSClient::parseEndpoint("2001:db8::1"); | ||
| EXPECT_EQ(host, "2001:db8::1"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_WithProtocolAndPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("https://[2001:db8::1]:9090"); | ||
| EXPECT_EQ(host, "2001:db8::1"); | ||
| EXPECT_EQ(port, "9090"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_Localhost) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[::1]:8080"); | ||
| EXPECT_EQ(host, "::1"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_LocalhostWithoutPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("::1"); | ||
| EXPECT_EQ(host, "::1"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_FullAddress) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443"); | ||
| EXPECT_EQ(host, "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); | ||
| EXPECT_EQ(port, "443"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_CompressedZeros) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[fe80::1]:8080"); | ||
| EXPECT_EQ(host, "fe80::1"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_Hostname_WithPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("shard-001.dc1.example.com:8080"); | ||
| EXPECT_EQ(host, "shard-001.dc1.example.com"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_Hostname_WithoutPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("shard-001.dc1.example.com"); | ||
| EXPECT_EQ(host, "shard-001.dc1.example.com"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_Hostname_WithProtocol) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("https://shard-001.dc1.example.com:9090"); | ||
| EXPECT_EQ(host, "shard-001.dc1.example.com"); | ||
| EXPECT_EQ(port, "9090"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_Localhost_WithPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("localhost:8765"); | ||
| EXPECT_EQ(host, "localhost"); | ||
| EXPECT_EQ(port, "8765"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_Localhost_WithoutPort) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("localhost"); | ||
| EXPECT_EQ(host, "localhost"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_MalformedBrackets) { | ||
| // Malformed: missing closing bracket | ||
| auto [host, port] = MTLSClient::parseEndpoint("[2001:db8::1"); | ||
| // Should treat entire string as host | ||
| EXPECT_EQ(host, "[2001:db8::1"); | ||
| EXPECT_EQ(port, "8080"); // Default port | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_LinkLocal) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[fe80::a00:27ff:fe4e:66a1]:8080"); | ||
| EXPECT_EQ(host, "fe80::a00:27ff:fe4e:66a1"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
||
| TEST(MTLSClientTest, ParseEndpoint_IPv6_AllZeros) { | ||
| auto [host, port] = MTLSClient::parseEndpoint("[::]:8080"); | ||
| EXPECT_EQ(host, "::"); | ||
| EXPECT_EQ(port, "8080"); | ||
| } | ||
|
|
There was a problem hiding this comment.
Missing test coverage for edge cases including: empty port strings (e.g., "[::1]:", "192.168.1.1:"), invalid port values (e.g., "[::1]:abc", "host:99999"), and excessively long port numbers. These edge cases should be tested to ensure the parser handles malformed input gracefully.
| size_t bracket_close = url.find(']'); | ||
| if (bracket_close != std::string::npos) { | ||
| // Extract host (without brackets) | ||
| host = url.substr(1, bracket_close - 1); |
There was a problem hiding this comment.
The function doesn't validate that the extracted IPv6 host address is well-formed. Malformed addresses like "[not:valid:ipv6::::]" or "[::]:" would be accepted. Consider adding basic IPv6 address validation to catch obvious malformations early.
| port = url.substr(bracket_close + 2); | ||
| } |
There was a problem hiding this comment.
The function doesn't validate the extracted port string. Malformed input like "[::1]:abc" or "[::1]:99999" would be accepted without validation. Consider adding validation to ensure the port is a valid integer in the range 1-65535.
| if (bracket_close + 1 < url.size() && url[bracket_close + 1] == ':') { | ||
| port = url.substr(bracket_close + 2); | ||
| } |
There was a problem hiding this comment.
The function doesn't handle the case where the port string after the closing bracket is empty (e.g., "[::1]:"). This would result in an empty port string being returned instead of the default port "8080". Consider checking if the extracted port is empty and falling back to the default.
| host = url.substr(0, colon_pos); | ||
| port = url.substr(colon_pos + 1); |
There was a problem hiding this comment.
The function doesn't handle the case where the port string after the colon is empty (e.g., "192.168.1.1:" or "example.com:"). This would result in an empty port string being returned instead of the default port "8080". Consider checking if the extracted port is empty and falling back to the default.
…ry, PDF/Office hash embeddings, ml_model_manager dead-block stubs Agent-Logs-Url: https://github.com/makr-code/ThemisDB/sessions/5328801c-536f-44a2-9dfa-3af6e2830fcc Co-authored-by: makr-code <[email protected]>
…ize, isValidNow, getExtractedText) Agent-Logs-Url: https://github.com/makr-code/ThemisDB/sessions/328511c9-a0cd-4d90-afe4-92ebb5df7703 Co-authored-by: makr-code <[email protected]>
The URN system's endpoint parser used
find_last_of(':')to split host and port, breaking on IPv6 addresses with multiple colons (e.g.,2001:db8::1:8080incorrectly parsed port as8080from within the address).Changes
Core Implementation
MTLSClient::parseEndpoint(): RFC 3986 compliant parsing with bracket detection for IPv6[host]:portformat and extracts correctlymtls_client.h: MadeparseEndpoint()public with documented APITesting
Documentation
docs/sharding/ipv6_support.md: Deployment guide with configuration examplesSupported Formats
No breaking changes. Default port remains 8080 when unspecified.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.