Skip to content

Commit cbdbb52

Browse files
authored
Merge branch 'apache:master' into master
2 parents f46c3b3 + d92e7cf commit cbdbb52

19 files changed

Lines changed: 250 additions & 47 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if(POLICY CMP0042)
4040
cmake_policy(SET CMP0042 NEW)
4141
endif()
4242

43-
set(BRPC_VERSION 1.15.0)
43+
set(BRPC_VERSION 1.16.0)
4444

4545
SET(CPACK_GENERATOR "DEB")
4646
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "brpc authors")

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(
22
name = 'brpc',
3-
version = '1.15.0',
3+
version = '1.16.0',
44
compatibility_level = 1,
55
)
66

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Apache bRPC
2-
Copyright 2018-2025 The Apache Software Foundation
2+
Copyright 2018-2026 The Apache Software Foundation
33

44
This product includes software developed at
55
The Apache Software Foundation (http://www.apache.org/).

RELEASE_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.15.0
1+
1.16.0

package/rpm/brpc.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020
Name: brpc
21-
Version: 1.15.0
21+
Version: 1.16.0
2222
Release: 1%{?dist}
2323
Summary: Industrial-grade RPC framework using C++ Language.
2424

src/brpc/channel.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ ChannelSSLOptions* ChannelOptions::mutable_ssl_options() {
7777
static ChannelSignature ComputeChannelSignature(const ChannelOptions& opt) {
7878
if (opt.auth == NULL &&
7979
!opt.has_ssl_options() &&
80+
opt.client_host.empty() &&
81+
opt.device_name.empty() &&
8082
opt.connection_group.empty() &&
8183
opt.hc_option.health_check_path.empty()) {
8284
// Returning zeroized result by default is more intuitive for users.
@@ -94,6 +96,14 @@ static ChannelSignature ComputeChannelSignature(const ChannelOptions& opt) {
9496
buf.append("|conng=");
9597
buf.append(opt.connection_group);
9698
}
99+
if (!opt.client_host.empty()) {
100+
buf.append("|clih=");
101+
buf.append(opt.client_host);
102+
}
103+
if (!opt.device_name.empty()) {
104+
buf.append("|devn=");
105+
buf.append(opt.device_name);
106+
}
97107
if (opt.auth) {
98108
buf.append("|auth=");
99109
buf.append((char*)&opt.auth, sizeof(opt.auth));
@@ -362,14 +372,27 @@ int Channel::InitSingle(const butil::EndPoint& server_addr_and_port,
362372
LOG(ERROR) << "Invalid port=" << port;
363373
return -1;
364374
}
375+
butil::EndPoint client_endpoint;
376+
if (!_options.client_host.empty() &&
377+
butil::str2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0 &&
378+
butil::hostname2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0) {
379+
LOG(ERROR) << "Invalid client host=`" << _options.client_host << '\'';
380+
return -1;
381+
}
365382
_server_address = server_addr_and_port;
366383
const ChannelSignature sig = ComputeChannelSignature(_options);
367384
std::shared_ptr<SocketSSLContext> ssl_ctx;
368385
if (CreateSocketSSLContext(_options, &ssl_ctx) != 0) {
369386
return -1;
370387
}
388+
SocketOptions opt;
389+
opt.local_side = client_endpoint;
390+
opt.initial_ssl_ctx = ssl_ctx;
391+
opt.use_rdma = _options.use_rdma;
392+
opt.hc_option = _options.hc_option;
393+
opt.device_name = _options.device_name;
371394
if (SocketMapInsert(SocketMapKey(server_addr_and_port, sig),
372-
&_server_id, ssl_ctx, _options.use_rdma, _options.hc_option) != 0) {
395+
&_server_id, opt) != 0) {
373396
LOG(ERROR) << "Fail to insert into SocketMap";
374397
return -1;
375398
}
@@ -397,6 +420,13 @@ int Channel::Init(const char* ns_url,
397420
_options.mutable_ssl_options()->sni_name = _service_name;
398421
}
399422
}
423+
butil::EndPoint client_endpoint;
424+
if (!_options.client_host.empty() &&
425+
butil::str2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0 &&
426+
butil::hostname2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0) {
427+
LOG(ERROR) << "Invalid client host=`" << _options.client_host << '\'';
428+
return -1;
429+
}
400430
std::unique_ptr<LoadBalancerWithNaming> lb(new (std::nothrow)
401431
LoadBalancerWithNaming);
402432
if (NULL == lb) {
@@ -406,10 +436,13 @@ int Channel::Init(const char* ns_url,
406436
GetNamingServiceThreadOptions ns_opt;
407437
ns_opt.succeed_without_server = _options.succeed_without_server;
408438
ns_opt.log_succeed_without_server = _options.log_succeed_without_server;
409-
ns_opt.use_rdma = _options.use_rdma;
439+
ns_opt.socket_option.use_rdma = _options.use_rdma;
410440
ns_opt.channel_signature = ComputeChannelSignature(_options);
411-
ns_opt.hc_option = _options.hc_option;
412-
if (CreateSocketSSLContext(_options, &ns_opt.ssl_ctx) != 0) {
441+
ns_opt.socket_option.hc_option = _options.hc_option;
442+
ns_opt.socket_option.local_side = client_endpoint;
443+
ns_opt.socket_option.device_name = _options.device_name;
444+
if (CreateSocketSSLContext(_options,
445+
&ns_opt.socket_option.initial_ssl_ctx) != 0) {
413446
return -1;
414447
}
415448
if (lb->Init(ns_url, lb_name, _options.ns_filter, &ns_opt) != 0) {

src/brpc/channel.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ struct ChannelOptions {
148148
// Its priority is higher than FLAGS_health_check_path and FLAGS_health_check_timeout_ms.
149149
// When it is not set, FLAGS_health_check_path and FLAGS_health_check_timeout_ms will take effect.
150150
HealthCheckOption hc_option;
151+
152+
// IP address or host name of the client.
153+
// if the client_host is "", the client IP address is determined by the OS.
154+
// Default: ""
155+
std::string client_host;
156+
157+
// The device name of the client's network adapter.
158+
// if the device_name is "", the flow control is determined by the OS.
159+
// Default: ""
160+
std::string device_name;
151161
private:
152162
// SSLOptions is large and not often used, allocate it on heap to
153163
// prevent ChannelOptions from being bloated in most cases.

src/brpc/details/naming_service_thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ void NamingServiceThread::Actions::ResetServers(
125125
// Socket. SocketMapKey may be passed through AddWatcher. Make sure
126126
// to pick those Sockets with the right settings during OnAddedServers
127127
const SocketMapKey key(_added[i], _owner->_options.channel_signature);
128-
CHECK_EQ(0, SocketMapInsert(key, &tagged_id.id, _owner->_options.ssl_ctx,
129-
_owner->_options.use_rdma, _owner->_options.hc_option));
128+
CHECK_EQ(0, SocketMapInsert(key, &tagged_id.id,
129+
_owner->_options.socket_option));
130130
_added_sockets.push_back(tagged_id);
131131
}
132132

src/brpc/details/naming_service_thread.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ class NamingServiceWatcher {
4444
struct GetNamingServiceThreadOptions {
4545
GetNamingServiceThreadOptions()
4646
: succeed_without_server(false)
47-
, log_succeed_without_server(true)
48-
, use_rdma(false) {}
47+
, log_succeed_without_server(true) {
48+
socket_option.use_rdma = false;
49+
}
4950

5051
bool succeed_without_server;
5152
bool log_succeed_without_server;
52-
bool use_rdma;
53-
HealthCheckOption hc_option;
5453
ChannelSignature channel_signature;
55-
std::shared_ptr<SocketSSLContext> ssl_ctx;
54+
SocketOptions socket_option;
5655
};
5756

5857
// A dedicated thread to map a name to ServerIds

src/brpc/selective_channel.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ typedef std::map<ChannelBase*, Socket*> ChannelToIdMap;
4141
class SubChannel : public SocketUser {
4242
public:
4343
ChannelBase* chan;
44+
ChannelOwnership ownership;
4445

4546
// internal channel is deleted after the fake Socket is SetFailed
4647
void BeforeRecycle(Socket*) {
47-
delete chan;
48+
if (ownership == OWNS_CHANNEL) {
49+
delete chan;
50+
}
4851
delete this;
4952
}
5053

@@ -83,7 +86,8 @@ class ChannelBalancer : public SharedLoadBalancer {
8386
ChannelBalancer() {}
8487
~ChannelBalancer();
8588
int Init(const char* lb_name);
86-
int AddChannel(ChannelBase* sub_channel, const std::string& tag,
89+
int AddChannel(ChannelBase* sub_channel,
90+
const SelectiveChannel::SubChannelOptions& subopt,
8791
SelectiveChannel::ChannelHandle* handle);
8892
void RemoveAndDestroyChannel(const SelectiveChannel::ChannelHandle& handle);
8993
int SelectChannel(const LoadBalancer::SelectIn& in, SelectOut* out);
@@ -168,7 +172,8 @@ int ChannelBalancer::Init(const char* lb_name) {
168172
return SharedLoadBalancer::Init(lb_name);
169173
}
170174

171-
int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag,
175+
int ChannelBalancer::AddChannel(ChannelBase* sub_channel,
176+
const SelectiveChannel::SubChannelOptions& subopt,
172177
SelectiveChannel::ChannelHandle* handle) {
173178
if (NULL == sub_channel) {
174179
LOG(ERROR) << "Parameter[sub_channel] is NULL";
@@ -185,6 +190,7 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
185190
return -1;
186191
}
187192
sub_chan->chan = sub_channel;
193+
sub_chan->ownership = subopt.ownership;
188194
SocketId sock_id;
189195
SocketOptions options;
190196
options.user = sub_chan;
@@ -206,7 +212,7 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
206212
<< sock_id << " is disabled";
207213
return -1;
208214
}
209-
if (!AddServer(ServerId(sock_id, tag))) {
215+
if (!AddServer(ServerId(sock_id, subopt.tag))) {
210216
LOG(ERROR) << "Duplicated sub_channel=" << sub_channel;
211217
// sub_chan will be deleted when the socket is recycled.
212218
ptr->SetFailed();
@@ -215,10 +221,10 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
215221
return -1;
216222
}
217223
// The health-check-related reference has been held on created.
218-
_chan_map[sub_channel]= ptr.get();
224+
_chan_map[sub_channel] = ptr.get();
219225
if (handle) {
220226
handle->id = sock_id;
221-
handle->tag = tag;
227+
handle->tag = subopt.tag;
222228
}
223229
return 0;
224230
}
@@ -532,20 +538,15 @@ bool SelectiveChannel::initialized() const {
532538
}
533539

534540
int SelectiveChannel::AddChannel(ChannelBase* sub_channel,
535-
ChannelHandle* handle) {
536-
return AddChannel(sub_channel, "", handle);
537-
}
538-
539-
int SelectiveChannel::AddChannel(ChannelBase* sub_channel,
540-
const std::string& tag,
541+
const SubChannelOptions& option,
541542
ChannelHandle* handle) {
542543
schan::ChannelBalancer* lb =
543544
static_cast<schan::ChannelBalancer*>(_chan._lb.get());
544545
if (lb == NULL) {
545546
LOG(ERROR) << "You must call Init() to initialize a SelectiveChannel";
546547
return -1;
547548
}
548-
return lb->AddChannel(sub_channel, tag, handle);
549+
return lb->AddChannel(sub_channel, option, handle);
549550
}
550551

551552
void SelectiveChannel::RemoveAndDestroyChannel(const ChannelHandle& handle) {

0 commit comments

Comments
 (0)