| 330 | } |
| 331 | |
| 332 | int Channel::InitSingle(const butil::EndPoint& server_addr_and_port, |
| 333 | const char* raw_server_address, |
| 334 | const ChannelOptions* options, |
| 335 | int raw_port) { |
| 336 | GlobalInitializeOrDie(); |
| 337 | if (InitChannelOptions(options) != 0) { |
| 338 | return -1; |
| 339 | } |
| 340 | int* port_out = raw_port == -1 ? &raw_port: NULL; |
| 341 | ParseURL(raw_server_address, &_scheme, &_service_name, port_out); |
| 342 | if (raw_port != -1) { |
| 343 | _service_name.append(":").append(std::to_string(raw_port)); |
| 344 | } |
| 345 | if (_options.protocol == brpc::PROTOCOL_HTTP && _scheme == "https") { |
| 346 | if (_options.mutable_ssl_options()->sni_name.empty()) { |
| 347 | _options.mutable_ssl_options()->sni_name = _service_name; |
| 348 | } |
| 349 | } |
| 350 | const int port = server_addr_and_port.port; |
| 351 | if (port < 0) { |
| 352 | LOG(ERROR) << "Invalid port=" << port; |
| 353 | return -1; |
| 354 | } |
| 355 | butil::EndPoint client_endpoint; |
| 356 | if (!_options.client_host.empty() && |
| 357 | butil::str2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0 && |
| 358 | butil::hostname2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0) { |
| 359 | LOG(ERROR) << "Invalid client host=`" << _options.client_host << '\''; |
| 360 | return -1; |
| 361 | } |
| 362 | _server_address = server_addr_and_port; |
| 363 | const ChannelSignature sig = ComputeChannelSignature(_options); |
| 364 | std::shared_ptr<SocketSSLContext> ssl_ctx; |
| 365 | if (CreateSocketSSLContext(_options, &ssl_ctx) != 0) { |
| 366 | return -1; |
| 367 | } |
| 368 | SocketOptions opt; |
| 369 | opt.local_side = client_endpoint; |
| 370 | opt.initial_ssl_ctx = ssl_ctx; |
| 371 | opt.socket_mode = _options.socket_mode; |
| 372 | opt.hc_option = _options.hc_option; |
| 373 | opt.device_name = _options.device_name; |
| 374 | if (SocketMapInsert(SocketMapKey(server_addr_and_port, sig), |
| 375 | &_server_id, opt) != 0) { |
| 376 | LOG(ERROR) << "Fail to insert into SocketMap"; |
| 377 | return -1; |
| 378 | } |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | int Channel::Init(const char* ns_url, |
| 383 | const char* lb_name, |
nothing calls this directly
no test coverage detected