GRPC Core  9.0.0
ssl_session_cache.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_CACHE_H
20 #define GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_CACHE_H
21 
23 
25 
26 #include <grpc/slice.h>
27 #include <grpc/support/sync.h>
28 
29 extern "C" {
30 #include <openssl/ssl.h>
31 }
32 
33 #include "src/core/lib/avl/avl.h"
37 
46 
47 namespace tsi {
48 
49 class SslSessionLRUCache : public grpc_core::RefCounted<SslSessionLRUCache> {
50  public:
53  return grpc_core::MakeRefCounted<SslSessionLRUCache>(capacity);
54  }
55 
56  // Use Create function instead of using this directly.
57  explicit SslSessionLRUCache(size_t capacity);
59 
60  // Not copyable nor movable.
63 
65  size_t Size();
68  void Put(const char* key, SslSessionPtr session);
71  SslSessionPtr Get(const char* key);
72 
73  private:
74  class Node;
75 
76  Node* FindLocked(const grpc_slice& key);
77  void Remove(Node* node);
78  void PushFront(Node* node);
79  void AssertInvariants();
80 
81  gpr_mu lock_;
82  size_t capacity_;
83 
84  Node* use_order_list_head_ = nullptr;
85  Node* use_order_list_tail_ = nullptr;
86  size_t use_order_list_size_ = 0;
87  grpc_avl entry_by_key_;
88 };
89 
90 } // namespace tsi
91 
92 #endif /* GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_CACHE_H */
tsi::SslSessionLRUCache::SslSessionLRUCache
SslSessionLRUCache(const SslSessionLRUCache &)=delete
avl.h
grpc_core::RefCounted
Definition: ref_counted.h:248
tsi::SslSessionLRUCache::Create
static grpc_core::RefCountedPtr< SslSessionLRUCache > Create(size_t capacity)
Create new LRU cache with the given capacity.
Definition: ssl_session_cache.h:52
tsi::SslSessionLRUCache::Get
SslSessionPtr Get(const char *key)
Returns the session from the cache associated with key or null if not found.
Definition: ssl_session_cache.cc:145
tsi::SslSessionLRUCache
Definition: ssl_session_cache.h:49
tsi::SslSessionLRUCache::Put
void Put(const char *key, SslSessionPtr session)
Add session in the cache using key.
Definition: ssl_session_cache.cc:122
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
tsi::SslSessionLRUCache::Size
size_t Size()
Returns current number of sessions in the cache.
Definition: ssl_session_cache.cc:102
tsi::SslSessionLRUCache::Node
Node for single cached session.
Definition: ssl_session_cache.cc:53
grpc_avl
"pointer" to an AVL tree - this is a reference counted object - use grpc_avl_ref to add a reference,...
Definition: avl.h:58
tsi::SslSessionPtr
std::unique_ptr< SSL_SESSION, SslSessionDeleter > SslSessionPtr
Definition: ssl_session.h:48
grpc_shadow_boringssl.h
grpc_slice
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice.h:60
tsi::SslSessionLRUCache::operator=
SslSessionLRUCache & operator=(const SslSessionLRUCache &)=delete
ref_counted.h
tsi::SslSessionLRUCache::SslSessionLRUCache
SslSessionLRUCache(size_t capacity)
Definition: ssl_session_cache.cc:85
tsi
Cache for SSL sessions for sessions resumption.
Definition: ssl_session.h:42
ssl_session.h
gpr_mu
Definition: sync_windows.h:26
slice.h
sync.h
memory.h
tsi::SslSessionLRUCache::~SslSessionLRUCache
~SslSessionLRUCache()
Definition: ssl_session_cache.cc:91
port_platform.h