From dd310888a579026fcda4d376f600a86d9dc36465 Mon Sep 17 00:00:00 2001 From: voidlizard Date: Sat, 15 Feb 2025 13:48:16 +0300 Subject: [PATCH] wip, rpc issue fix? --- .../HBS2/Net/Messaging/Encrypted/ByPass.hs | 27 ++++++++++--------- hbs2-core/lib/HBS2/Net/Proto/Service.hs | 8 ++++-- hbs2-peer/app/PeerMain.hs | 5 ++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/hbs2-core/lib/HBS2/Net/Messaging/Encrypted/ByPass.hs b/hbs2-core/lib/HBS2/Net/Messaging/Encrypted/ByPass.hs index d245546e..b76e5e14 100644 --- a/hbs2-core/lib/HBS2/Net/Messaging/Encrypted/ByPass.hs +++ b/hbs2-core/lib/HBS2/Net/Messaging/Encrypted/ByPass.hs @@ -158,19 +158,20 @@ getStat :: forall e w m . ( ForByPass e ) => ByPass e w -> m ByPassStat -getStat bus = liftIO $ - ByPassStat <$> readTVarIO (bypassed bus) - <*> readTVarIO (encrypted bus) - <*> readTVarIO (decrypted bus) - <*> readTVarIO (decryptFails bus) - <*> readTVarIO (sentNum bus) - <*> readTVarIO (recvNum bus) - <*> readTVarIO (sentBytes bus) - <*> readTVarIO (recvBytes bus) - <*> (readTVarIO (flowKeys bus) <&> HashMap.size) - <*> (readTVarIO (noncesByPeer bus) <&> HashMap.size) - <*> readTVarIO (authFail bus) - <*> readTVarIO (maxPkt bus) +getStat ByPass{..} = liftIO do + atomically do + ByPassStat <$> readTVar bypassed + <*> readTVar encrypted + <*> readTVar decrypted + <*> readTVar decryptFails + <*> readTVar sentNum + <*> readTVar recvNum + <*> readTVar sentBytes + <*> readTVar recvBytes + <*> (readTVar flowKeys <&> HashMap.size) + <*> (readTVar noncesByPeer <&> HashMap.size) + <*> readTVar authFail + <*> readTVar maxPkt cleanupByPassMessaging :: forall e w m . ( ForByPass e , MonadIO m diff --git a/hbs2-core/lib/HBS2/Net/Proto/Service.hs b/hbs2-core/lib/HBS2/Net/Proto/Service.hs index 756dc93e..f73627fd 100644 --- a/hbs2-core/lib/HBS2/Net/Proto/Service.hs +++ b/hbs2-core/lib/HBS2/Net/Proto/Service.hs @@ -26,6 +26,7 @@ import UnliftIO.Async import UnliftIO qualified as UIO import UnliftIO (TVar,TQueue,atomically) import System.Random (randomIO) +import Data.Hashable import Data.Word import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict qualified as HashMap @@ -130,10 +131,13 @@ makeRequestR :: forall api method e m . ( KnownNat (FromJust (FindMethodIndex 0 ) => Input method -> m (ServiceProto api e) makeRequestR input = do + + t <- getTimeCoarse <&> round @_ @Word64 . realToFrac + rnum <- atomically do n <- readTVar rnumnum - modifyTVar rnumnum succ - pure n + modifyTVar' rnumnum succ + pure (fromIntegral $ hash (n+t)) pure $ ServiceRequest rnum (serialise (fromIntegral idx :: Int, serialise input)) where diff --git a/hbs2-peer/app/PeerMain.hs b/hbs2-peer/app/PeerMain.hs index 762755fd..1674e934 100644 --- a/hbs2-peer/app/PeerMain.hs +++ b/hbs2-peer/app/PeerMain.hs @@ -604,9 +604,8 @@ runCLI = do pByPassShow = do rpc <- pRpcCommon pure $ withMyRPC @PeerAPI rpc $ \caller -> do - void $ runMaybeT do - d <- toMPlus =<< callService @RpcByPassInfo caller () - liftIO $ print $ pretty d + d <- callRpcWaitRetry @RpcByPassInfo (TimeoutSec 1) 10 caller () + liftIO $ print $ pretty d pRunGC = do rpc <- pRpcCommon