summaryrefslogtreecommitdiff
path: root/P2P
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-11-30 15:14:54 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-11-30 15:16:25 -0400
commitf14c412232808399c609e0dd484b8243af7daa3a (patch)
treece47c3914ad582525c4632d0229ea02bd4e1222e /P2P
parent66b3af4aa5c3bbb53fc27b25303c4e69364930f5 (diff)
implement p2p --link
This commit was sponsored by Riku Voipio.
Diffstat (limited to 'P2P')
-rw-r--r--P2P/Auth.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/P2P/Auth.hs b/P2P/Auth.hs
index 2482c1dc0..2c8465900 100644
--- a/P2P/Auth.hs
+++ b/P2P/Auth.hs
@@ -9,7 +9,9 @@ module P2P.Auth where
import Annex.Common
import Creds
+import P2P.Address
import Utility.AuthToken
+import Utility.Tor
import qualified Data.Text as T
@@ -24,6 +26,7 @@ loadP2PAuthTokens' = mapMaybe toAuthToken
. fromMaybe []
<$> readCacheCreds p2pAuthCredsFile
+-- | Stores an AuthToken, making it be accepted by this repository.
storeP2PAuthToken :: AuthToken -> Annex ()
storeP2PAuthToken t = do
ts <- loadP2PAuthTokens'
@@ -33,3 +36,20 @@ storeP2PAuthToken t = do
p2pAuthCredsFile :: FilePath
p2pAuthCredsFile = "p2pauth"
+
+-- | Loads the AuthToken to use when connecting with a given P2P address.
+loadP2PRemoteAuthToken :: P2PAddress -> Annex (Maybe AuthToken)
+loadP2PRemoteAuthToken addr = maybe Nothing (toAuthToken . T.pack)
+ <$> readCacheCreds (addressCredsFile addr)
+
+-- | Stores the AuthToken o use when connecting with a given P2P address.
+storeP2PRemoteAuthToken :: P2PAddress -> AuthToken -> Annex ()
+storeP2PRemoteAuthToken addr t = writeCacheCreds
+ (T.unpack $ fromAuthToken t)
+ (addressCredsFile addr)
+
+addressCredsFile :: P2PAddress -> FilePath
+-- We can omit the port and just use the onion address for the creds file,
+-- because any given tor hidden service runs on a single port and has a
+-- unique onion address.
+addressCredsFile (TorAnnex (OnionAddress onionaddr) _port) = onionaddr