mirror of https://github.com/voidlizard/hbs2
much betta
This commit is contained in:
parent
cb17fd9382
commit
88ac2021d4
|
@ -40,13 +40,11 @@ import GHC.TypeLits
|
||||||
import Lens.Micro.Platform as Lens
|
import Lens.Micro.Platform as Lens
|
||||||
import Data.HashMap.Strict (HashMap)
|
import Data.HashMap.Strict (HashMap)
|
||||||
import Data.HashMap.Strict qualified as HashMap
|
import Data.HashMap.Strict qualified as HashMap
|
||||||
-- import Control.Concurrent.STM.TVar
|
|
||||||
-- import Control.Concurrent.STM
|
|
||||||
import Control.Monad.IO.Unlift
|
import Control.Monad.IO.Unlift
|
||||||
import Data.List qualified as L
|
import Data.List qualified as L
|
||||||
import Data.Monoid qualified as Monoid
|
import Data.Monoid qualified as Monoid
|
||||||
|
|
||||||
import UnliftIO
|
import UnliftIO
|
||||||
|
import UnliftIO.Concurrent (getNumCapabilities)
|
||||||
|
|
||||||
import Codec.Serialise (serialise, deserialiseOrFail)
|
import Codec.Serialise (serialise, deserialiseOrFail)
|
||||||
|
|
||||||
|
@ -440,7 +438,9 @@ runPeerM :: forall e m . ( MonadUnliftIO m
|
||||||
|
|
||||||
runPeerM env@PeerEnv{..} f = flip runContT pure do
|
runPeerM env@PeerEnv{..} f = flip runContT pure do
|
||||||
|
|
||||||
as <- liftIO $ replicateM 16 $ async $ runPipeline _envDeferred
|
n <- liftIO getNumCapabilities <&> max 2 . div 2
|
||||||
|
|
||||||
|
as <- liftIO $ replicateM n $ async $ runPipeline _envDeferred
|
||||||
|
|
||||||
sw <- liftIO $ async $ forever $ withPeerM env $ do
|
sw <- liftIO $ async $ forever $ withPeerM env $ do
|
||||||
pause defSweepTimeout
|
pause defSweepTimeout
|
||||||
|
@ -453,12 +453,12 @@ runPeerM env@PeerEnv{..} f = flip runContT pure do
|
||||||
sweep
|
sweep
|
||||||
|
|
||||||
void $ ContT $ bracket none $ const $ do
|
void $ ContT $ bracket none $ const $ do
|
||||||
|
void $ liftIO $ stopPipeline _envDeferred
|
||||||
|
liftIO $ mapM_ cancel (as <> [sw])
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
lift $ void $ runReaderT (fromPeerM f) env
|
lift $ void $ runReaderT (fromPeerM f) env
|
||||||
|
|
||||||
void $ liftIO $ stopPipeline _envDeferred
|
|
||||||
liftIO $ mapM_ cancel (as <> [sw])
|
|
||||||
|
|
||||||
withPeerM :: MonadIO m => PeerEnv e -> PeerM e m a -> m a
|
withPeerM :: MonadIO m => PeerEnv e -> PeerM e m a -> m a
|
||||||
withPeerM env action = runReaderT (fromPeerM action) env
|
withPeerM env action = runReaderT (fromPeerM action) env
|
||||||
|
|
|
@ -645,7 +645,7 @@ downloadDispatcher brains env = flip runContT pure do
|
||||||
Just s -> pure s
|
Just s -> pure s
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
-- TODO: semaphore-hardcode
|
-- TODO: semaphore-hardcode
|
||||||
new <- TSem.newTSem 2
|
new <- TSem.newTSem 10
|
||||||
modifyTVar _psem (HM.insert nonce new)
|
modifyTVar _psem (HM.insert nonce new)
|
||||||
pure new
|
pure new
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,7 @@ import UnliftIO (MonadUnliftIO(..))
|
||||||
import UnliftIO.Exception qualified as U
|
import UnliftIO.Exception qualified as U
|
||||||
-- import UnliftIO.STM
|
-- import UnliftIO.STM
|
||||||
import UnliftIO.Async
|
import UnliftIO.Async
|
||||||
|
import UnliftIO.Concurrent (getNumCapabilities)
|
||||||
|
|
||||||
import Streaming.Prelude qualified as S
|
import Streaming.Prelude qualified as S
|
||||||
|
|
||||||
|
@ -812,7 +813,9 @@ runPeer opts = respawnOnError opts $ do
|
||||||
simpleStorageSetProbe s stoProbe
|
simpleStorageSetProbe s stoProbe
|
||||||
addProbe stoProbe
|
addProbe stoProbe
|
||||||
|
|
||||||
w <- replicateM defStorageThreads $ async $ liftIO $ simpleStorageWorker s
|
stn <- getNumCapabilities <&> max 2 . div 4
|
||||||
|
|
||||||
|
w <- replicateM 2 $ async $ liftIO $ simpleStorageWorker s
|
||||||
|
|
||||||
localMulticast <- liftIO $ (headMay <$> parseAddrUDP (fromString defLocalMulticast)
|
localMulticast <- liftIO $ (headMay <$> parseAddrUDP (fromString defLocalMulticast)
|
||||||
<&> fmap (fromSockAddr @'UDP . addrAddress) )
|
<&> fmap (fromSockAddr @'UDP . addrAddress) )
|
||||||
|
|
|
@ -76,7 +76,6 @@ import UnliftIO.Concurrent
|
||||||
import Lens.Micro.Platform
|
import Lens.Micro.Platform
|
||||||
import Streaming.Prelude qualified as S
|
import Streaming.Prelude qualified as S
|
||||||
|
|
||||||
|
|
||||||
instance (e ~ L4Proto, MonadUnliftIO m, HasRpcContext PeerAPI RPC2Context m) => HandleMethod m RpcRunScript where
|
instance (e ~ L4Proto, MonadUnliftIO m, HasRpcContext PeerAPI RPC2Context m) => HandleMethod m RpcRunScript where
|
||||||
handleMethod top = do
|
handleMethod top = do
|
||||||
|
|
||||||
|
@ -94,6 +93,10 @@ instance (e ~ L4Proto, MonadUnliftIO m, HasRpcContext PeerAPI RPC2Context m) =>
|
||||||
entry $ bindMatch "hey" $ const do
|
entry $ bindMatch "hey" $ const do
|
||||||
pure $ mkSym @C "hey"
|
pure $ mkSym @C "hey"
|
||||||
|
|
||||||
|
entry $ bindMatch "system:capabilities" $ const $ do
|
||||||
|
n <- getNumCapabilities
|
||||||
|
pure $ mkForm "capabilities" [mkInt n]
|
||||||
|
|
||||||
entry $ bindMatch "tcp:peer:kick" $ \case
|
entry $ bindMatch "tcp:peer:kick" $ \case
|
||||||
[ StringLike addr ] -> flip runContT pure $ callCC \exit -> do
|
[ StringLike addr ] -> flip runContT pure $ callCC \exit -> do
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue