need to auth with the peer
This commit is contained in:
parent
f744bd5391
commit
bb5168e894
2 changed files with 22 additions and 3 deletions
|
@ -11,6 +11,7 @@ module P2P.IO
|
||||||
( RunProto
|
( RunProto
|
||||||
, P2PConnection(..)
|
, P2PConnection(..)
|
||||||
, connectPeer
|
, connectPeer
|
||||||
|
, closeConnection
|
||||||
, setupHandle
|
, setupHandle
|
||||||
, runNetProto
|
, runNetProto
|
||||||
, runNet
|
, runNet
|
||||||
|
@ -60,6 +61,11 @@ connectPeer g (TorAnnex onionaddress onionport) = do
|
||||||
, connOhdl = h
|
, connOhdl = h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeConnection :: P2PConnection -> IO ()
|
||||||
|
closeConnection conn = do
|
||||||
|
hClose (connIhdl conn)
|
||||||
|
hClose (connOhdl conn)
|
||||||
|
|
||||||
setupHandle :: Socket -> IO Handle
|
setupHandle :: Socket -> IO Handle
|
||||||
setupHandle s = do
|
setupHandle s = do
|
||||||
h <- socketToHandle s ReadWriteMode
|
h <- socketToHandle s ReadWriteMode
|
||||||
|
|
|
@ -16,13 +16,16 @@ import qualified P2P.Protocol as P2P
|
||||||
import P2P.Address
|
import P2P.Address
|
||||||
import P2P.Annex
|
import P2P.Annex
|
||||||
import P2P.IO
|
import P2P.IO
|
||||||
|
import P2P.Auth
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
import Types.GitConfig
|
import Types.GitConfig
|
||||||
import qualified Git
|
import qualified Git
|
||||||
|
import Annex.UUID
|
||||||
import Config
|
import Config
|
||||||
import Config.Cost
|
import Config.Cost
|
||||||
import Remote.Helper.Git
|
import Remote.Helper.Git
|
||||||
import Utility.Metered
|
import Utility.Metered
|
||||||
|
import Utility.AuthToken
|
||||||
import Types.NumCopies
|
import Types.NumCopies
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
|
@ -128,8 +131,7 @@ runProto' a (OpenConnection conn) = do
|
||||||
if isJust r
|
if isJust r
|
||||||
then return (OpenConnection conn, r)
|
then return (OpenConnection conn, r)
|
||||||
else do
|
else do
|
||||||
liftIO $ hClose (connIhdl conn)
|
liftIO $ closeConnection conn
|
||||||
liftIO $ hClose (connOhdl conn)
|
|
||||||
return (ClosedConnection, r)
|
return (ClosedConnection, r)
|
||||||
|
|
||||||
-- Uses an open connection if one is available in the ConnectionPool;
|
-- Uses an open connection if one is available in the ConnectionPool;
|
||||||
|
@ -165,5 +167,16 @@ openConnection addr = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
v <- liftIO $ tryNonAsync $ connectPeer g addr
|
v <- liftIO $ tryNonAsync $ connectPeer g addr
|
||||||
case v of
|
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
|
Left _e -> return ClosedConnection
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue