proxygen
Server.cpp File Reference

Go to the source code of this file.

Typedefs

typedef Pipeline< IOBufQueue &, std::stringEchoPipeline
 

Functions

 DEFINE_string (cert_path,"","Path to cert pem")
 
 DEFINE_string (key_path,"","Path to cert key")
 
 DEFINE_string (ca_path,"","Path to trusted CA file")
 
 DEFINE_int32 (port, 8080,"Listen port")
 
 DEFINE_string (tickets_path,"","Path for ticket seeds")
 
 DEFINE_uint32 (num_workers, 2,"Number of worker threads")
 
int main (int argc, char **argv)
 

Typedef Documentation

Definition at line 46 of file Server.cpp.

Function Documentation

DEFINE_int32 ( port  ,
8080  ,
"Listen port"   
)
DEFINE_string ( cert_path  ,
""  ,
"Path to cert pem"   
)
DEFINE_string ( key_path  ,
""  ,
"Path to cert key"   
)
DEFINE_string ( ca_path  ,
""  ,
"Path to trusted CA file"   
)
DEFINE_string ( tickets_path  ,
""  ,
"Path for ticket seeds"   
)
DEFINE_uint32 ( num_workers  ,
,
"Number of worker threads  
)
int main ( int  argc,
char **  argv 
)

Definition at line 117 of file Server.cpp.

References wangle::ServerBootstrap< Pipeline >::acceptorConfig(), wangle::SSLContextConfig::addCertificate(), wangle::ServerSocketConfig::allowInsecureConnectionsOnSecureServer, wangle::ServerBootstrap< Pipeline >::bind(), wangle::ServerBootstrap< Pipeline >::childPipeline(), wangle::SSLContextConfig::clientCAFile, wangle::ServerBootstrap< Pipeline >::group(), folly::ssl::init(), bm::init(), wangle::ServerSocketConfig::initialTicketSeeds, wangle::SSLContextConfig::isDefault, folly::gen::move, wangle::TLSCredProcessor::processTLSTickets(), wangle::TLSCredProcessor::setCertPathsToWatch(), wangle::TLSCredProcessor::setTicketPathToWatch(), wangle::ServerSocketConfig::sslContextConfigs, and wangle::ServerBootstrap< Pipeline >::waitForStop().

117  {
118  folly::Init init(&argc, &argv);
120 
121  ServerSocketConfig cfg;
123 
125  TLSCredProcessor processor;
126 
127  if (!FLAGS_tickets_path.empty()) {
128  seeds = TLSCredProcessor::processTLSTickets(FLAGS_tickets_path);
129  if (seeds) {
130  cfg.initialTicketSeeds = *seeds;
131  // watch for changes
132  processor.setTicketPathToWatch(FLAGS_tickets_path);
133  }
134  }
135 
136  if (!FLAGS_cert_path.empty() && !FLAGS_key_path.empty()) {
137  VLOG(0) << "Configuring SSL";
138  SSLContextConfig sslCfg;
139  sslCfg.addCertificate(FLAGS_cert_path, FLAGS_key_path, "");
140  sslCfg.clientCAFile = FLAGS_ca_path;
141  sslCfg.isDefault = true;
142  cfg.sslContextConfigs.push_back(sslCfg);
143  // IMPORTANT: when allowing both plaintext and ssl on the same port,
144  // the acceptor requires 9 bytes of data to determine what kind of
145  // connection is coming in. If the client does not send 9 bytes the
146  // connection will idle out before the EchoCallback receives data.
148 
149  // reload ssl contexts when certs change
150  std::set<std::string> pathsToWatch { FLAGS_cert_path, FLAGS_key_path };
151  if (!FLAGS_ca_path.empty()) {
152  pathsToWatch.insert(FLAGS_ca_path);
153  }
154  processor.setCertPathsToWatch(std::move(pathsToWatch));
155  }
156 
157  initCredProcessorCallbacks(sb, processor);
158 
159  // workers
160  auto workers =
161  std::make_shared<folly::IOThreadPoolExecutor>(FLAGS_num_workers);
162 
163  // create a server
164  sb.acceptorConfig(cfg);
165  sb.childPipeline(std::make_shared<EchoPipelineFactory>());
166  sb.group(workers);
167 
168  sb.bind(FLAGS_port);
169  sb.waitForStop();
170  return 0;
171 }
void setTicketPathToWatch(const std::string &ticketFile)
void bind(folly::AsyncServerSocket::UniquePtr s)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void init()
Definition: Init.cpp:54
void init()
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
char ** argv
ServerBootstrap * group(std::shared_ptr< folly::IOThreadPoolExecutor > io_group)
void setCertPathsToWatch(std::set< std::string > certFiles)
void addCertificate(const std::string &certPath, const std::string &keyPath, const std::string &passwordPath)
TLSTicketKeySeeds initialTicketSeeds
ServerBootstrap * acceptorConfig(const ServerSocketConfig &accConfig)
std::vector< SSLContextConfig > sslContextConfigs