diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-12-06 15:49:39 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-12-06 15:50:02 -0400 |
commit | 12a58f1922d30995019ca73c462f6a9937413f2b (patch) | |
tree | 4e9a54d7ff0f4d3a204437ef295c67f7f97f5854 | |
parent | 5258f572d494d015c6c6e60c37a215bb95048bbd (diff) |
need to auth with the peer
-rw-r--r-- | P2P/IO.hs | 6 | ||||
-rw-r--r-- | Remote/P2P.hs | 19 |
2 files changed, 22 insertions, 3 deletions
@@ -11,6 +11,7 @@ module P2P.IO ( RunProto , P2PConnection(..) , connectPeer + , closeConnection , setupHandle , runNetProto , runNet @@ -60,6 +61,11 @@ connectPeer g (TorAnnex onionaddress onionport) = do , connOhdl = h } +closeConnection :: P2PConnection -> IO () +closeConnection conn = do + hClose (connIhdl conn) + hClose (connOhdl conn) + setupHandle :: Socket -> IO Handle setupHandle s = do h <- socketToHandle s ReadWriteMode diff --git a/Remote/P2P.hs b/Remote/P2P.hs index 0c7ca0574..68b75924f 100644 --- a/Remote/P2P.hs +++ b/Remote/P2P.hs @@ -16,13 +16,16 @@ import qualified P2P.Protocol as P2P import P2P.Address import P2P.Annex import P2P.IO +import P2P.Auth import Types.Remote import Types.GitConfig import qualified Git +import Annex.UUID import Config import Config.Cost import Remote.Helper.Git import Utility.Metered +import Utility.AuthToken import Types.NumCopies import Control.Concurrent @@ -128,8 +131,7 @@ runProto' a (OpenConnection conn) = do if isJust r then return (OpenConnection conn, r) else do - liftIO $ hClose (connIhdl conn) - liftIO $ hClose (connOhdl conn) + liftIO $ closeConnection conn return (ClosedConnection, r) -- Uses an open connection if one is available in the ConnectionPool; @@ -165,5 +167,16 @@ openConnection addr = do g <- Annex.gitRepo v <- liftIO $ tryNonAsync $ connectPeer g addr case v of - Right conn -> return (OpenConnection conn) + Right conn -> do + myuuid <- getUUID + authtoken <- fromMaybe nullAuthToken + <$> loadP2PRemoteAuthToken addr + res <- liftIO $ runNetProto conn $ + P2P.auth myuuid authtoken + case res of + Just (Just _theiruuid) -> + return (OpenConnection conn) + _ -> do + liftIO $ closeConnection conn + return ClosedConnection Left _e -> return ClosedConnection |