From 2da7ea122a62bd9469707bf73ce195ac27f96c51 Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Fri, 13 Jan 2023 11:18:51 +0300 Subject: [PATCH] wip --- hbs2-core/hbs2-core.cabal | 4 +- hbs2-core/lib/HBS2/Actors.hs | 5 +++ hbs2-core/lib/HBS2/Net/Proto.hs | 7 ++++ .../lib/HBS2/Net/Proto/Actors/BlockInfo.hs | 40 +++++++++++++++++-- hbs2-core/lib/HBS2/Prelude.hs | 4 +- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 hbs2-core/lib/HBS2/Actors.hs diff --git a/hbs2-core/hbs2-core.cabal b/hbs2-core/hbs2-core.cabal index d6912eee..d9a15ca0 100644 --- a/hbs2-core/hbs2-core.cabal +++ b/hbs2-core/hbs2-core.cabal @@ -64,7 +64,8 @@ library import: shared-properties exposed-modules: - HBS2.Clock + HBS2.Actors + , HBS2.Clock , HBS2.Data.Types , HBS2.Data.Types.Refs , HBS2.Defaults @@ -101,6 +102,7 @@ library , safe , serialise , stm + , stm-chans , text , uniplate diff --git a/hbs2-core/lib/HBS2/Actors.hs b/hbs2-core/lib/HBS2/Actors.hs new file mode 100644 index 00000000..f207d567 --- /dev/null +++ b/hbs2-core/lib/HBS2/Actors.hs @@ -0,0 +1,5 @@ +module HBS2.Actors where + + + + diff --git a/hbs2-core/lib/HBS2/Net/Proto.hs b/hbs2-core/lib/HBS2/Net/Proto.hs index 455b5171..05479ec2 100644 --- a/hbs2-core/lib/HBS2/Net/Proto.hs +++ b/hbs2-core/lib/HBS2/Net/Proto.hs @@ -1,8 +1,15 @@ module HBS2.Net.Proto where +import HBS2.Prelude.Plated + import Data.Kind import Data.Hashable class (Hashable (Peer a), Eq (Peer a)) => IsPeer a where data family Peer a :: Type + +newtype BlockInfo = BlockInfo Integer + deriving stock (Eq, Data) + + diff --git a/hbs2-core/lib/HBS2/Net/Proto/Actors/BlockInfo.hs b/hbs2-core/lib/HBS2/Net/Proto/Actors/BlockInfo.hs index 98008848..204327e8 100644 --- a/hbs2-core/lib/HBS2/Net/Proto/Actors/BlockInfo.hs +++ b/hbs2-core/lib/HBS2/Net/Proto/Actors/BlockInfo.hs @@ -2,11 +2,24 @@ module HBS2.Net.Proto.Actors.BlockInfo where import HBS2.Prelude import HBS2.Hash +import HBS2.Net.Proto +import HBS2.Clock + +import Data.Function +import Control.Concurrent.STM.TBMQueue (TBMQueue) +import Control.Concurrent.STM.TBMQueue qualified as TBMQ +import Control.Concurrent.STM -- needs: logger -- needs: reader and shit -- needs: messaging -newtype BlockInfoActor = BlockInfoActor () +-- needs: cookie manager +-- needs: peer manager + +data BlockInfoActor = + BlockInfoActor + { tasks :: TBMQueue (IO ()) + } -- TODO: send block info request @@ -17,10 +30,29 @@ newtype BlockInfoActor = BlockInfoActor () createBlockInfoActor :: MonadIO m => m BlockInfoActor createBlockInfoActor = do - pure $ BlockInfoActor () + qtask <- liftIO $ atomically $ TBMQ.newTBMQueue 500 -- FIXME: settings + pure $ BlockInfoActor undefined -sendBlockInfoRequest :: MonadIO m => BlockInfoActor -> Hash h -> m () -sendBlockInfoRequest b h = do +runBlockInfoActor :: MonadIO m => BlockInfoActor -> m () +runBlockInfoActor _ = + fix \next -> do + pause (1 :: Timeout 'Seconds) + next + +requestBlockInfo :: MonadIO m + => BlockInfoActor + -> Maybe (Peer peer) + -> Hash h + -> m () + +requestBlockInfo b h = do undefined +getBlockInfo :: MonadIO m + => BlockInfoActor + -> Maybe (Peer peer) + -> m (Maybe BlockInfo) + +getBlockInfo _ _ = undefined + diff --git a/hbs2-core/lib/HBS2/Prelude.hs b/hbs2-core/lib/HBS2/Prelude.hs index 64f3ea78..13683cb4 100644 --- a/hbs2-core/lib/HBS2/Prelude.hs +++ b/hbs2-core/lib/HBS2/Prelude.hs @@ -1,13 +1,13 @@ module HBS2.Prelude ( module Data.String , module Safe - , MonadIO + , MonadIO(..) -- , module HBS2.Prelude ) where import Data.String (IsString(..)) import Safe -import Control.Monad.IO.Class (MonadIO) +import Control.Monad.IO.Class (MonadIO(..))