nghttpx: Rename cl_tls_session as downstream_tls_session

This commit is contained in:
Tatsuhiro Tsujikawa 2016-02-07 17:30:38 +09:00
parent 5c10534b88
commit e7de5e9f6c
3 changed files with 25 additions and 24 deletions

View File

@ -136,7 +136,7 @@ HttpDownstreamConnection::~HttpDownstreamConnection() {
auto &downstreamconf = get_config()->conn.downstream; auto &downstreamconf = get_config()->conn.downstream;
auto &addr = downstreamconf.addr_groups[group_].addrs[addr_idx_]; auto &addr = downstreamconf.addr_groups[group_].addrs[addr_idx_];
worker_->cache_cl_tls_session(&addr, session); worker_->cache_downstream_tls_session(&addr, session);
} }
} }
} }
@ -221,7 +221,7 @@ int HttpDownstreamConnection::attach_downstream(Downstream *downstream) {
SSL_set_tlsext_host_name(conn_.tls.ssl, sni_name.c_str()); SSL_set_tlsext_host_name(conn_.tls.ssl, sni_name.c_str());
} }
auto session = worker_->reuse_cl_tls_session(&addrs[i]); auto session = worker_->reuse_downstream_tls_session(&addrs[i]);
if (session) { if (session) {
SSL_set_session(conn_.tls.ssl, session); SSL_set_session(conn_.tls.ssl, session);
SSL_SESSION_free(session); SSL_SESSION_free(session);

View File

@ -73,7 +73,7 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
dconn_pool_(get_config()->conn.downstream.addr_groups.size()), dconn_pool_(get_config()->conn.downstream.addr_groups.size()),
worker_stat_(get_config()->conn.downstream.addr_groups.size()), worker_stat_(get_config()->conn.downstream.addr_groups.size()),
dgrps_(get_config()->conn.downstream.addr_groups.size()), dgrps_(get_config()->conn.downstream.addr_groups.size()),
cl_tls_session_cache_size_(0), downstream_tls_session_cache_size_(0),
loop_(loop), loop_(loop),
sv_ssl_ctx_(sv_ssl_ctx), sv_ssl_ctx_(sv_ssl_ctx),
cl_ssl_ctx_(cl_ssl_ctx), cl_ssl_ctx_(cl_ssl_ctx),
@ -118,7 +118,7 @@ Worker::~Worker() {
ev_async_stop(loop_, &w_); ev_async_stop(loop_, &w_);
ev_timer_stop(loop_, &mcpool_clear_timer_); ev_timer_stop(loop_, &mcpool_clear_timer_);
for (auto &p : cl_tls_session_cache_) { for (auto &p : downstream_tls_session_cache_) {
for (auto session : p.second) { for (auto session : p.second) {
SSL_SESSION_free(session); SSL_SESSION_free(session);
} }
@ -307,8 +307,8 @@ mruby::MRubyContext *Worker::get_mruby_context() const {
} }
#endif // HAVE_MRUBY #endif // HAVE_MRUBY
void Worker::cache_cl_tls_session(const DownstreamAddr *addr, void Worker::cache_downstream_tls_session(const DownstreamAddr *addr,
SSL_SESSION *session) { SSL_SESSION *session) {
auto &tlsconf = get_config()->tls; auto &tlsconf = get_config()->tls;
auto max = tlsconf.backend_session_cache_per_worker; auto max = tlsconf.backend_session_cache_per_worker;
@ -316,34 +316,34 @@ void Worker::cache_cl_tls_session(const DownstreamAddr *addr,
return; return;
} }
if (cl_tls_session_cache_size_ >= max) { if (downstream_tls_session_cache_size_ >= max) {
// It is implementation dependent which item is returned from // It is implementation dependent which item is returned from
// std::begin(). Probably, this depends on hash algorithm. If it // std::begin(). Probably, this depends on hash algorithm. If it
// is random fashion, then we are mostly OK. // is random fashion, then we are mostly OK.
auto it = std::begin(cl_tls_session_cache_); auto it = std::begin(downstream_tls_session_cache_);
assert(it != std::end(cl_tls_session_cache_)); assert(it != std::end(downstream_tls_session_cache_));
auto &v = (*it).second; auto &v = (*it).second;
assert(!v.empty()); assert(!v.empty());
auto sess = v.front(); auto sess = v.front();
v.pop_front(); v.pop_front();
SSL_SESSION_free(sess); SSL_SESSION_free(sess);
if (v.empty()) { if (v.empty()) {
cl_tls_session_cache_.erase(it); downstream_tls_session_cache_.erase(it);
} }
} }
auto it = cl_tls_session_cache_.find(addr); auto it = downstream_tls_session_cache_.find(addr);
if (it == std::end(cl_tls_session_cache_)) { if (it == std::end(downstream_tls_session_cache_)) {
std::tie(it, std::ignore) = std::tie(it, std::ignore) = downstream_tls_session_cache_.emplace(
cl_tls_session_cache_.emplace(addr, std::deque<SSL_SESSION *>()); addr, std::deque<SSL_SESSION *>());
} }
(*it).second.push_back(session); (*it).second.push_back(session);
++cl_tls_session_cache_size_; ++downstream_tls_session_cache_size_;
} }
SSL_SESSION *Worker::reuse_cl_tls_session(const DownstreamAddr *addr) { SSL_SESSION *Worker::reuse_downstream_tls_session(const DownstreamAddr *addr) {
auto it = cl_tls_session_cache_.find(addr); auto it = downstream_tls_session_cache_.find(addr);
if (it == std::end(cl_tls_session_cache_)) { if (it == std::end(downstream_tls_session_cache_)) {
return nullptr; return nullptr;
} }
@ -351,10 +351,10 @@ SSL_SESSION *Worker::reuse_cl_tls_session(const DownstreamAddr *addr) {
assert(!v.empty()); assert(!v.empty());
auto session = v.back(); auto session = v.back();
v.pop_back(); v.pop_back();
--cl_tls_session_cache_size_; --downstream_tls_session_cache_size_;
if (v.empty()) { if (v.empty()) {
cl_tls_session_cache_.erase(it); downstream_tls_session_cache_.erase(it);
} }
return session; return session;

View File

@ -148,12 +148,13 @@ public:
// Caches |session| which is associated to downstream address // Caches |session| which is associated to downstream address
// |addr|. The caller is responsible to increment the reference // |addr|. The caller is responsible to increment the reference
// count of |session|, since this function does not do so. // count of |session|, since this function does not do so.
void cache_cl_tls_session(const DownstreamAddr *addr, SSL_SESSION *session); void cache_downstream_tls_session(const DownstreamAddr *addr,
SSL_SESSION *session);
// Returns cached session associated |addr|. If non-nullptr value // Returns cached session associated |addr|. If non-nullptr value
// is returned, its cache entry was successfully removed from cache. // is returned, its cache entry was successfully removed from cache.
// If no cache entry is found associated to |addr|, nullptr will be // If no cache entry is found associated to |addr|, nullptr will be
// returned. // returned.
SSL_SESSION *reuse_cl_tls_session(const DownstreamAddr *addr); SSL_SESSION *reuse_downstream_tls_session(const DownstreamAddr *addr);
private: private:
#ifndef NOTHREADS #ifndef NOTHREADS
@ -175,8 +176,8 @@ private:
// When doing eviction due to storage limitation, the SSL_SESSION // When doing eviction due to storage limitation, the SSL_SESSION
// which sits at the front of deque is removed. // which sits at the front of deque is removed.
std::unordered_map<const DownstreamAddr *, std::deque<SSL_SESSION *>> std::unordered_map<const DownstreamAddr *, std::deque<SSL_SESSION *>>
cl_tls_session_cache_; downstream_tls_session_cache_;
size_t cl_tls_session_cache_size_; size_t downstream_tls_session_cache_size_;
std::unique_ptr<MemcachedDispatcher> session_cache_memcached_dispatcher_; std::unique_ptr<MemcachedDispatcher> session_cache_memcached_dispatcher_;
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY