Skip to content

Conversation

@wenjiecn
Copy link
Contributor

@wenjiecn wenjiecn commented Dec 25, 2025

What problem does this PR solve?

Issue Number: #3157, #3178

Problem Summary:

What is changed and the side effects?

Changed:
1.在ChannelOptions中添加client_host,让用户设置client的ip或hostname
2.在SocketOptions 中添加butil::EndPoint local_side,由 client_host:0 -> local_side
3.在GetNamingServiceThreadOptions添加butil::EndPoint client_end_point,由 client_host:0 -> client_end_point
4.在ComputeChannelSignature中append "clih=client_host", 进行hash
5.在系统调用socket创建socket后,调用bind绑定ip
Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

@wwbmmm
Copy link
Contributor

wwbmmm commented Dec 26, 2025

The unit test is broken, please fix.

Copy link

Copilot AI left a 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 binding client sockets to a specific IP address or hostname before connecting to a server, addressing issue #3157. The feature allows users to control which local network interface is used for outgoing connections.

  • Adds client_host field to ChannelOptions for user configuration
  • Propagates client endpoint information through SocketOptions, GetNamingServiceThreadOptions, and channel signature computation
  • Implements socket binding in Socket::Connect() to bind the client socket to the specified IP before connecting

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/brpc/channel.h Adds client_host string field to ChannelOptions for specifying client IP/hostname
src/brpc/channel.cpp Implements parsing of client_host to EndPoint and includes it in channel signature; handles both InitSingle and Init paths
src/brpc/socket.h Adds local_side field to SocketOptions to store the client endpoint
src/brpc/socket.cpp Implements bind() call in Connect() to bind socket to client IP; initializes local_side from options
src/brpc/socket_map.h Updates function signatures to accept client_end_point parameter
src/brpc/socket_map.cpp Passes client_end_point through to SocketOptions when creating sockets
src/brpc/details/naming_service_thread.h Adds client_end_point field to GetNamingServiceThreadOptions
src/brpc/details/naming_service_thread.cpp Passes client_end_point to SocketMapInsert when adding servers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjiecn wenjiecn reopened this Dec 26, 2025
@wenjiecn wenjiecn changed the title bind_client_ip support bind client ip Dec 26, 2025
@wenjiecn wenjiecn closed this Dec 27, 2025
@wenjiecn wenjiecn reopened this Dec 27, 2025
@wenjiecn wenjiecn closed this Dec 27, 2025
@wenjiecn wenjiecn reopened this Dec 27, 2025
@chenBright
Copy link
Contributor

Please add some unit tests for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

是否支持SO_BINDTODEVICE brpc channel 能否支持绑定client ip

3 participants