in mcrouter/lib/network/ThriftTransport.cpp [81:142]
return folly::fibers::runInMainContext(
[this]() -> folly::AsyncTransportWrapper::UniquePtr {
auto expectedSocket = createAsyncSocket(eventBase_, connectionOptions_);
if (expectedSocket.hasError()) {
LOG_FAILURE(
"ThriftTransport",
failure::Category::kBadEnvironment,
"{}",
expectedSocket.error().what());
return {};
}
auto socket = std::move(expectedSocket).value();
auto sockAddressExpected = getSocketAddress(connectionOptions_);
if (sockAddressExpected.hasError()) {
const auto& ex = sockAddressExpected.error();
LOG_FAILURE(
"ThriftTransport",
failure::Category::kBadEnvironment,
"{}",
ex.what());
return {};
}
folly::SocketAddress address = std::move(sockAddressExpected).value();
auto socketOptions = createSocketOptions(address, connectionOptions_);
connectionState_ = ConnectionState::Connecting;
const auto securityMech =
connectionOptions_.accessPoint->getSecurityMech();
if (securityMech == SecurityMech::TLS_TO_PLAINTEXT) {
socket->setSendTimeout(connectionOptions_.writeTimeout.count());
socket->getUnderlyingTransport<AsyncTlsToPlaintextSocket>()->connect(
this,
address,
connectionOptions_.connectTimeout,
std::move(socketOptions));
} else if (securityMech == SecurityMech::TLS) {
socket->setSendTimeout(connectionOptions_.writeTimeout.count());
socket->getUnderlyingTransport<folly::AsyncSSLSocket>()->connect(
this,
address,
connectionOptions_.connectTimeout.count(),
socketOptions);
} else if (securityMech == SecurityMech::TLS13_FIZZ) {
auto fizzClient = socket->getUnderlyingTransport<McFizzClient>();
fizzClient->setSendTimeout(connectionOptions_.writeTimeout.count());
fizzClient->connect(
this,
address,
connectionOptions_.connectTimeout.count(),
socketOptions);
} else {
DCHECK(securityMech == SecurityMech::NONE);
socket->setSendTimeout(connectionOptions_.writeTimeout.count());
socket->getUnderlyingTransport<folly::AsyncSocket>()->connect(
this,
address,
connectionOptions_.connectTimeout.count(),
socketOptions);
}
return socket;
});