2014-04-05 18:30:42 +00:00
|
|
|
{- git-remote-daemon data types.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-04-05 18:30:42 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-04-05 18:30:42 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
|
|
|
module RemoteDaemon.Types where
|
|
|
|
|
2014-04-09 18:10:29 +00:00
|
|
|
import Common
|
2014-04-06 23:06:03 +00:00
|
|
|
import qualified Annex
|
2014-04-05 18:30:42 +00:00
|
|
|
import qualified Git.Types as Git
|
|
|
|
import qualified Utility.SimpleProtocol as Proto
|
2015-02-12 20:12:32 +00:00
|
|
|
import Types.GitConfig
|
2016-12-09 18:52:38 +00:00
|
|
|
import Annex.ChangedRefs (ChangedRefs)
|
2023-08-14 16:28:10 +00:00
|
|
|
import Utility.Url.Parse
|
2014-04-05 18:30:42 +00:00
|
|
|
|
2014-04-09 18:10:29 +00:00
|
|
|
import Network.URI
|
2014-04-06 23:06:03 +00:00
|
|
|
import Control.Concurrent
|
2015-01-15 19:37:48 +00:00
|
|
|
import Control.Concurrent.STM
|
2014-04-06 23:06:03 +00:00
|
|
|
|
2014-04-09 18:10:29 +00:00
|
|
|
-- The URI of a remote is used to uniquely identify it (names change..)
|
|
|
|
newtype RemoteURI = RemoteURI URI
|
2014-10-09 19:09:26 +00:00
|
|
|
deriving (Show)
|
2014-04-09 18:10:29 +00:00
|
|
|
|
2014-04-06 23:06:03 +00:00
|
|
|
-- A Transport for a particular git remote consumes some messages
|
|
|
|
-- from a Chan, and emits others to another Chan.
|
2015-01-15 19:37:48 +00:00
|
|
|
type Transport = RemoteRepo -> RemoteURI -> TransportHandle -> TChan Consumed -> TChan Emitted -> IO ()
|
2014-04-08 17:41:36 +00:00
|
|
|
|
2016-12-28 16:21:52 +00:00
|
|
|
-- A server for a Transport consumes some messages from a Chan in
|
|
|
|
-- order to learn about network changes, reloads, etc.
|
|
|
|
type Server = TChan Consumed -> TransportHandle -> IO ()
|
|
|
|
|
2015-02-12 20:12:32 +00:00
|
|
|
data RemoteRepo = RemoteRepo Git.Repo RemoteGitConfig
|
2016-06-02 20:34:52 +00:00
|
|
|
newtype LocalRepo = LocalRepo Git.Repo
|
2014-04-08 17:41:36 +00:00
|
|
|
|
2021-04-02 19:26:21 +00:00
|
|
|
-- All Transports share a single AnnexState MVar and an AnnexRead.
|
2014-04-20 19:45:14 +00:00
|
|
|
--
|
|
|
|
-- Different TransportHandles may have different versions of the LocalRepo.
|
|
|
|
-- (For example, the ssh transport modifies it to enable ssh connection
|
|
|
|
-- caching.)
|
2021-04-02 19:26:21 +00:00
|
|
|
data TransportHandle = TransportHandle LocalRepo (MVar Annex.AnnexState) Annex.AnnexRead
|
2014-04-06 23:06:03 +00:00
|
|
|
|
2014-04-05 18:30:42 +00:00
|
|
|
-- Messages that the daemon emits.
|
|
|
|
data Emitted
|
2014-04-09 18:10:29 +00:00
|
|
|
= CONNECTED RemoteURI
|
|
|
|
| DISCONNECTED RemoteURI
|
|
|
|
| SYNCING RemoteURI
|
|
|
|
| DONESYNCING RemoteURI Bool
|
|
|
|
| WARNING RemoteURI String
|
2014-04-20 19:30:39 +00:00
|
|
|
deriving (Show)
|
2014-04-05 18:30:42 +00:00
|
|
|
|
2023-03-14 02:39:16 +00:00
|
|
|
-- Messages that the daemon consumes.
|
2014-04-05 18:30:42 +00:00
|
|
|
data Consumed
|
|
|
|
= PAUSE
|
2014-04-12 20:32:59 +00:00
|
|
|
| LOSTNET
|
2014-04-05 18:30:42 +00:00
|
|
|
| RESUME
|
2016-12-09 18:52:38 +00:00
|
|
|
| CHANGED ChangedRefs
|
2014-04-05 18:30:42 +00:00
|
|
|
| RELOAD
|
2014-04-06 23:06:03 +00:00
|
|
|
| STOP
|
2014-04-20 19:30:39 +00:00
|
|
|
deriving (Show)
|
2014-04-05 18:30:42 +00:00
|
|
|
|
|
|
|
instance Proto.Sendable Emitted where
|
2014-04-05 20:04:37 +00:00
|
|
|
formatMessage (CONNECTED remote) =
|
|
|
|
["CONNECTED", Proto.serialize remote]
|
|
|
|
formatMessage (DISCONNECTED remote) =
|
|
|
|
["DISCONNECTED", Proto.serialize remote]
|
2014-04-06 23:06:03 +00:00
|
|
|
formatMessage (SYNCING remote) =
|
|
|
|
["SYNCING", Proto.serialize remote]
|
2014-04-09 18:10:29 +00:00
|
|
|
formatMessage (DONESYNCING remote status) =
|
|
|
|
["DONESYNCING", Proto.serialize remote, Proto.serialize status]
|
|
|
|
formatMessage (WARNING remote message) =
|
|
|
|
["WARNING", Proto.serialize remote, Proto.serialize message]
|
2014-04-05 18:30:42 +00:00
|
|
|
|
|
|
|
instance Proto.Sendable Consumed where
|
|
|
|
formatMessage PAUSE = ["PAUSE"]
|
2014-04-12 20:32:59 +00:00
|
|
|
formatMessage LOSTNET = ["LOSTNET"]
|
2014-04-05 18:30:42 +00:00
|
|
|
formatMessage RESUME = ["RESUME"]
|
2014-04-06 23:06:03 +00:00
|
|
|
formatMessage (CHANGED refs) =["CHANGED", Proto.serialize refs]
|
2014-04-05 18:30:42 +00:00
|
|
|
formatMessage RELOAD = ["RELOAD"]
|
2014-04-06 23:06:03 +00:00
|
|
|
formatMessage STOP = ["STOP"]
|
2014-04-05 18:30:42 +00:00
|
|
|
|
|
|
|
instance Proto.Receivable Emitted where
|
2014-04-05 20:04:37 +00:00
|
|
|
parseCommand "CONNECTED" = Proto.parse1 CONNECTED
|
|
|
|
parseCommand "DISCONNECTED" = Proto.parse1 DISCONNECTED
|
2014-04-06 23:06:03 +00:00
|
|
|
parseCommand "SYNCING" = Proto.parse1 SYNCING
|
|
|
|
parseCommand "DONESYNCING" = Proto.parse2 DONESYNCING
|
2014-04-09 18:10:29 +00:00
|
|
|
parseCommand "WARNING" = Proto.parse2 WARNING
|
2014-04-05 18:30:42 +00:00
|
|
|
parseCommand _ = Proto.parseFail
|
|
|
|
|
|
|
|
instance Proto.Receivable Consumed where
|
|
|
|
parseCommand "PAUSE" = Proto.parse0 PAUSE
|
2014-04-12 20:32:59 +00:00
|
|
|
parseCommand "LOSTNET" = Proto.parse0 LOSTNET
|
2014-04-05 18:30:42 +00:00
|
|
|
parseCommand "RESUME" = Proto.parse0 RESUME
|
2014-04-06 23:06:03 +00:00
|
|
|
parseCommand "CHANGED" = Proto.parse1 CHANGED
|
2014-04-05 18:30:42 +00:00
|
|
|
parseCommand "RELOAD" = Proto.parse0 RELOAD
|
2014-04-06 23:06:03 +00:00
|
|
|
parseCommand "STOP" = Proto.parse0 STOP
|
2014-04-05 18:30:42 +00:00
|
|
|
parseCommand _ = Proto.parseFail
|
|
|
|
|
2014-04-09 18:10:29 +00:00
|
|
|
instance Proto.Serializable RemoteURI where
|
|
|
|
serialize (RemoteURI u) = show u
|
2023-03-27 17:38:02 +00:00
|
|
|
deserialize = RemoteURI <$$> parseURIPortable
|
2014-04-09 18:10:29 +00:00
|
|
|
|
2014-04-06 23:06:03 +00:00
|
|
|
instance Proto.Serializable Bool where
|
|
|
|
serialize False = "0"
|
|
|
|
serialize True = "1"
|
|
|
|
|
|
|
|
deserialize "0" = Just False
|
|
|
|
deserialize "1" = Just True
|
|
|
|
deserialize _ = Nothing
|