34 using namespace folly;
63 std::cout <<
"received back: " << msg;
69 void readEOF(Context* ctx)
override {
70 std::cout <<
"EOF received :(" << std::endl;
79 std::shared_ptr<AsyncTransportWrapper> sock)
override {
86 pipeline->addBack(EchoHandler());
95 std::shared_ptr<folly::AsyncTransportWrapper>
socket)
override {
104 std::shared_ptr<SSLContext> createSSLContext() {
105 auto context = std::make_shared<SSLContext>();
106 if (!FLAGS_ca_path.empty()) {
107 context->loadTrustedCertificates(FLAGS_ca_path.c_str());
109 context->authenticate(
true,
false);
111 context->setVerificationOption(SSLContext::SSLVerifyPeerEnum::VERIFY);
113 if (!FLAGS_cert_path.empty() && !FLAGS_key_path.empty()) {
114 context->loadCertificate(FLAGS_cert_path.c_str());
115 context->loadPrivateKey(FLAGS_key_path.c_str());
116 if (!
context->isCertKeyPairValid()) {
117 throw std::runtime_error(
"Cert and key do not match");
120 folly::ssl::setSignatureAlgorithms<folly::ssl::SSLCommonOptions>(*context);
130 std::shared_ptr<SSLSessionPersistentCache> cache;
131 if (!FLAGS_cache_file.empty()) {
132 cache = std::make_shared<SSLSessionPersistentCache>(
133 FLAGS_cache_file, 100, std::chrono::seconds(60));
136 EchoClientBootstrap client;
137 client.group(std::make_shared<IOThreadPoolExecutor>(1));
138 client.pipelineFactory(std::make_shared<EchoPipelineFactory>());
141 auto ctx = createSSLContext();
145 ctx->getSSLCtx(), cache.get());
148 VLOG(0) <<
"Reusing session";
149 client.sslSession(session.release());
152 client.sslContext(ctx);
156 VLOG(0) <<
"Connecting";
157 auto pipeline = client.connect(
addr).get();
158 VLOG(0) <<
"Connected";
167 VLOG(0) <<
"Sending " << line;
168 pipeline->write(line +
"\r\n").get();
174 }
catch (
const std::exception& e) {
const std::string SESSION_KEY
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
void BENCHFUN() getline(size_t iters, size_t arg)
DEFINE_bool(ssl, true,"Whether to use SSL")
—— Concurrent Priority Queue Implementation ——
void setSessionKey(std::string sessionKey)
size_t read(T &out, folly::io::Cursor &cursor)
int main(int argc, char **argv)
NetworkSocket socket(int af, int type, int protocol)
static void attachCallbacksToContext(SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
Pipeline< folly::IOBufQueue &, std::string > EchoPipeline
DEFINE_string(ip,"::1","Ip address to connect to")
virtual void makePipeline(std::shared_ptr< folly::AsyncTransportWrapper > socket)
std::shared_ptr< Pipeline > Ptr
DEFINE_uint32(port, 8080,"Port to connect to")
int close(NetworkSocket s)
ThreadPoolListHook * addr