diff --git a/hbs2-peer/app/PeerMain.hs b/hbs2-peer/app/PeerMain.hs index 7ad62f24..3769850e 100644 --- a/hbs2-peer/app/PeerMain.hs +++ b/hbs2-peer/app/PeerMain.hs @@ -143,10 +143,6 @@ import Graphics.Vty.Platform.Unix qualified as Vty import Control.Concurrent.Async (ExceptionInLinkedThread(..)) -data GoAgainException = GoAgainException - deriving (Eq,Ord,Show,Typeable) - -instance Exception GoAgainException -- TODO: write-workers-to-config defStorageThreads :: Integral a => a @@ -1354,7 +1350,8 @@ runPeer opts = respawnOnError opts $ do setProbe rpcmsg rpcProbe addProbe rpcProbe - let rpcctx = RPC2Context { rpcConfig = fromPeerConfig conf + let rpcctx = RPC2Context { rpcSelf = myself + , rpcConfig = fromPeerConfig conf , rpcMessaging = rpcmsg , rpcTCP = tcp , rpcPokeAnswer = pokeAnsw diff --git a/hbs2-peer/app/PeerTypes.hs b/hbs2-peer/app/PeerTypes.hs index fc7841a4..3c6570b7 100644 --- a/hbs2-peer/app/PeerTypes.hs +++ b/hbs2-peer/app/PeerTypes.hs @@ -65,6 +65,11 @@ import UnliftIO import Streaming.Prelude qualified as S +data GoAgainException = GoAgainException + deriving (Eq,Ord,Show,Typeable) + +instance Exception GoAgainException + data PeerInfo e = PeerInfo { _peerBurst :: TVar Int diff --git a/hbs2-peer/app/RPC2.hs b/hbs2-peer/app/RPC2.hs index 1081fae1..ff904cc6 100644 --- a/hbs2-peer/app/RPC2.hs +++ b/hbs2-peer/app/RPC2.hs @@ -79,7 +79,7 @@ import Streaming.Prelude qualified as S instance (e ~ L4Proto, MonadUnliftIO m, HasRpcContext PeerAPI RPC2Context m) => HandleMethod m RpcRunScript where handleMethod top = do - co <- getRpcContext @PeerAPI + co@RPC2Context{..} <- getRpcContext @PeerAPI let cli = parseTop top & fromRight mempty @@ -218,6 +218,11 @@ instance (e ~ L4Proto, MonadUnliftIO m, HasRpcContext PeerAPI RPC2Context m) => _ -> do pure nil + + entry $ bindMatch "reset" $ const do + throwTo rpcSelf GoAgainException + pure $ mkSym "reset" + entry $ bindMatch "peer-info" $ const do now <- getTimeCoarse diff --git a/hbs2-peer/lib/HBS2/Peer/RPC/Internal/Types.hs b/hbs2-peer/lib/HBS2/Peer/RPC/Internal/Types.hs index fc2652c5..24594878 100644 --- a/hbs2-peer/lib/HBS2/Peer/RPC/Internal/Types.hs +++ b/hbs2-peer/lib/HBS2/Peer/RPC/Internal/Types.hs @@ -25,13 +25,15 @@ import Data.Config.Suckless.Parse import Data.Kind import Control.Monad import Control.Monad.Reader +import Control.Concurrent (ThreadId) import Data.ByteString ( ByteString ) import UnliftIO import HBS2.Prelude (asyncLinked) data RPC2Context = RPC2Context - { rpcConfig :: [Syntax C] + { rpcSelf :: ThreadId + , rpcConfig :: [Syntax C] , rpcMessaging :: MessagingUnix , rpcTCP :: Maybe MessagingTCP , rpcPokeAnswer :: String