summaryrefslogtreecommitdiffhomepage
path: root/HTTP
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-22 10:40:06 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-22 10:44:55 -0400
commit3923667ebdb24680dbb415bd688a8c0326df2212 (patch)
tree81a6648827130f013053994ba6ec65ddb3cfd772 /HTTP
parent281bc63549a49c173b85d7b80b4b703aab9d3a52 (diff)
downloadkeysafe-3923667ebdb24680dbb415bd688a8c0326df2212.tar.gz
allow servers to have multiple or no addresses
This allows the server list to contain 3 servers although only 1 is running so far; uploads to the others will be queued. It also allows a server to be spread amoung multiple addresses, which may be useful later for scaling. This changes BackupRecord serialization, but it's not been in a keysafe release yet, so that's not a problem. This commit was sponsored by Boyd Stephen Smith Jr. on Patreon.
Diffstat (limited to 'HTTP')
-rw-r--r--HTTP/Client.hs28
1 files changed, 15 insertions, 13 deletions
diff --git a/HTTP/Client.hs b/HTTP/Client.hs
index 48a430c..f13620e 100644
--- a/HTTP/Client.hs
+++ b/HTTP/Client.hs
@@ -64,23 +64,25 @@ serverRequest srv onerr onsuccess p a = do
(Just $ genProofOfWork req p)
(Seconds timeleft - generationTime req)
+-- A new Manager is allocated for each request, rather than reusing
+-- any connection. This is a feature; it makes correlation attacks
+-- harder because the server can't tell if two connections
+-- accessing different objects came from the same user, except by
+-- comparing IP addresses (which are masked somewhat by using tor).
serverRequest'
:: Server
-> (Manager -> BaseUrl -> ExceptT ServantError IO r)
-> IO (Either String r)
-serverRequest' srv a = do
- -- A new Manager is allocated for each request, rather than reusing
- -- any connection. This is a feature; it makes correlation attacks
- -- harder because the server can't tell if two connections
- -- accessing different objects came from the same user, except by
- -- comparing IP addresses (which are masked somewhat by using tor).
- manager <- torableManager
- res <- runExceptT $ a manager url
- return $ case res of
- Left err -> Left $ "server failure: " ++ show err
- Right r -> Right r
+serverRequest' srv a = go Nothing (serverUrls srv)
where
- url = serverUrl srv
+ go lasterr [] = return $ Left $
+ maybe "no available servers" (\err -> "server failure: " ++ show err) lasterr
+ go _ (url:urls) = do
+ manager <- torableManager
+ res <- runExceptT $ a manager url
+ case res of
+ Left err -> go (Just err) urls
+ Right r -> return (Right r)
-- | HTTP Manager supporting tor .onion and regular hosts
torableManager :: IO Manager
@@ -94,7 +96,7 @@ torableManager = newManager $ defaultManagerSettings
regular <- managerRawConnection defaultManagerSettings
regular addr host port
-torConnection :: HostName -> Port -> IO Connection
+torConnection :: String -> Port -> IO Connection
torConnection onionaddress p = do
(socket, _) <- socksConnect torsockconf socksaddr
socketConnection socket 8192