Exemplo n.º 1
0
void DestinationClient::initializeAsyncMcClient() {
  FBI_ASSERT(proxy_->eventBase);

  auto pdstn = pdstn_.lock();
  assert(pdstn != nullptr);

  ConnectionOptions options(pdstn->accessPoint);
  options.noNetwork = proxy_->opts.no_network;
  options.tcpKeepAliveCount = proxy_->opts.keepalive_cnt;
  options.tcpKeepAliveIdle = proxy_->opts.keepalive_idle_s;
  options.tcpKeepAliveInterval = proxy_->opts.keepalive_interval_s;
  options.timeout = std::chrono::duration_cast<std::chrono::milliseconds>(
    std::chrono::seconds(pdstn->server_timeout.tv_sec) +
    std::chrono::microseconds(pdstn->server_timeout.tv_usec));
  if (proxy_->opts.enable_qos) {
    options.enableQoS = true;
    options.qos = pdstn->qos;
  }

  if (pdstn->use_ssl) {
    auto& opts = proxy_->opts;
    checkLogic(!opts.pem_cert_path.empty() &&
               !opts.pem_key_path.empty() &&
               !opts.pem_ca_path.empty(),
               "Some of ssl key paths are not set!");
    options.sslContextProvider = [&opts] {
      return getSSLContext(opts.pem_cert_path, opts.pem_key_path,
                           opts.pem_ca_path);
    };
  }

  asyncMcClient_ = folly::make_unique<AsyncMcClient>(*proxy_->eventBase,
                                                     std::move(options));

  auto pdstnWeakPtr = pdstn_;
  asyncMcClient_->setStatusCallbacks(
    [pdstnWeakPtr] () {
      auto pdstnPtr = pdstnWeakPtr.lock();
      if (!pdstnPtr) {
        return;
      }
      pdstnPtr->on_up();
    },
    [pdstnWeakPtr] (const apache::thrift::transport::TTransportException&) {
      auto pdstnPtr = pdstnWeakPtr.lock();
      if (!pdstnPtr) {
        return;
      }
      pdstnPtr->on_down();
    });

  if (proxy_->opts.target_max_inflight_requests > 0) {
    asyncMcClient_->setThrottle(proxy_->opts.target_max_inflight_requests,
                                proxy_->opts.target_max_pending_requests);
  }
}
Exemplo n.º 2
0
 void connectionAccepted(
     int fd,
     const folly::SocketAddress& clientAddr) noexcept override {
   if (secure_) {
     auto& opts = mcServerThread_->server_.opts_;
     auto sslCtx = getSSLContext(opts.pemCertPath, opts.pemKeyPath,
                                 opts.pemCaPath);
     if (sslCtx) {
       sslCtx->setVerificationOption(
         folly::SSLContext::SSLVerifyPeerEnum::VERIFY_REQ_CLIENT_CERT);
       mcServerThread_->worker_.addSecureClientSocket(fd, std::move(sslCtx));
     } else {
       ::close(fd);
     }
   } else {
     mcServerThread_->worker_.addClientSocket(fd);
   }
 }
Exemplo n.º 3
0
void CurlClient::connect(const std::string& host, uint16_t port)
{
    LOG(INFO) << "connect !";
	//folly::EventBase* evb = folly::EventBaseManager::get()->getEventBase();
	HHWheelTimer::UniquePtr timer{
	    new HHWheelTimer(
	    	evb_,
	        std::chrono::milliseconds(HHWheelTimer::DEFAULT_TICK_INTERVAL),
	        AsyncTimeout::InternalEnum::NORMAL,
	        std::chrono::milliseconds(50000))};
	timer_ = std::move(timer);
	connector_ = std::make_shared<proxygen::HTTPConnector>(this, timer_.get());
	//URL url("https://newapi.mogujie.com/gw/mwp.Petstore.helloworld/2");
    URL url("https://newapi.mogujie.com/gw/mwp.PetStore.helloWorld/2/?data=123");
	SocketAddress addr(url.getHost(), url.getPort(), true);
	static const AsyncSocket::OptionMap opts{{{SOL_SOCKET, SO_REUSEADDR}, 1}};
	connector_->connectSSL(
		evb_, addr, getSSLContext(), nullptr,
	      std::chrono::milliseconds(1000), opts,
	      folly::AsyncSocket::anyAddress(), getServerName());
    LOG(INFO) << "after connect!";
    std::cout << "after connect!";
}
SSLContextProvider brokenSsl() {
  return []() {
    return getSSLContext(kBrokenCertPath, kBrokenKeyPath, kPemCaPath);
  };
}
SSLContextProvider invalidSsl() {
  return []() {
    return getSSLContext(kInvalidCertPath, kInvalidKeyPath, kPemCaPath);
  };
}