A peer-to-peer stack for code collaboration
feat: Explicit timeouts for IPFS API. (#557)
James Haydon051c9e94fdea
diff --git a/src/Radicle/Daemon/Client.hs b/src/Radicle/Daemon/Client.hsindex df39878..155851f 100644--- a/src/Radicle/Daemon/Client.hs+++ b/src/Radicle/Daemon/Client.hs@@ -24,7 +24,7 @@ import Radicle.Internal.Coreimport Radicle.Internal.Identifierimport qualified Radicle.Internal.PrimFns as PrimFnsimport Radicle.Internal.Type-+import qualified Radicle.Ipfs as Ipfs-- | Constraints for all client functionstype ClientM m = (MonadIO m, MonadError Servant.ServantError m)@@ -41,7 +41,7 @@ newClient :: IO ClientnewClient = dobaseUrlString <- fromMaybe "http://localhost:8909" <$> lookupEnv "RAD_DAEMON_API_URL"clientBaseUrl <- Servant.parseBaseUrl baseUrlString- clientHttpManager <- HttpClient.newManager HttpClient.defaultManagerSettings+ clientHttpManager <- Ipfs.newIpfsHttpClientManagerpure Client {..}-- | Send an input to a machine to be evaluated and applied. Returns the resultsdiff --git a/src/Radicle/Ipfs.hs b/src/Radicle/Ipfs.hsindex 358ce59..3c39ddf 100644--- a/src/Radicle/Ipfs.hs+++ b/src/Radicle/Ipfs.hs@@ -2,6 +2,7 @@module Radicle.Ipfs( MonadIpfs(..), Client+ , newIpfsHttpClientManager, newClient, IpfsException(..)@@ -65,11 +66,17 @@ data Client = Client, clientHttpManager :: HttpClient.Manager}+newIpfsHttpClientManager :: IO HttpClient.Manager+newIpfsHttpClientManager = HttpClient.newManager+ HttpClient.defaultManagerSettings{+ HttpClient.managerResponseTimeout = HttpClient.responseTimeoutMicro (ipfsTimeoutSeconds * 1000000)+ }+newClient :: MonadIO m => m ClientnewClient = liftIO $ dobaseUrl <- fromMaybe "http://localhost:9301" <$> lookupEnv "RAD_IPFS_API_URL"clientBaseRequest <- HttpClient.parseUrlThrow baseUrl- clientHttpManager <- HttpClient.newManager HttpClient.defaultManagerSettings+ clientHttpManager <- newIpfsHttpClientManagerpure Client{clientBaseRequest, clientHttpManager}data IpfsException@@ -291,7 +298,7 @@ newtype NameResolveResponse= NameResolveResponse CIDnameResolve :: (MonadIpfs m) => IpnsId -> m NameResolveResponse-nameResolve ipnsId = ipfsHttpGet "name/resolve" [("arg", ipnsId), ("recursive", "true")]+nameResolve ipnsId = ipfsHttpGet "name/resolve" [("arg", ipnsId), ("recursive", "true"), ("dht-timeout", show ipfsTimeoutSeconds <> "s")]instance FromJSON NameResolveResponse whereparseJSON = Aeson.withObject "v0/name/resolve response" $ \o -> do@@ -361,6 +368,9 @@ makeIpfsRequest baseRequest method path params =whereparams' = [ (encodeUtf8 key, Just (encodeUtf8 value)) | (key, value) <- params]+-- | Timeout for IPFS API.+ipfsTimeoutSeconds :: Int+ipfsTimeoutSeconds = 60-- | Parses response body as JSON and returns the parsed value. @path@-- is the IPFS API the response was obtained from. Throws