need to auth with the peer

This commit is contained in:
Joey Hess 2016-12-06 15:49:39 -04:00
parent f744bd5391
commit bb5168e894
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
2 changed files with 22 additions and 3 deletions

View file

@ -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

View file

@ -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