| 34 | namespace c2 { |
| 35 | |
| 36 | void ControllerSocketProtocol::initialize(core::controller::ControllerServiceProvider* controller, const std::shared_ptr<state::StateMonitor> &updateSink, |
| 37 | const std::shared_ptr<Configure> &configuration) { |
| 38 | HeartBeatReporter::initialize(controller, updateSink, configuration); |
| 39 | stream_factory_ = minifi::io::StreamFactory::getInstance(configuration); |
| 40 | |
| 41 | std::string host = "localhost", port, limitStr, context_name; |
| 42 | bool anyInterface = false; |
| 43 | |
| 44 | std::shared_ptr<minifi::controllers::SSLContextService> secure_context = nullptr; |
| 45 | |
| 46 | if (configuration_->get("controller.ssl.context.service", context_name)) { |
| 47 | std::shared_ptr<core::controller::ControllerService> service = controller->getControllerService(context_name); |
| 48 | if (nullptr != service) { |
| 49 | secure_context = std::static_pointer_cast<minifi::controllers::SSLContextService>(service); |
| 50 | } |
| 51 | } |
| 52 | if (nullptr == secure_context) { |
| 53 | std::string secureStr; |
| 54 | bool is_secure = false; |
| 55 | if (configuration->get(Configure::nifi_remote_input_secure, secureStr) && org::apache::nifi::minifi::utils::StringUtils::StringToBool(secureStr, is_secure)) { |
| 56 | secure_context = std::make_shared<minifi::controllers::SSLContextService>("ControllerSocketProtocolSSL", configuration); |
| 57 | secure_context->onEnable(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | std::string value; |
| 62 | |
| 63 | if (configuration_->get("controller.socket.local.any.interface", limitStr)) { |
| 64 | utils::StringUtils::StringToBool(limitStr, anyInterface); |
| 65 | } |
| 66 | |
| 67 | // if host name isn't defined we will use localhost |
| 68 | configuration_->get("controller.socket.host", host); |
| 69 | |
| 70 | if (nullptr != configuration_ && configuration_->get("controller.socket.port", port)) { |
| 71 | if (nullptr != secure_context) { |
| 72 | #ifdef OPENSSL_SUPPORT |
| 73 | // if there is no openssl support we won't be using SSL |
| 74 | auto tls_context = std::make_shared<io::TLSContext>(configuration, secure_context); |
| 75 | server_socket_ = std::unique_ptr<io::BaseServerSocket>(new io::TLSServerSocket(tls_context, host, std::stoi(port), 2)); |
| 76 | #else |
| 77 | server_socket_ = std::unique_ptr<io::BaseServerSocket>(new io::ServerSocket(nullptr, host, std::stoi(port), 2)); |
| 78 | #endif |
| 79 | } else { |
| 80 | server_socket_ = std::unique_ptr<io::BaseServerSocket>(new io::ServerSocket(nullptr, host, std::stoi(port), 2)); |
| 81 | } |
| 82 | // if we have a localhost hostname and we did not manually specify any.interface we will |
| 83 | // bind only to the loopback adapter |
| 84 | if ((host == "localhost" || host == "127.0.0.1" || host == "::") && !anyInterface) { |
| 85 | server_socket_->initialize(true); |
| 86 | } else { |
| 87 | server_socket_->initialize(false); |
| 88 | } |
| 89 | |
| 90 | auto check = [this]() -> bool { |
| 91 | return update_sink_->isRunning(); |
| 92 | }; |
| 93 |
nothing calls this directly
no test coverage detected