<commit_before>{-# LANGUAGE BangPatterns #-}

-- | In-memory TLS session manager.
--
-- * Limitation: you can set the maximum size of the session data database.
-- * Automatic pruning: old session data over their lifetime are pruned automatically.
-- * Replay resistance: each session data is used at most once to prevent replay attacks.
-- * Energy saving: no dedicate pruning thread is running when the size of session database is zero.

module Network.TLS.SessionManager (
    Config(..)
  , defaultConfig
  , newSessionManager
  ) where

import Control.Reaper
import Data.IORef
import Data.List (foldl')
import Data.OrdPSQ (OrdPSQ)
import qualified Data.OrdPSQ as Q
import Data.Time (UTCTime, NominalDiffTime, getCurrentTime, addUTCTime)
import Network.TLS (SessionID, SessionData, SessionManager(..))

----------------------------------------------------------------

-- | Configuration for session managers.
data Config = Config {
    -- | Ticket lifetime in seconds.
      ticketLifetime :: !Int
    -- | Pruning delay in seconds. This is set to 'reaperDelay'.
    , pruningDelay   :: !Int<commit_msg>updating doc.<commit_after>{-# LANGUAGE BangPatterns #-}

-- | In-memory TLS session manager.
--
-- * Limitation: you can set the maximum size of the session data database.
-- * Automatic pruning: old session data over their lifetime are pruned automatically.
-- * Energy saving: no dedicate pruning thread is running when the size of session data database is zero.
-- * (Replay resistance: each session data is used at most once to prevent replay attacks against 0RTT early data of TLS 1.3.)

module Network.TLS.SessionManager (
    Config(..)
  , defaultConfig
  , newSessionManager
  ) where

import Control.Reaper
import Data.IORef
import Data.List (foldl')
import Data.OrdPSQ (OrdPSQ)
import qualified Data.OrdPSQ as Q
import Data.Time (UTCTime, NominalDiffTime, getCurrentTime, addUTCTime)
import Network.TLS (SessionID, SessionData, SessionManager(..))

----------------------------------------------------------------

-- | Configuration for session managers.
data Config = Config {
    -- | Ticket lifetime in seconds.
      ticketLifetime :: !Int
    -- | Pruning delay in seconds. This is set to 'reaperDelay'.
    , pruningDelay   :: !Int
{'fraction_non_alphanumeric': 0.14260407440212577, 'fraction_numerical': 0.001328609388839681, 'mean_word_length': 2.881443298969072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2973930', 'n_tokens_mistral': 615, 'n_tokens_neox': 601, 'n_words': 240}