git-annex/Assistant/Pairing.hs

66 lines
1.8 KiB
Haskell
Raw Normal View History

2012-09-08 19:21:34 +00:00
{- git-annex assistant repo pairing, core data types
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Assistant.Pairing where
import Utility.Verifiable
import Assistant.Ssh
import Control.Concurrent
2012-09-08 19:21:34 +00:00
import Network.Socket
data PairStage
{- "I'll pair with anybody who shares the secret that can be used
- to verify this request." -}
= PairReq
{- "I've verified your request, and you can verify this to see
- that I know the secret. I set up your ssh key already.
- Here's mine for you to set up." -}
| PairAck
{- "I saw your PairAck; you can stop sending them." -}
| PairDone
deriving (Eq, Read, Show)
2012-09-11 01:55:59 +00:00
newtype PairMsg = PairMsg (Verifiable (PairStage, PairData, SomeAddr))
deriving (Eq, Read, Show)
2012-09-11 01:55:59 +00:00
fromPairMsg :: PairMsg -> (Verifiable (PairStage, PairData, SomeAddr))
fromPairMsg (PairMsg m) = m
pairMsgStage :: PairMsg -> PairStage
2012-09-11 01:55:59 +00:00
pairMsgStage (PairMsg (Verifiable (s, _, _) _)) = s
pairMsgData :: PairMsg -> PairData
2012-09-11 01:55:59 +00:00
pairMsgData (PairMsg (Verifiable (_, d, _) _)) = d
pairMsgAddr :: PairMsg -> SomeAddr
pairMsgAddr (PairMsg (Verifiable (_, _, a) _)) = a
data PairData = PairData
-- uname -n output, not a full domain name
{ remoteHostName :: Maybe HostName
, remoteUserName :: UserName
2012-09-08 19:40:47 +00:00
, remoteDirectory :: FilePath
, remoteSshPubKey :: SshPubKey
}
deriving (Eq, Read, Show)
type UserName = String
{- A pairing that is in progress has a secret, a thread that is
- broadcasting pairing messages, and a SshKeyPair that has not yet been
- set up on disk. -}
data PairingInProgress = PairingInProgress
{ inProgressSecret :: Secret
2012-09-11 01:55:59 +00:00
, inProgressThreadId :: Maybe ThreadId
, inProgressSshKeyPair :: SshKeyPair
2012-09-11 01:55:59 +00:00
, inProgressPairData :: PairData
}
data SomeAddr = IPv4Addr HostAddress | IPv6Addr HostAddress6
deriving (Ord, Eq, Read, Show)