aboutsummaryrefslogtreecommitdiff
path: root/RemoteDaemon
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-02 13:50:56 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-02 13:52:43 -0400
commit9d6ee2fe7fa1ec5511070a964ba35d9c9711e235 (patch)
tree8877c12f7cd694375c8efad54be804a2f8d35631 /RemoteDaemon
parentce831b4569e17acf44465324afb0dfb674fa04d0 (diff)
make remote-daemon able to send and receive objects over tor
Each worker thread needs to run in the Annex monad, but the remote-daemon's liftAnnex can only run 1 action at a time. Used Annex.Concurrent to deal with that. P2P.Annex is incomplete as of yet.
Diffstat (limited to 'RemoteDaemon')
-rw-r--r--RemoteDaemon/Transport/Tor.hs30
1 files changed, 19 insertions, 11 deletions
diff --git a/RemoteDaemon/Transport/Tor.hs b/RemoteDaemon/Transport/Tor.hs
index 75b1a7923..3c715fbde 100644
--- a/RemoteDaemon/Transport/Tor.hs
+++ b/RemoteDaemon/Transport/Tor.hs
@@ -8,6 +8,8 @@
module RemoteDaemon.Transport.Tor (server) where
import Common
+import qualified Annex
+import Annex.Concurrent
import RemoteDaemon.Types
import RemoteDaemon.Common
import Utility.Tor
@@ -15,7 +17,7 @@ import Utility.FileMode
import Utility.AuthToken
import Remote.Helper.Tor
import P2P.Protocol
-import P2P.IO
+import P2P.Annex
import P2P.Auth
import Annex.UUID
import Types.UUID
@@ -75,14 +77,20 @@ serveClient th u r q = bracket setup cleanup go
cleanup = hClose
go h = do
debugM "remotedaemon" "serving a TOR connection"
- -- Load auth tokens for every connection, to notice
- -- when the allowed set is changed.
- allowed <- liftAnnex th loadP2PAuthTokens
- let runenv = RunEnv
- { runRepo = r
- , runCheckAuth = (`isAllowedAuthToken` allowed)
- , runIhdl = h
- , runOhdl = h
- }
- void $ runNetProto runenv (serve u)
+ -- Avoid doing any work in the liftAnnex, since only one
+ -- can run at a time.
+ st <- liftAnnex th dupState
+ ((), st') <- Annex.run st $ do
+ -- Load auth tokens for every connection, to notice
+ -- when the allowed set is changed.
+ allowed <- loadP2PAuthTokens
+ let runenv = RunEnv
+ { runRepo = r
+ , runCheckAuth = (`isAllowedAuthToken` allowed)
+ , runIhdl = h
+ , runOhdl = h
+ }
+ void $ runFullProto runenv (serve u)
+ -- Merge the duplicated state back in.
+ liftAnnex th $ mergeState st'
debugM "remotedaemon" "done with TOR connection"