@@ -77,6 +77,8 @@ ChannelSSLOptions* ChannelOptions::mutable_ssl_options() {
7777static 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 ) {
0 commit comments