proxygen
Client.cpp File Reference

Go to the source code of this file.

Functions

 DEFINE_string (ip,"::1","Ip address to connect to")
 
 DEFINE_uint32 (port, 8080,"Port to connect to")
 
 DEFINE_bool (ssl, true,"Whether to use SSL")
 
 DEFINE_string (cache_file,"","Session cache file")
 
 DEFINE_string (cert_path,"","Path to client cert pem")
 
 DEFINE_string (key_path,"","Path to client cert key pem")
 
 DEFINE_string (ca_path,"","Path to trusted CA file")
 
int main (int argc, char **argv)
 

Variables

const std::string SESSION_KEY = "test_client"
 

Function Documentation

DEFINE_bool ( ssl  ,
true  ,
"Whether to use SSL"   
)
DEFINE_string ( ip  ,
"::1"  ,
"Ip address to connect to"   
)
DEFINE_string ( cache_file  ,
""  ,
"Session cache file"   
)
DEFINE_string ( cert_path  ,
""  ,
"Path to client cert pem"   
)
DEFINE_string ( key_path  ,
""  ,
"Path to client cert key pem"   
)
DEFINE_string ( ca_path  ,
""  ,
"Path to trusted CA file"   
)
DEFINE_uint32 ( port  ,
8080  ,
"Port to connect to"   
)
int main ( int  argc,
char **  argv 
)

Definition at line 125 of file Client.cpp.

References addr, wangle::SSLSessionCallbacks::attachCallbacksToContext(), folly::exceptionStr(), getline(), folly::ssl::init(), bm::init(), SESSION_KEY, and string.

125  {
126  folly::Init init(&argc, &argv);
128 
129  // an in memory ssl session cache used for caching sessions
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));
134  }
135 
136  EchoClientBootstrap client;
137  client.group(std::make_shared<IOThreadPoolExecutor>(1));
138  client.pipelineFactory(std::make_shared<EchoPipelineFactory>());
139 
140  if (FLAGS_ssl) {
141  auto ctx = createSSLContext();
142  // attach the context to the cache
143  if (cache) {
145  ctx->getSSLCtx(), cache.get());
146  auto session = cache->getSSLSession(SESSION_KEY);
147  if (session) {
148  VLOG(0) << "Reusing session";
149  client.sslSession(session.release());
150  }
151  }
152  client.sslContext(ctx);
153  }
154 
155  SocketAddress addr(FLAGS_ip.c_str(), FLAGS_port);
156  VLOG(0) << "Connecting";
157  auto pipeline = client.connect(addr).get();
158  VLOG(0) << "Connected";
159  try {
160  while (true) {
161  std::string line;
162  std::getline(std::cin, line);
163  if (line == "") {
164  VLOG(0) << "End";
165  break;
166  }
167  VLOG(0) << "Sending " << line;
168  pipeline->write(line + "\r\n").get();
169  if (line == "bye") {
170  pipeline->close();
171  break;
172  }
173  }
174  } catch (const std::exception& e) {
175  std::cout << exceptionStr(e) << std::endl;
176  }
177  return 0;
178 }
const std::string SESSION_KEY
Definition: Client.cpp:44
fbstring exceptionStr(const std::exception &e)
void BENCHFUN() getline(size_t iters, size_t arg)
void init()
Definition: Init.cpp:54
void init()
char ** argv
static void attachCallbacksToContext(SSL_CTX *ctx, SSLSessionCallbacks *callbacks)
const char * string
Definition: Conv.cpp:212
ThreadPoolListHook * addr

Variable Documentation

const std::string SESSION_KEY = "test_client"

Definition at line 44 of file Client.cpp.

Referenced by main().