{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
module Network.QUIC.Config where
import Data.Default.Class
import Data.IP
import Network.Socket
import Network.TLS hiding (Hooks, HostName, Version)
import Network.TLS.QUIC
import Network.QUIC.Imports
import Network.QUIC.Parameters
import Network.QUIC.Stream
import Network.QUIC.Types
data Hooks = Hooks
{ Hooks -> IO ()
onCloseCompleted :: IO ()
, Hooks -> EncryptionLevel -> Plain -> Plain
onPlainCreated :: EncryptionLevel -> Plain -> Plain
, Hooks -> Parameters -> Parameters
onTransportParametersCreated :: Parameters -> Parameters
, Hooks -> [ExtensionRaw] -> [ExtensionRaw]
onTLSExtensionCreated :: [ExtensionRaw] -> [ExtensionRaw]
, Hooks
-> [(EncryptionLevel, CryptoData)]
-> ([(EncryptionLevel, CryptoData)], Bool)
onTLSHandshakeCreated
:: [(EncryptionLevel, CryptoData)]
-> ([(EncryptionLevel, CryptoData)], Bool)
, Hooks -> Stream -> ApplicationProtocolError -> IO ()
onResetStreamReceived :: Stream -> ApplicationProtocolError -> IO ()
, Hooks -> IO ()
onServerReady :: IO ()
}
defaultHooks :: Hooks
defaultHooks :: Hooks
defaultHooks =
Hooks
{ onCloseCompleted :: IO ()
onCloseCompleted = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
, onPlainCreated :: EncryptionLevel -> Plain -> Plain
onPlainCreated = \EncryptionLevel
_l Plain
p -> Plain
p
, onTransportParametersCreated :: Parameters -> Parameters
onTransportParametersCreated = Parameters -> Parameters
forall a. a -> a
id
, onTLSExtensionCreated :: [ExtensionRaw] -> [ExtensionRaw]
onTLSExtensionCreated = [ExtensionRaw] -> [ExtensionRaw]
forall a. a -> a
id
, onTLSHandshakeCreated :: [(EncryptionLevel, CryptoData)]
-> ([(EncryptionLevel, CryptoData)], Bool)
onTLSHandshakeCreated = (,Bool
False)
, onResetStreamReceived :: Stream -> ApplicationProtocolError -> IO ()
onResetStreamReceived = \Stream
_ ApplicationProtocolError
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
, onServerReady :: IO ()
onServerReady = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
}
data ClientConfig = ClientConfig
{ ClientConfig -> [Version]
ccVersions :: [Version]
, ClientConfig -> [Cipher]
ccCiphers :: [Cipher]
, ClientConfig -> [Group]
ccGroups :: [Group]
, ClientConfig -> Parameters
ccParameters :: Parameters
, ClientConfig -> String -> IO ()
ccKeyLog :: String -> IO ()
, ClientConfig -> Maybe String
ccQLog :: Maybe FilePath
, ClientConfig -> Credentials
ccCredentials :: Credentials
, ClientConfig -> Hooks
ccHooks :: Hooks
, ClientConfig -> ClientHooks
ccTlsHooks :: ClientHooks
, ClientConfig -> Bool
ccUse0RTT :: Bool
, ClientConfig -> String
ccServerName :: HostName
, ClientConfig -> String
ccPortName :: ServiceName
, ClientConfig -> Version -> IO (Maybe [CryptoData])
ccALPN :: Version -> IO (Maybe [ByteString])
, ClientConfig -> Bool
ccValidate :: Bool
, ClientConfig -> ResumptionInfo
ccResumption :: ResumptionInfo
, ClientConfig -> Maybe Int
ccPacketSize :: Maybe Int
, ClientConfig -> Bool
ccDebugLog :: Bool
, ClientConfig -> Bool
ccAutoMigration :: Bool
}
defaultClientConfig :: ClientConfig
defaultClientConfig :: ClientConfig
defaultClientConfig =
ClientConfig
{ ccVersions :: [Version]
ccVersions = [Version
Version2, Version
Version1]
, ccCiphers :: [Cipher]
ccCiphers = Supported -> [Cipher]
supportedCiphers Supported
defaultSupported
, ccGroups :: [Group]
ccGroups = Supported -> [Group]
supportedGroups Supported
defaultSupported
, ccParameters :: Parameters
ccParameters = Parameters
defaultParameters
, ccKeyLog :: String -> IO ()
ccKeyLog = \String
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
, ccQLog :: Maybe String
ccQLog = Maybe String
forall a. Maybe a
Nothing
, ccCredentials :: Credentials
ccCredentials = Credentials
forall a. Monoid a => a
mempty
, ccHooks :: Hooks
ccHooks = Hooks
defaultHooks
, ccTlsHooks :: ClientHooks
ccTlsHooks = ClientHooks
forall a. Default a => a
def
, ccUse0RTT :: Bool
ccUse0RTT = Bool
False
,
ccServerName :: String
ccServerName = String
"127.0.0.1"
, ccPortName :: String
ccPortName = String
"4433"
, ccALPN :: Version -> IO (Maybe [CryptoData])
ccALPN = \Version
_ -> Maybe [CryptoData] -> IO (Maybe [CryptoData])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe [CryptoData]
forall a. Maybe a
Nothing
, ccValidate :: Bool
ccValidate = Bool
True
, ccResumption :: ResumptionInfo
ccResumption = ResumptionInfo
defaultResumptionInfo
, ccPacketSize :: Maybe Int
ccPacketSize = Maybe Int
forall a. Maybe a
Nothing
, ccDebugLog :: Bool
ccDebugLog = Bool
False
, ccAutoMigration :: Bool
ccAutoMigration = Bool
True
}
data ServerConfig = ServerConfig
{ ServerConfig -> [Version]
scVersions :: [Version]
, ServerConfig -> [Cipher]
scCiphers :: [Cipher]
, ServerConfig -> [Group]
scGroups :: [Group]
, ServerConfig -> Parameters
scParameters :: Parameters
, ServerConfig -> String -> IO ()
scKeyLog :: String -> IO ()
, ServerConfig -> Maybe String
scQLog :: Maybe FilePath
, ServerConfig -> Credentials
scCredentials :: Credentials
, ServerConfig -> Hooks
scHooks :: Hooks
, ServerConfig -> ServerHooks
scTlsHooks :: ServerHooks
, ServerConfig -> Bool
scUse0RTT :: Bool
, ServerConfig -> [(IP, PortNumber)]
scAddresses :: [(IP, PortNumber)]
, ServerConfig -> Maybe (Version -> [CryptoData] -> IO CryptoData)
scALPN :: Maybe (Version -> [ByteString] -> IO ByteString)
, ServerConfig -> Bool
scRequireRetry :: Bool
, ServerConfig -> SessionManager
scSessionManager :: SessionManager
, ServerConfig -> Maybe String
scDebugLog :: Maybe FilePath
, ServerConfig -> Int
scTicketLifetime :: Int
}
defaultServerConfig :: ServerConfig
defaultServerConfig :: ServerConfig
defaultServerConfig =
ServerConfig
{ scVersions :: [Version]
scVersions = [Version
Version2, Version
Version1]
, scCiphers :: [Cipher]
scCiphers = Supported -> [Cipher]
supportedCiphers Supported
defaultSupported
, scGroups :: [Group]
scGroups = Supported -> [Group]
supportedGroups Supported
defaultSupported
, scParameters :: Parameters
scParameters = Parameters
defaultParameters
, scKeyLog :: String -> IO ()
scKeyLog = \String
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
, scQLog :: Maybe String
scQLog = Maybe String
forall a. Maybe a
Nothing
, scCredentials :: Credentials
scCredentials = Credentials
forall a. Monoid a => a
mempty
, scHooks :: Hooks
scHooks = Hooks
defaultHooks
, scTlsHooks :: ServerHooks
scTlsHooks = ServerHooks
forall a. Default a => a
def
, scUse0RTT :: Bool
scUse0RTT = Bool
False
,
scAddresses :: [(IP, PortNumber)]
scAddresses = [(IP
"0.0.0.0", PortNumber
4433), (IP
"::", PortNumber
4433)]
, scALPN :: Maybe (Version -> [CryptoData] -> IO CryptoData)
scALPN = Maybe (Version -> [CryptoData] -> IO CryptoData)
forall a. Maybe a
Nothing
, scRequireRetry :: Bool
scRequireRetry = Bool
False
, scSessionManager :: SessionManager
scSessionManager = SessionManager
noSessionManager
, scDebugLog :: Maybe String
scDebugLog = Maybe String
forall a. Maybe a
Nothing
, scTicketLifetime :: Int
scTicketLifetime = Int
7200
}