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 
24 #include <map>
25 
26 #include <openssl/ssl.h>
27 
28 #include <grpc/slice.h>
29 #include <grpc/support/sync.h>
30 
35 
44 
45 namespace tsi {
46 
47 class SslSessionLRUCache : public grpc_core::RefCounted<SslSessionLRUCache> {
48  public:
51  return grpc_core::MakeRefCounted<SslSessionLRUCache>(capacity);
52  }
53 
54  // Use Create function instead of using this directly.
55  explicit SslSessionLRUCache(size_t capacity);
56  ~SslSessionLRUCache() override;
57 
58  // Not copyable nor movable.
59  SslSessionLRUCache(const SslSessionLRUCache&) = delete;
61 
63  size_t Size();
66  void Put(const char* key, SslSessionPtr session);
69  SslSessionPtr Get(const char* key);
70 
71  private:
72  class Node;
73 
74  Node* FindLocked(const std::string& key);
75  void Remove(Node* node);
76  void PushFront(Node* node);
77  void AssertInvariants();
78 
80  size_t capacity_;
81 
85  std::map<std::string, Node*> entry_by_key_;
86 };
87 
88 } // namespace tsi
89 
90 #endif /* GRPC_CORE_TSI_SSL_SESSION_CACHE_SSL_SESSION_CACHE_H */
tsi::SslSessionLRUCache::PushFront
void PushFront(Node *node)
Definition: ssl_session_cache.cc:142
tsi::SslSessionLRUCache::use_order_list_head_
Node * use_order_list_head_
Definition: ssl_session_cache.h:82
tsi::SslSessionLRUCache::AssertInvariants
void AssertInvariants()
Definition: ssl_session_cache.cc:158
tsi::SslSessionLRUCache::Get
SslSessionPtr Get(const char *key)
Definition: ssl_session_cache.cc:117
opencensus.proto.agent.common.v1.common_pb2.Node
Node
Definition: common_pb2.py:308
tsi::SslSessionLRUCache
Definition: ssl_session_cache.h:47
slice.h
capacity
uint16_t capacity
Definition: protobuf/src/google/protobuf/descriptor.cc:948
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
tsi::SslSessionLRUCache::SslSessionLRUCache
SslSessionLRUCache(size_t capacity)
Definition: ssl_session_cache.cc:63
memory.h
tsi::SslSessionLRUCache::entry_by_key_
std::map< std::string, Node * > entry_by_key_
Definition: ssl_session_cache.h:85
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
tsi::SslSessionPtr
std::unique_ptr< SSL_SESSION, SslSessionDeleter > SslSessionPtr
Definition: ssl_session.h:46
tsi::SslSessionLRUCache::capacity_
size_t capacity_
Definition: ssl_session_cache.h:80
tsi::SslSessionLRUCache::operator=
SslSessionLRUCache & operator=(const SslSessionLRUCache &)=delete
tsi::SslSessionLRUCache::Remove
void Remove(Node *node)
Definition: ssl_session_cache.cc:127
grpc_core::RefCounted
Definition: ref_counted.h:280
tsi::SslSessionLRUCache::~SslSessionLRUCache
~SslSessionLRUCache() override
Definition: ssl_session_cache.cc:67
tsi::SslSessionLRUCache::lock_
grpc_core::Mutex lock_
Definition: ssl_session_cache.h:79
tsi::SslSessionLRUCache::Node
Node for single cached session.
Definition: ssl_session_cache.cc:33
ssl.h
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
tsi::SslSessionLRUCache::Put
void Put(const char *key, SslSessionPtr session)
Definition: ssl_session_cache.cc:95
key
const char * key
Definition: hpack_parser_table.cc:164
ref_counted.h
tsi
Definition: ssl_key_logging.cc:29
tsi::SslSessionLRUCache::use_order_list_size_
size_t use_order_list_size_
Definition: ssl_session_cache.h:84
tsi::SslSessionLRUCache::FindLocked
Node * FindLocked(const std::string &key)
Definition: ssl_session_cache.cc:81
ssl_session.h
tsi::SslSessionLRUCache::use_order_list_tail_
Node * use_order_list_tail_
Definition: ssl_session_cache.h:83
tsi::SslSessionLRUCache::Size
size_t Size()
Returns current number of sessions in the cache.
Definition: ssl_session_cache.cc:76
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:50
sync.h
sync.h
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:21