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

[WIP]feat: support ipv6 #100

Open
wants to merge 42 commits into
base: unstable
Choose a base branch
from
Open

[WIP]feat: support ipv6 #100

wants to merge 42 commits into from

Conversation

marsevilspirit
Copy link
Collaborator

@marsevilspirit marsevilspirit commented Nov 30, 2024

support ipv6

Summary by CodeRabbit

Based on the comprehensive changes, here are the updated release notes:

  • Configuration Updates

    • Added support for multiple IP addresses in server configuration.
    • Introduced new configuration option for Raft server IP.
  • Network Improvements

    • Enhanced socket handling to support both IPv4 and IPv6.
    • Enabled listening on multiple network interfaces simultaneously.
    • Improved IP address validation and configuration management.
  • Performance Enhancements

    • Refined event handling for multiple listening sockets.
    • Updated thread management to support multiple network interfaces.
  • Bug Fixes

    • Corrected configuration syntax for RocksDB periodic settings.
    • Improved error handling in socket and network operations.

Copy link

coderabbitai bot commented Nov 30, 2024

Walkthrough

This pull request introduces comprehensive modifications to support multiple IP addresses and enhance IPv6 compatibility across the KiwiDB networking stack. The changes span configuration management, socket handling, and network event processing. Key updates include allowing multiple listening addresses, improving socket creation for IPv4 and IPv6, and refactoring configuration handling to support more flexible network configurations.

Changes

File Change Summary
etc/conf/kiwi.conf Updated IP configuration to support multiple addresses, added Raft IP setting
src/net/base_socket.{h,cc} Enhanced socket creation with IPv6 support, added SetDisableIpv6Only method
src/config.{h,cc} Replaced single IP with IP vector, added Raft-specific IP configuration
src/net/event_server.h Modified to handle multiple listening addresses
src/net/socket_addr.h Comprehensive updates for IPv4/IPv6 address handling
src/net/{epoll_event,kqueue_event,listening_socket}.h Updated constructors and methods to support multiple listening sockets
src/net/{epoll_event,kqueue_event}.cc Enhanced event handling to manage multiple listening sockets
src/net/thread_manager.h Updated methods to handle multiple listening sockets
src/net/client_socket.cc Modified connection handling to utilize address parameter
src/net/listen_socket.h Added method to retrieve listening address
src/cmd_admin.cc Improved IP validation logic for shutdown command
src/replication.cc Updated master IP address check for Raft service
src/raft/raft.cc Refactored to use Raft-specific IP configuration

Sequence Diagram

sequenceDiagram
    participant Config as Configuration
    participant EventServer as Event Server
    participant ListenSocket as Listen Socket
    participant NetworkStack as Network Stack

    Config->>Config: Define multiple IPs
    Config->>EventServer: Pass IP list
    EventServer->>ListenSocket: Create socket for each IP
    ListenSocket->>NetworkStack: Bind and listen
    NetworkStack-->>EventServer: Confirm socket readiness
Loading

Possibly related PRs

Poem

🐰 Hopping through network lanes,
IPv4 and IPv6 in my veins,
Sockets dancing, addresses free,
KiwiDB's network, now multi-key!
Bind them all, with rabbit's might! 🌐


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@marsevilspirit marsevilspirit requested review from lqxhub and luky116 and removed request for lqxhub and luky116 November 30, 2024 09:29
@luky116
Copy link
Collaborator

luky116 commented Nov 30, 2024

想本地跑下看看效果,发现使用这个分支在本地无法进行编译,我是 mac m2 芯片,你看看

image

@marsevilspirit
Copy link
Collaborator Author

想本地跑下看看效果,发现使用这个分支在本地无法进行编译,我是 mac m2 芯片,你看看

image

可能是我删除了一些头文件的问题,我修改一下

这个pr目前还没有完成,目标是可以同时bind ipv4 和 ipv6,创造出两个fd 去 listen,目前只能bind其中之一。

@luky116 luky116 changed the title feat: support ipv6 【WIP】feat: support ipv6 Nov 30, 2024
@luky116
Copy link
Collaborator

luky116 commented Nov 30, 2024

试试在 free BSD 系统是否能通过,他代表mac系统的运行环境

@marsevilspirit
Copy link
Collaborator Author

目前支持了ipv4和ipv6的同时bind和listen, 后续准备优化一下代码,目前的代码有些许丑陋,并准备在conf中添加ipv6的使用选项

Copy link
Collaborator

@lqxhub lqxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个baseEvent里,不放两个listen, 而是如果需要listen ipv6的话,直接在 start那里,启动两个listenSocket,一个是ipv4的,一个是ipv6的, 这样会不会改动更小, 看起来也更清晰

src/client.h Outdated Show resolved Hide resolved
@marsevilspirit
Copy link
Collaborator Author

marsevilspirit commented Dec 30, 2024

conf 的 ip 配置处理完毕, 可review

@marsevilspirit marsevilspirit changed the title feat: support ipv6 [WIP]feat: support ipv6 Jan 6, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9ceb4a and 2aada3b.

📒 Files selected for processing (23)
  • etc/conf/kiwi.conf (2 hunks)
  • src/cmd_admin.cc (1 hunks)
  • src/config.cc (2 hunks)
  • src/config.h (4 hunks)
  • src/kiwi.cc (1 hunks)
  • src/kiwi_logo.h (1 hunks)
  • src/net/base_event.h (4 hunks)
  • src/net/base_socket.cc (2 hunks)
  • src/net/base_socket.h (2 hunks)
  • src/net/callback_function.h (1 hunks)
  • src/net/client_socket.cc (2 hunks)
  • src/net/epoll_event.cc (3 hunks)
  • src/net/epoll_event.h (2 hunks)
  • src/net/event_server.h (4 hunks)
  • src/net/kqueue_event.cc (3 hunks)
  • src/net/kqueue_event.h (1 hunks)
  • src/net/listen_socket.cc (3 hunks)
  • src/net/listen_socket.h (1 hunks)
  • src/net/socket_addr.h (1 hunks)
  • src/net/stream_socket.cc (1 hunks)
  • src/net/thread_manager.h (5 hunks)
  • src/raft/raft.cc (2 hunks)
  • src/replication.cc (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (15)
  • src/net/listen_socket.h
  • src/kiwi.cc
  • src/net/base_socket.h
  • src/net/kqueue_event.h
  • src/net/callback_function.h
  • src/net/client_socket.cc
  • src/replication.cc
  • src/kiwi_logo.h
  • src/net/listen_socket.cc
  • src/net/stream_socket.cc
  • src/net/base_socket.cc
  • src/net/kqueue_event.cc
  • src/net/epoll_event.cc
  • src/net/base_event.h
  • src/cmd_admin.cc
🔇 Additional comments (13)
src/raft/raft.cc (1)

327-327: Verify consistency of IP configuration usage.

The change from g_config.ip to g_config.raft_ip should be consistently applied across all Raft-related functionality.

Run the following script to verify consistent usage:

✅ Verification successful

The change from g_config.ip to g_config.raft_ip is consistently applied

The codebase shows proper separation between general IP configuration (g_config.ip/ips) and Raft-specific IP configuration (g_config.raft_ip). All Raft-related functionality consistently uses g_config.raft_ip.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of g_config.ip that should be g_config.raft_ip
rg 'g_config\.ip' src/raft/

Length of output: 126


Script:

#!/bin/bash
# Search for any remaining g_config.ip instances in the entire codebase
rg 'g_config\.ip' -A 2

# Search for g_config.raft_ip usage to verify consistency
rg 'g_config\.raft_ip' -A 2

Length of output: 1321

src/net/epoll_event.h (1)

26-27: LGTM! Constructor updated to support multiple listen sockets.

The constructor has been properly modified to handle multiple listening sockets, which is necessary for supporting both IPv4 and IPv6 simultaneously. The initialization list correctly forwards the parameters to the base class.

src/net/socket_addr.h (2)

21-25: LGTM! Memory operations are safe and efficient.

The use of memcpy with sizeof(addr_) is appropriate for copying the union structure.


101-112: LGTM! Comparison operators handle both IPv4 and IPv6 correctly.

The equality comparison is properly implemented with appropriate checks for address family and memory comparison for IPv6 addresses.

src/config.cc (2)

10-10: Remove unnecessary include.

The <iostream> include was previously flagged for removal and should be deleted as it's not being used.

-#include <iostream>  //delete

137-138: LGTM! Good IPv6 support implementation.

The changes correctly implement support for multiple IP addresses and Raft configuration:

  • Using AddStringArray for multiple IP bindings supports both IPv4 and IPv6
  • Separate Raft IP configuration allows for flexible network topology
src/net/thread_manager.h (2)

58-58: LGTM! Well-structured interface changes for multi-socket support.

The method signatures are properly updated to handle multiple listening sockets, which is essential for IPv6 support. The parameter names are clear and follow the project's naming conventions.

Also applies to: 86-87


127-129: LGTM! Clean implementation of multi-socket initialization.

The implementation correctly handles the initialization of multiple listening sockets and maintains backward compatibility with the existing timer functionality.

etc/conf/kiwi.conf (3)

12-12: LGTM! Clear IPv6 configuration.

The configuration now properly supports both IPv4 (127.0.0.1) and IPv6 (::1) addresses.


345-345: LGTM! Fixed configuration syntax.

Removed trailing semicolon for consistency with the configuration format.


348-351: LGTM! Well-documented Raft IP configuration.

The Raft IP configuration is properly documented and maintains consistent spacing with surrounding sections.

src/config.h (2)

286-288: LGTM! Clear documentation and implementation for IPv6 support.

The changes properly implement IPv6 support:

  • Documentation clearly explains the dual-stack support
  • Default configuration includes both IPv4 and IPv6 loopback addresses

345-347: LGTM! Well-structured Raft IP configuration.

The Raft IP configuration is properly implemented with a sensible default value.

src/raft/raft.cc Outdated Show resolved Hide resolved
src/net/socket_addr.h Outdated Show resolved Hide resolved
src/net/socket_addr.h Outdated Show resolved Hide resolved
src/net/event_server.h Outdated Show resolved Hide resolved
src/net/event_server.h Outdated Show resolved Hide resolved
@marsevilspirit marsevilspirit changed the title [WIP]feat: support ipv6 feat: support ipv6 Jan 15, 2025
@marsevilspirit
Copy link
Collaborator Author

build bug fixd

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/net/event_server.h (1)

Line range hint 278-282: Add comprehensive error handling.

Consider adding:

  1. Cleanup of listen sockets when thread start fails
  2. Validation that listenSockets is not empty in server mode

Apply this diff to add the suggested error handling:

+    if (serverMode && listenSockets.empty()) {
+      return static_cast<int>(NetListen::ERROR);
+    }
     bool ret = i == 0 ? thread->Start(listenSockets, timer_) : thread->Start(listenSockets, nullptr);
     if (!ret) {
+      listenSockets.clear();  // Clean up sockets on thread start failure
       return -1;
     }
src/net/socket_addr.h (1)

46-48: Enhance error handling with more descriptive messages.

Add the scope resolution operator and provide more descriptive error messages.

-    if (::inet_pton(AF_INET6, ip.c_str(), &addr_.addr6_.sin6_addr) != 1) {
-      throw std::invalid_argument("Invalid IP address format");
+    if (::inet_pton(AF_INET6, ip.c_str(), &addr_.addr6_.sin6_addr) != 1) {
+      throw ::std::invalid_argument("Invalid IPv6 address format: " + ip);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0e0fe1 and f27731b.

📒 Files selected for processing (10)
  • src/kiwi.cc (2 hunks)
  • src/net/epoll_event.cc (6 hunks)
  • src/net/event_server.h (4 hunks)
  • src/net/kqueue_event.cc (4 hunks)
  • src/net/listen_socket.cc (4 hunks)
  • src/net/socket_addr.h (1 hunks)
  • src/net/timer.cc (1 hunks)
  • src/raft/raft.cc (2 hunks)
  • src/storage/src/debug.h (1 hunks)
  • src/storage/src/options_helper.h (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/storage/src/debug.h
  • src/storage/src/options_helper.h
  • src/net/timer.cc
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/kiwi.cc
  • src/net/listen_socket.cc
  • src/raft/raft.cc
  • src/net/epoll_event.cc
  • src/net/kqueue_event.cc
🔇 Additional comments (8)
src/net/event_server.h (3)

10-10: LGTM! Good preparation for multi-address support.

The addition of sys/socket.h and conversion of listenAddrs_ to a vector properly sets up the foundation for supporting multiple listening addresses, which is essential for dual-stack IPv4/IPv6 support.

Also applies to: 92-92


46-46: Implementation follows previous review feedback.

Good use of emplace_back for efficient in-place construction of socket addresses.


257-258: LGTM! Proper cleanup implementation.

Good implementation of socket cleanup on initialization failure, following the previous review feedback.

Also applies to: 271-272

src/net/socket_addr.h (5)

21-28: LGTM! Copy operations are correctly implemented.

The copy constructor and assignment operator correctly handle both IPv4 and IPv6 addresses using safe memory operations.


97-101: LGTM! Utility methods are well-implemented.

The validity and address family checking methods are concise and correct.


103-124: LGTM! Memory management and comparisons are well-implemented.

The Clear method, equality operators, and address storage union are correctly implemented with proper handling of both IPv4 and IPv6 addresses.


82-88: ⚠️ Potential issue

Add error handling to GetIP buffer method.

The buffer-based GetIP method lacks error handling and could potentially write beyond buffer bounds.

   std::string GetIP(char *buf, socklen_t size) const {
     if (IsIPV4()) {
-      ::inet_ntop(AF_INET, &addr_.addr4_.sin_addr, buf, size);
+      if (!::inet_ntop(AF_INET, &addr_.addr4_.sin_addr, buf, size)) {
+        throw ::std::runtime_error("Failed to convert IPv4 address to string");
+      }
       return buf;
     }
-    ::inet_ntop(AF_INET6, &addr_.addr6_.sin6_addr, buf, size);
+    if (!::inet_ntop(AF_INET6, &addr_.addr6_.sin6_addr, buf, size)) {
+      throw ::std::runtime_error("Failed to convert IPv6 address to string");
+    }
     return buf;
   }

Likely invalid or redundant comment.


53-65: Verify usage of GetAddr and GetAddrLen in socket operations.

Let's verify that these methods are used correctly in socket creation and binding operations throughout the codebase.

✅ Verification successful

GetAddr and GetAddrLen methods are correctly used in socket operations

The methods are properly used in pairs for both server-side binding and client connections, with appropriate error handling and correct parameter types for socket API calls.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for socket creation and binding operations
rg -A 5 "socket\(" 
rg -A 5 "bind\("

# Search for GetAddr and GetAddrLen usage
rg -A 2 "GetAddr\(\)" 
rg -A 2 "GetAddrLen\(\)"

Length of output: 3427

src/net/event_server.h Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
src/net/event_server.h (1)

266-273: Consider adding configuration option for port reuse.

While the port reuse implementation is correct, consider making it configurable through NetOptions since it might not be desired in all deployment scenarios.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7e0f35 and b4f8d9b.

📒 Files selected for processing (1)
  • src/net/event_server.h (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build_on_ubuntu
  • GitHub Check: build_on_macos
🔇 Additional comments (6)
src/net/event_server.h (6)

10-15: LGTM! Appropriate system header inclusion.

The addition of <sys/socket.h> is necessary for socket-related functionality and follows proper include organization.


46-46: LGTM! Efficient implementation using emplace_back.

The method correctly uses emplace_back for efficient insertion into the vector, as previously suggested.


92-92: LGTM! Vector implementation supports multiple addresses.

The change from single address to vector enables listening on multiple addresses, supporting both IPv4 and IPv6 simultaneously.


278-278: LGTM! Proper thread initialization with timer control.

The implementation correctly initializes threads with the socket vector and restricts timer to the first thread.


251-259: Verify IPv6 socket initialization across different platforms.

The socket initialization looks correct but should be tested on various platforms (as mentioned in PR comments about FreeBSD and macOS).

Run this script to check socket implementation across files:

✅ Verification successful

IPv6 socket initialization verified as platform-independent

The implementation uses standard POSIX socket APIs and proper error handling, making it safe across different platforms including FreeBSD and macOS. No platform-specific code is required as it follows established networking standards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for IPv6-related socket configurations and platform-specific code
rg -A 3 "AF_INET6|IPV6_V6ONLY|in6_addr"

# Check for platform-specific socket implementations
ast-grep --pattern 'if defined(__FreeBSD__) || defined(__APPLE__) { $$$ }'

Length of output: 1974


249-273: Verify dual-stack socket behavior.

Please ensure the implementation correctly handles dual-stack (IPv4 + IPv6) scenarios:

  1. Binding to both IPv4 and IPv6 addresses simultaneously
  2. Proper handling of IPv4-mapped IPv6 addresses
  3. Correct behavior when only IPv6 is available

Run this script to check dual-stack implementation:

✅ Verification successful

Dual-stack socket implementation verified

The implementation correctly handles dual-stack scenarios with proper:

  • Address family detection and socket creation
  • IPv4 and IPv6 address initialization
  • Dual-stack control via IPV6_V6ONLY socket option
  • Address validation and conversion
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for dual-stack socket configurations
rg -A 5 "IPV6_V6ONLY|AF_INET6.*AF_INET"

# Check for IPv4-mapped IPv6 address handling
ast-grep --pattern 'struct sockaddr_in6 { $$$ }'

Length of output: 448


Script:

#!/bin/bash
# Check socket creation and address family handling
ast-grep --pattern 'socket($$$)'

# Find address family selection logic
rg -B 3 -A 3 "AF_INET6|AF_INET" src/net/

# Look for bind implementation
ast-grep --pattern 'bind($$$)'

Length of output: 3712

@luky116
Copy link
Collaborator

luky116 commented Jan 18, 2025

待看 japson 如何处理配置多个 IP 地址的问题,再考虑合并

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


It remains to be seen how japson handles the problem of configuring multiple IP addresses before considering merging it.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
src/config.h (1)

352-354: Consider using dual-stack for Raft communication.

The Raft IP configuration currently defaults to IPv4 only. Consider supporting both IPv4 and IPv6 for Raft communication as well.

Consider updating the Raft IP configuration similar to the main IP configuration:

-  std::string raft_ip = "127.0.0.1";
+  std::vector<std::string> raft_ips = {"127.0.0.1", "::1"};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4f8d9b and 762f95a.

📒 Files selected for processing (8)
  • etc/conf/kiwi.conf (2 hunks)
  • src/config.cc (2 hunks)
  • src/config.h (4 hunks)
  • src/kiwi.cc (1 hunks)
  • src/net/base_socket.cc (2 hunks)
  • src/net/base_socket.h (2 hunks)
  • src/net/event_server.h (4 hunks)
  • src/net/thread_manager.h (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/net/base_socket.h
  • src/kiwi.cc
  • src/config.cc
  • src/net/base_socket.cc
  • etc/conf/kiwi.conf
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build_on_ubuntu
  • GitHub Check: build_on_macos
🔇 Additional comments (8)
src/net/event_server.h (3)

46-46: LGTM! Method inlining optimization.

The AddListenAddr method is now marked as inline, which is appropriate for this small, frequently called method.


92-92: LGTM! Data structure change to support multiple addresses.

Changed listenAddrs_ from a single SocketAddr to std::vector<SocketAddr> to support multiple listening addresses for IPv4/IPv6.


249-281: 🛠️ Refactor suggestion

Verify error handling in socket initialization loop.

The socket initialization loop now handles multiple addresses, but there's a potential resource leak if initialization fails for any socket after the first one.

Apply this diff to ensure proper cleanup:

  if (serverMode) {
    for (auto &listenAddr : listenAddrs_) {
      std::shared_ptr<ListenSocket> listen(ListenSocket::CreateTCPListen());
      listen->SetListenAddr(listenAddr);
      listen->SetBSTcpKeepAlive(tcpKeepAlive);
-     listenSockets.push_back(listen);
      if (auto ret = (listen->Init() != static_cast<int>(NetListen::OK))) {
        listenSockets.clear();  // Clean up all sockets
        return ret;
      }
+     listenSockets.push_back(listen);
    }
  }

Run this script to verify error handling in similar patterns:

src/net/thread_manager.h (4)

58-58: LGTM! Method signatures updated for multiple sockets.

The method signatures have been updated to accept a vector of sockets instead of a single socket, aligning with the IPv6 support changes.

Also applies to: 86-87


128-130: LGTM! Start method updated for multiple sockets.

The Start method has been updated to pass the vector of sockets to CreateReadThread.


279-280: LGTM! Event creation updated for multiple sockets.

The event creation has been updated to handle multiple sockets for both epoll and kqueue events.

Also applies to: 288-288, 290-290


322-322: LGTM! Write thread initialization with empty socket list.

The write thread is correctly initialized with an empty vector of sockets as it doesn't need to listen for new connections.

Also applies to: 324-324

src/config.h (1)

293-295: LGTM! Configuration updated for dual-stack support.

The IP configuration has been updated to support both IPv4 (127.0.0.1) and IPv6 (::1) addresses by default.

Run this script to verify the configuration handling:

✅ Verification successful

Dual-stack support properly implemented and verified

The implementation correctly supports both IPv4 and IPv6:

  • Socket layer has proper dual-stack support with IPv6 socket options
  • Configuration system correctly handles multiple IP addresses
  • Raft subsystem intentionally uses a single configurable IP for cluster setup
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the configuration parser correctly handles multiple IP addresses

# Check if the configuration parser handles both IPv4 and IPv6 addresses
ast-grep --pattern 'AddStringArray($_, $_, $_)'

# Check for any hardcoded IP addresses that might need to be updated
rg -g '!*.md' '127\.0\.0\.1|::1'

Length of output: 1635


Script:

#!/bin/bash
# Check raft implementation for IPv6 support and config parsing
# Look for IP address parsing/validation in raft code
rg -g '*.{h,cc}' -B 2 -A 2 'ParseIP|ValidateIP|addr|address' src/raft/

# Check configuration parsing implementation
ast-grep --pattern 'class Config {
  $$$
}'

# Look for any IPv6 related code
rg -g '*.{h,cc}' '(?i)ipv6|::1|AF_INET6'

Length of output: 23217

@AlexStocks
Copy link
Contributor

待看 japson 如何处理配置多个 IP 地址的问题,再考虑合并

是 jephsen 测试

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Wait and see how japson handles the problem of configuring multiple IP addresses before considering merging

is jephsen test

@marsevilspirit marsevilspirit changed the title feat: support ipv6 [WIP]feat: support ipv6 Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants