nghttpx: Use Address* as a key for client side session cache
This commit is contained in:
parent
396dde1347
commit
00175eac33
|
@ -133,7 +133,7 @@ HttpDownstreamConnection::~HttpDownstreamConnection() {
|
||||||
if (conn_.tls.ssl) {
|
if (conn_.tls.ssl) {
|
||||||
auto session = SSL_get1_session(conn_.tls.ssl);
|
auto session = SSL_get1_session(conn_.tls.ssl);
|
||||||
if (session) {
|
if (session) {
|
||||||
worker_->cache_downstream_tls_session(addr_, session);
|
worker_->cache_downstream_tls_session(&addr_->addr, session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,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_downstream_tls_session(addr_);
|
auto session = worker_->reuse_downstream_tls_session(&addr_->addr);
|
||||||
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);
|
||||||
|
|
|
@ -307,7 +307,7 @@ mruby::MRubyContext *Worker::get_mruby_context() const {
|
||||||
}
|
}
|
||||||
#endif // HAVE_MRUBY
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
void Worker::cache_downstream_tls_session(const DownstreamAddr *addr,
|
void Worker::cache_downstream_tls_session(const Address *addr,
|
||||||
SSL_SESSION *session) {
|
SSL_SESSION *session) {
|
||||||
auto &tlsconf = get_config()->tls;
|
auto &tlsconf = get_config()->tls;
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ void Worker::cache_downstream_tls_session(const DownstreamAddr *addr,
|
||||||
++downstream_tls_session_cache_size_;
|
++downstream_tls_session_cache_size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_SESSION *Worker::reuse_downstream_tls_session(const DownstreamAddr *addr) {
|
SSL_SESSION *Worker::reuse_downstream_tls_session(const Address *addr) {
|
||||||
auto it = downstream_tls_session_cache_.find(addr);
|
auto it = downstream_tls_session_cache_.find(addr);
|
||||||
if (it == std::end(downstream_tls_session_cache_)) {
|
if (it == std::end(downstream_tls_session_cache_)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -145,16 +145,15 @@ public:
|
||||||
mruby::MRubyContext *get_mruby_context() const;
|
mruby::MRubyContext *get_mruby_context() const;
|
||||||
#endif // HAVE_MRUBY
|
#endif // HAVE_MRUBY
|
||||||
|
|
||||||
// Caches |session| which is associated to downstream address
|
// Caches |session| which is associated to remote address |addr|.
|
||||||
// |addr|. The caller is responsible to increment the reference
|
// The caller is responsible to increment the reference count of
|
||||||
// count of |session|, since this function does not do so.
|
// |session|, since this function does not do so.
|
||||||
void cache_downstream_tls_session(const DownstreamAddr *addr,
|
void cache_downstream_tls_session(const Address *addr, SSL_SESSION *session);
|
||||||
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_downstream_tls_session(const DownstreamAddr *addr);
|
SSL_SESSION *reuse_downstream_tls_session(const Address *addr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef NOTHREADS
|
#ifndef NOTHREADS
|
||||||
|
@ -170,12 +169,12 @@ private:
|
||||||
WorkerStat worker_stat_;
|
WorkerStat worker_stat_;
|
||||||
std::vector<DownstreamGroup> dgrps_;
|
std::vector<DownstreamGroup> dgrps_;
|
||||||
|
|
||||||
// Cache for SSL_SESSION for downstream connections. SSL_SESSION is
|
// Client side SSL_SESSION cache. SSL_SESSION is associated to
|
||||||
// associated to downstream address. One address has multiple
|
// remote address. One address has multiple SSL_SESSION objects.
|
||||||
// SSL_SESSION objects. New SSL_SESSION is appended to the deque.
|
// New SSL_SESSION is appended to the deque. When doing eviction
|
||||||
// When doing eviction due to storage limitation, the SSL_SESSION
|
// due to storage limitation, the SSL_SESSION which sits at the
|
||||||
// which sits at the front of deque is removed.
|
// front of deque is removed.
|
||||||
std::unordered_map<const DownstreamAddr *, std::deque<SSL_SESSION *>>
|
std::unordered_map<const Address *, std::deque<SSL_SESSION *>>
|
||||||
downstream_tls_session_cache_;
|
downstream_tls_session_cache_;
|
||||||
size_t downstream_tls_session_cache_size_;
|
size_t downstream_tls_session_cache_size_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue