mirror of https://github.com/voidlizard/hbs2
wip, mailbox SendMessage skeleton
This commit is contained in:
parent
172e180d0e
commit
c31c2c04c6
|
@ -25,24 +25,36 @@ import PeerTypes
|
|||
|
||||
import Control.Monad
|
||||
import UnliftIO
|
||||
-- import Control.Concurrent.STM.TBQueue
|
||||
import Lens.Micro.Platform
|
||||
|
||||
{- HLINT ignore "Functor law" -}
|
||||
|
||||
data MailboxProtoWorker e =
|
||||
data MailboxProtoWorker (s :: CryptoScheme) e =
|
||||
MailboxProtoWorker
|
||||
{
|
||||
{ mpwStorage :: AnyStorage
|
||||
, inMessageQueue :: TBQueue (Message s, MessageContent s)
|
||||
, inMessageQueueDropped :: TVar Int
|
||||
}
|
||||
|
||||
instance IsMailboxProtoAdapter 'HBS2Basic (MailboxProtoWorker e) where
|
||||
mailboxGetStorage = const $ error "OOPSIE"
|
||||
instance (s ~ HBS2Basic) => IsMailboxProtoAdapter s (MailboxProtoWorker s e) where
|
||||
mailboxGetStorage = pure . mpwStorage
|
||||
|
||||
mailboxAcceptMessage _ _ _ = do
|
||||
error "DOOPSIE"
|
||||
mailboxAcceptMessage MailboxProtoWorker{..} m c = do
|
||||
atomically do
|
||||
full <- isFullTBQueue inMessageQueue
|
||||
if full then do
|
||||
modifyTVar inMessageQueueDropped succ
|
||||
else do
|
||||
writeTBQueue inMessageQueue (m,c)
|
||||
|
||||
createMailboxProtoWorker :: forall e m . MonadIO m => m (MailboxProtoWorker e)
|
||||
createMailboxProtoWorker = do
|
||||
pure MailboxProtoWorker
|
||||
createMailboxProtoWorker :: forall e m . MonadIO m => AnyStorage -> m (MailboxProtoWorker (Encryption e) e)
|
||||
createMailboxProtoWorker sto = do
|
||||
-- FIXME: queue-size-hardcode
|
||||
-- $class: hardcode
|
||||
inQ <- newTBQueueIO 1000
|
||||
inDroppped <- newTVarIO 0
|
||||
pure $ MailboxProtoWorker sto inQ inDroppped
|
||||
|
||||
mailboxProtoWorker :: forall e s m . ( MonadIO m
|
||||
, MonadUnliftIO m
|
||||
|
@ -54,7 +66,7 @@ mailboxProtoWorker :: forall e s m . ( MonadIO m
|
|||
, s ~ Encryption e
|
||||
, IsRefPubKey s
|
||||
)
|
||||
=> MailboxProtoWorker e
|
||||
=> MailboxProtoWorker s e
|
||||
-> m ()
|
||||
|
||||
mailboxProtoWorker me = do
|
||||
|
@ -71,5 +83,3 @@ mailboxProtoWorker me = do
|
|||
-- gossip (LWWRefProto1 @e (LWWProtoGet (LWWRefKey ref)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1106,7 +1106,7 @@ runPeer opts = Exception.handle (\e -> myException e
|
|||
|
||||
peerThread "lwwRefWorker" (lwwRefWorker @e conf (SomeBrains brains))
|
||||
|
||||
mbw <- createMailboxProtoWorker @e
|
||||
mbw <- createMailboxProtoWorker @e (AnyStorage s)
|
||||
peerThread "mailboxProtoWorker" (mailboxProtoWorker mbw)
|
||||
|
||||
liftIO $ withPeerM penv do
|
||||
|
|
|
@ -134,6 +134,7 @@ mailboxProto adapter mess = do
|
|||
gossip mess
|
||||
mailboxAcceptMessage adapter msg content
|
||||
-- TODO: expire-block-and-collect-garbage
|
||||
-- $class: leak
|
||||
void $ putBlock sto routed
|
||||
|
||||
CheckMailbox{} -> do
|
||||
|
|
Loading…
Reference in New Issue