This commit is contained in:
Dmitry Zuikov 2023-01-20 07:10:12 +03:00
parent f1d9513ad5
commit cea8a22e1b
2 changed files with 22 additions and 2 deletions

View File

@ -37,6 +37,24 @@ class Request e p (m :: Type -> Type) | p -> e where
request :: Peer e -> p -> m () request :: Peer e -> p -> m ()
data family SessionKey p :: Type
data family SessionData p :: Type
class ( Monad m
, HasProtocol e p
, Eq (SessionKey p)
) => Sessions e p m | p -> e where
fetch :: SessionData p -- ^ default value in case it's not found
-> SessionKey p -- ^ session key
-> (SessionData p -> a ) -- ^ modification function, i.e. lens
-> m a
update :: SessionKey p -- ^ session key
-> (SessionData p -> SessionData p) -- ^ modification function, i.e. lens
-> m ()
class (KnownNat (ProtocolId p), HasPeer e) => HasProtocol e p | p -> e where class (KnownNat (ProtocolId p), HasPeer e) => HasProtocol e p | p -> e where
type family ProtocolId p = (id :: Nat) | id -> p type family ProtocolId p = (id :: Nat) | id -> p
type family Encoded e :: Type type family Encoded e :: Type

View File

@ -67,7 +67,7 @@ data BlockDownload m =
, _sOnBlockReady :: OnBlockReady HbSync m , _sOnBlockReady :: OnBlockReady HbSync m
} }
data Sessions e m = data MySessions e m =
Sessions Sessions
{ _sBlockDownload :: Cache (Peer e, Cookie e) (BlockDownload m) { _sBlockDownload :: Cache (Peer e, Cookie e) (BlockDownload m)
, _sBlockSizes :: Cache (Hash HbSync) (Map (Peer e) Size) , _sBlockSizes :: Cache (Hash HbSync) (Map (Peer e) Size)
@ -123,7 +123,7 @@ main = do
-- ] -- ]
emptySessions :: forall e m . MonadIO m => m (Sessions e m) emptySessions :: forall e m . MonadIO m => m (MySessions e m)
emptySessions = liftIO $ emptySessions = liftIO $
Sessions <$> Cache.newCache (Just defCookieTimeout) Sessions <$> Cache.newCache (Just defCookieTimeout)
<*> Cache.newCache (Just defBlockInfoTimeout) <*> Cache.newCache (Just defBlockInfoTimeout)
@ -316,6 +316,8 @@ test1 = do
let h = fromString "81JeD7LNR6Q7RYfyWBxfjJn1RsWzvegkUXae6FUNgrMZ" let h = fromString "81JeD7LNR6Q7RYfyWBxfjJn1RsWzvegkUXae6FUNgrMZ"
-- updateSession cookie (id)
-- se <- getSession cookie (lens)
-- cookie <- newSession ??? -- cookie <- newSession ???
-- newCookie <- genCookie @Fake (p1, h) -- <<~~~ FIXME: generate a good session id! -- newCookie <- genCookie @Fake (p1, h) -- <<~~~ FIXME: generate a good session id!