diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-11-30 14:35:24 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-11-30 14:35:24 -0400 |
commit | 66b3af4aa5c3bbb53fc27b25303c4e69364930f5 (patch) | |
tree | acb9491353a5c5f8a143b29e8aff92533b8c359d /P2P | |
parent | ef6cd4fe3a5bf0163ae3e50ac6248dc11d8a7bcf (diff) |
implement p2p command
Diffstat (limited to 'P2P')
-rw-r--r-- | P2P/Address.hs | 5 | ||||
-rw-r--r-- | P2P/Auth.hs | 37 |
2 files changed, 25 insertions, 17 deletions
diff --git a/P2P/Address.hs b/P2P/Address.hs index 862f06a9c..19ff82a89 100644 --- a/P2P/Address.hs +++ b/P2P/Address.hs @@ -23,7 +23,10 @@ import qualified Data.Text as T data P2PAddress = TorAnnex OnionAddress OnionPort deriving (Eq, Show) --- | A P2P address, with an AuthToken +-- | A P2P address, with an AuthToken. +-- +-- This is enough information to connect to the peer, and authenticate with +-- it. data P2PAddressAuth = P2PAddressAuth P2PAddress AuthToken deriving (Eq, Show) diff --git a/P2P/Auth.hs b/P2P/Auth.hs index 5c3feb713..2482c1dc0 100644 --- a/P2P/Auth.hs +++ b/P2P/Auth.hs @@ -1,4 +1,4 @@ -{- P2P protocol, authorization +{- P2P authtokens - - Copyright 2016 Joey Hess <id@joeyh.name> - @@ -7,24 +7,29 @@ module P2P.Auth where -import Common +import Annex.Common +import Creds import Utility.AuthToken import qualified Data.Text as T --- Use .git/annex/creds/p2p to hold AuthTokens of authorized peers. -getAuthTokens :: Annex AllowedAuthTokens -getAuthTokens = allowedAuthTokens <$> getAuthTokens' +-- | Load authtokens that are accepted by this repository. +loadP2PAuthTokens :: Annex AllowedAuthTokens +loadP2PAuthTokens = allowedAuthTokens <$> loadP2PAuthTokens' -getAuthTokens' :: Annex [AuthTokens] -getAuthTokens' = mapMaybe toAuthToken - . map T.pack - . lines - . fromMaybe [] - <$> readCacheCreds "tor" +loadP2PAuthTokens' :: Annex [AuthToken] +loadP2PAuthTokens' = mapMaybe toAuthToken + . map T.pack + . lines + . fromMaybe [] + <$> readCacheCreds p2pAuthCredsFile -addAuthToken :: AuthToken -> Annex () -addAuthToken t = do - ts <- getAuthTokens' - let d = unlines $ map (T.unpack . fromAuthToken) (t:ts) - writeCacheCreds d "tor" +storeP2PAuthToken :: AuthToken -> Annex () +storeP2PAuthToken t = do + ts <- loadP2PAuthTokens' + unless (t `elem` ts) $ do + let d = unlines $ map (T.unpack . fromAuthToken) (t:ts) + writeCacheCreds d p2pAuthCredsFile + +p2pAuthCredsFile :: FilePath +p2pAuthCredsFile = "p2pauth" |