2017-03-30 23:32:58 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2017 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2017-03-30 23:32:58 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Command.Multicast where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Logs.Multicast
|
|
|
|
import Annex.Multicast
|
|
|
|
import Annex.WorkTree
|
|
|
|
import Annex.Content
|
|
|
|
import Annex.UUID
|
|
|
|
import Annex.Perms
|
2020-12-11 15:33:10 +00:00
|
|
|
import Logs.Location
|
2017-03-30 23:32:58 +00:00
|
|
|
import Utility.FileMode
|
2017-04-05 15:19:29 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import Creds
|
2017-03-30 23:32:58 +00:00
|
|
|
#endif
|
|
|
|
import qualified Limit
|
|
|
|
import Types.FileMatcher
|
|
|
|
import qualified Git.LsFiles as LsFiles
|
|
|
|
import Utility.Hash
|
|
|
|
import Utility.Tmp
|
2017-12-31 20:08:31 +00:00
|
|
|
import Utility.Tmp.Dir
|
|
|
|
import Utility.Process.Transcript
|
2020-11-24 16:38:12 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
2017-03-30 23:32:58 +00:00
|
|
|
|
|
|
|
import Data.Char
|
|
|
|
import qualified Data.ByteString.Lazy.UTF8 as B8
|
|
|
|
import qualified Data.Map as M
|
|
|
|
import Control.Concurrent.Async
|
|
|
|
|
|
|
|
cmd :: Command
|
|
|
|
cmd = command "multicast" SectionCommon "multicast file distribution"
|
|
|
|
paramNothing (seek <$$> optParser)
|
|
|
|
|
|
|
|
data MultiCastAction
|
|
|
|
= GenAddress
|
|
|
|
| Send
|
|
|
|
| Receive
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
data MultiCastOptions = MultiCastOptions MultiCastAction [CommandParam] [FilePath]
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser MultiCastOptions
|
|
|
|
optParser _ = MultiCastOptions
|
|
|
|
<$> (genaddressp <|> sendp <|> receivep)
|
|
|
|
<*> many uftpopt
|
|
|
|
<*> cmdParams paramPaths
|
|
|
|
where
|
|
|
|
genaddressp = flag' GenAddress
|
|
|
|
( long "gen-address"
|
|
|
|
<> help "generate multicast encryption key and store address in git-annex branch"
|
|
|
|
)
|
|
|
|
sendp = flag' Send
|
|
|
|
( long "send"
|
|
|
|
<> help "multicast files"
|
|
|
|
)
|
|
|
|
receivep = flag' Receive
|
|
|
|
( long "receive"
|
|
|
|
<> help "listen for multicast files and store in repository"
|
|
|
|
)
|
|
|
|
uftpopt = Param <$> strOption
|
|
|
|
( long "uftp-opt"
|
|
|
|
<> short 'U'
|
|
|
|
<> help "passed on to uftp/uftpd"
|
|
|
|
<> metavar "OPTION"
|
|
|
|
)
|
|
|
|
|
|
|
|
seek :: MultiCastOptions -> CommandSeek
|
|
|
|
seek (MultiCastOptions GenAddress _ _) = commandAction genAddress
|
|
|
|
seek (MultiCastOptions Send ups fs) = commandAction $ send ups fs
|
|
|
|
seek (MultiCastOptions Receive ups []) = commandAction $ receive ups
|
|
|
|
seek (MultiCastOptions Receive _ _) = giveup "Cannot specify list of files with --receive; this receives whatever files the sender chooses to send."
|
|
|
|
|
|
|
|
genAddress :: CommandStart
|
2020-09-14 20:49:33 +00:00
|
|
|
genAddress = starting "gen-address" (ActionItemOther Nothing) (SeekInput []) $ do
|
2017-03-30 23:32:58 +00:00
|
|
|
k <- uftpKey
|
|
|
|
(s, ok) <- case k of
|
|
|
|
KeyContainer s -> liftIO $ genkey (Param s)
|
|
|
|
KeyFile f -> do
|
2020-11-02 20:31:28 +00:00
|
|
|
createAnnexDirectory (toRawFilePath (takeDirectory f))
|
2020-11-24 16:38:12 +00:00
|
|
|
liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
|
2017-03-30 23:32:58 +00:00
|
|
|
liftIO $ protectedOutput $ genkey (File f)
|
|
|
|
case (ok, parseFingerprint s) of
|
|
|
|
(False, _) -> giveup $ "uftp_keymgt failed: " ++ s
|
|
|
|
(_, Nothing) -> giveup $ "Failed to find fingerprint in uftp_keymgt output: " ++ s
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
(True, Just fp) -> next $ do
|
2017-03-30 23:32:58 +00:00
|
|
|
recordFingerprint fp =<< getUUID
|
|
|
|
return True
|
|
|
|
where
|
|
|
|
-- Annoyingly, the fingerprint is output to stderr.
|
|
|
|
genkey p = processTranscript "uftp_keymgt" ps Nothing
|
|
|
|
where
|
|
|
|
ps = toCommand $
|
|
|
|
[ Param "-g"
|
|
|
|
, keyparam
|
|
|
|
, p
|
|
|
|
]
|
|
|
|
-- uftp only supports rsa up to 2048 which is on the lower
|
|
|
|
-- limit of secure RSA key sizes. Instead, use an EC curve.
|
|
|
|
-- Except for on Windows XP, secp521r1 is supported on all
|
|
|
|
-- platforms by uftp. DJB thinks it's pretty good compared
|
|
|
|
-- with other NIST curves: "there's one standard NIST curve
|
2021-05-04 03:44:31 +00:00
|
|
|
-- using a nice prime, namely 2521-1 but the sheer size of this
|
2017-03-30 23:32:58 +00:00
|
|
|
-- prime makes it much slower than NIST P-256"
|
|
|
|
-- (http://blog.cr.yp.to/20140323-ecdsa.html)
|
|
|
|
-- Since this key is only used to set up the block encryption,
|
|
|
|
-- its slow speed is ok.
|
|
|
|
keyparam = Param "ec:secp521r1"
|
|
|
|
|
|
|
|
parseFingerprint :: String -> Maybe Fingerprint
|
|
|
|
parseFingerprint = Fingerprint <$$> lastMaybe . filter isfingerprint . words
|
|
|
|
where
|
|
|
|
isfingerprint s =
|
|
|
|
let os = filter (all isHexDigit) (splitc ':' s)
|
|
|
|
in length os == 20
|
|
|
|
|
|
|
|
send :: [CommandParam] -> [FilePath] -> CommandStart
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
send ups fs = do
|
2017-03-30 23:32:58 +00:00
|
|
|
-- Need to be able to send files with the names of git-annex
|
|
|
|
-- keys, and uftp does not allow renaming the files that are sent.
|
|
|
|
-- In a direct mode repository, the annex objects do not have
|
|
|
|
-- the names of keys, and would have to be copied, which is too
|
|
|
|
-- expensive.
|
2020-09-14 20:49:33 +00:00
|
|
|
starting "sending files" (ActionItemOther Nothing) (SeekInput []) $
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
withTmpFile "send" $ \t h -> do
|
2020-05-28 19:55:17 +00:00
|
|
|
let ww = WarnUnmatchLsFiles
|
2020-09-25 15:38:42 +00:00
|
|
|
(fs', cleanup) <- seekHelper id ww LsFiles.inRepo
|
2020-05-28 19:55:17 +00:00
|
|
|
=<< workTreeItems ww fs
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
matcher <- Limit.getMatcher
|
2021-03-01 20:34:40 +00:00
|
|
|
let addlist f o = whenM (matcher $ MatchingFile $ FileInfo f f Nothing) $
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
liftIO $ hPutStrLn h o
|
2020-09-14 20:49:33 +00:00
|
|
|
forM_ fs' $ \(_, f) -> do
|
2020-07-10 18:17:35 +00:00
|
|
|
mk <- lookupKey f
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
case mk of
|
|
|
|
Nothing -> noop
|
2019-12-11 18:12:22 +00:00
|
|
|
Just k -> withObjectLoc k $
|
|
|
|
addlist f . fromRawFilePath
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
liftIO $ hClose h
|
2020-09-25 15:38:42 +00:00
|
|
|
liftIO $ void cleanup
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
|
|
|
|
serverkey <- uftpKey
|
|
|
|
u <- getUUID
|
|
|
|
withAuthList $ \authlist -> do
|
|
|
|
let ps =
|
|
|
|
-- Force client authentication.
|
|
|
|
[ Param "-c"
|
2022-04-19 16:02:10 +00:00
|
|
|
, Param "-Y", Param "aes256-gcm"
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
, Param "-h", Param "sha512"
|
|
|
|
-- Picked ecdh_ecdsa for perfect forward secrecy,
|
|
|
|
-- and because a EC key exchange algorithm is
|
|
|
|
-- needed since all keys are EC.
|
|
|
|
, Param "-e", Param "ecdh_ecdsa"
|
|
|
|
, Param "-k", uftpKeyParam serverkey
|
|
|
|
, Param "-U", Param (uftpUID u)
|
|
|
|
-- only allow clients on the authlist
|
|
|
|
, Param "-H", Param ("@"++authlist)
|
|
|
|
-- pass in list of files to send
|
|
|
|
, Param "-i", File t
|
|
|
|
] ++ ups
|
|
|
|
liftIO (boolSystem "uftp" ps) >>= showEndResult
|
|
|
|
next $ return True
|
2017-03-30 23:32:58 +00:00
|
|
|
|
|
|
|
receive :: [CommandParam] -> CommandStart
|
2020-09-14 20:49:33 +00:00
|
|
|
receive ups = starting "receiving multicast files" ai si $ do
|
2017-03-30 23:32:58 +00:00
|
|
|
showNote "Will continue to run until stopped by ctrl-c"
|
|
|
|
|
|
|
|
showOutput
|
|
|
|
clientkey <- uftpKey
|
|
|
|
u <- getUUID
|
|
|
|
(callback, environ, statush) <- liftIO multicastCallbackEnv
|
|
|
|
tmpobjdir <- fromRepo gitAnnexTmpObjectDir
|
|
|
|
createAnnexDirectory tmpobjdir
|
2020-11-02 20:31:28 +00:00
|
|
|
withTmpDirIn (fromRawFilePath tmpobjdir) "multicast" $ \tmpdir -> withAuthList $ \authlist -> do
|
|
|
|
abstmpdir <- liftIO $ absPath (toRawFilePath tmpdir)
|
2017-03-30 23:32:58 +00:00
|
|
|
abscallback <- liftIO $ searchPath callback
|
|
|
|
let ps =
|
|
|
|
-- Avoid it running as a daemon.
|
|
|
|
[ Param "-d"
|
|
|
|
-- Require encryption.
|
|
|
|
, Param "-E"
|
|
|
|
, Param "-k", uftpKeyParam clientkey
|
|
|
|
, Param "-U", Param (uftpUID u)
|
|
|
|
-- Only allow servers on the authlist
|
|
|
|
, Param "-S", Param authlist
|
|
|
|
-- Receive files into tmpdir
|
|
|
|
-- (it needs an absolute path)
|
2020-11-02 20:31:28 +00:00
|
|
|
, Param "-D", File (fromRawFilePath abstmpdir)
|
2017-03-30 23:32:58 +00:00
|
|
|
-- Run callback after each file received
|
|
|
|
-- (it needs an absolute path)
|
|
|
|
, Param "-s", Param (fromMaybe callback abscallback)
|
|
|
|
] ++ ups
|
|
|
|
runner <- liftIO $ async $
|
|
|
|
hClose statush
|
|
|
|
`after` boolSystemEnv "uftpd" ps (Just environ)
|
|
|
|
mapM_ storeReceived . lines =<< liftIO (hGetContents statush)
|
|
|
|
showEndResult =<< liftIO (wait runner)
|
make CommandStart return a StartMessage
The goal is to be able to run CommandStart in the main thread when -J is
used, rather than unncessarily passing it off to a worker thread, which
incurs overhead that is signficant when the CommandStart is going to
quickly decide to stop.
To do that, the message it displays needs to be displayed in the worker
thread, after the CommandStart has run.
Also, the change will mean that CommandStart will no longer necessarily
run with the same Annex state as CommandPerform. While its docs already
said it should avoid modifying Annex state, I audited all the
CommandStart code as part of the conversion. (Note that CommandSeek
already sometimes runs with a different Annex state, and that has not been
a source of any problems, so I am not too worried that this change will
lead to breakage going forward.)
The only modification of Annex state I found was it calling
allowMessages in some Commands that default to noMessages. Dealt with
that by adding a startCustomOutput and a startingUsualMessages.
This lets a command start with noMessages and then select the output it
wants for each CommandStart.
One bit of breakage: onlyActionOn has been removed from commands that used it.
The plan is that, since a StartMessage contains an ActionItem,
when a Key can be extracted from that, the parallel job runner can
run onlyActionOn' automatically. Then commands won't need to worry about
this detail. Future work.
Otherwise, this was a fairly straightforward process of making each
CommandStart compile again. Hopefully other behavior changes were mostly
avoided.
In a few cases, a command had a CommandStart that called a CommandPerform
that then called showStart multiple times. I have collapsed those
down to a single start action. The main command to perhaps suffer from it
is Command.Direct, which used to show a start for each file, and no
longer does.
Another minor behavior change is that some commands used showStart
before, but had an associated file and a Key available, so were changed
to ShowStart with an ActionItemAssociatedFile. That will not change the
normal output or behavior, but --json output will now include the key.
This should not break it for anyone using a real json parser.
2019-06-06 19:42:30 +00:00
|
|
|
next $ return True
|
2020-09-14 20:49:33 +00:00
|
|
|
where
|
|
|
|
ai = ActionItemOther Nothing
|
|
|
|
si = SeekInput []
|
2017-03-30 23:32:58 +00:00
|
|
|
|
|
|
|
storeReceived :: FilePath -> Annex ()
|
|
|
|
storeReceived f = do
|
2019-01-14 17:17:47 +00:00
|
|
|
case deserializeKey (takeFileName f) of
|
2017-03-30 23:32:58 +00:00
|
|
|
Nothing -> do
|
|
|
|
warning $ "Received a file " ++ f ++ " that is not a git-annex key. Deleting this file."
|
2020-11-24 16:38:12 +00:00
|
|
|
liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
|
2020-12-11 15:33:10 +00:00
|
|
|
Just k -> void $ logStatusAfter k $
|
2020-11-16 18:09:55 +00:00
|
|
|
getViaTmpFromDisk RetrievalVerifiableKeysSecure AlwaysVerify k (AssociatedFile Nothing) $ \dest -> unVerified $
|
2017-03-30 23:32:58 +00:00
|
|
|
liftIO $ catchBoolIO $ do
|
2022-07-12 18:53:32 +00:00
|
|
|
R.rename (toRawFilePath f) dest
|
2017-03-30 23:32:58 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
-- Under Windows, uftp uses key containers, which are not files on the
|
|
|
|
-- filesystem.
|
|
|
|
data UftpKey = KeyFile FilePath | KeyContainer String
|
|
|
|
|
|
|
|
uftpKeyParam :: UftpKey -> CommandParam
|
|
|
|
uftpKeyParam (KeyFile f) = File f
|
|
|
|
uftpKeyParam (KeyContainer s) = Param s
|
|
|
|
|
|
|
|
uftpKey :: Annex UftpKey
|
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
uftpKey = do
|
|
|
|
u <- getUUID
|
|
|
|
return $ KeyContainer $ "annex-" ++ fromUUID u
|
|
|
|
#else
|
2018-12-04 18:02:37 +00:00
|
|
|
uftpKey = KeyFile <$> credsFile "multicast"
|
2017-03-30 23:32:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
-- uftp needs a unique UID for each client and server, which
|
|
|
|
-- is a 8 digit hex number in the form "0xnnnnnnnn"
|
|
|
|
-- Derive it from the UUID.
|
|
|
|
uftpUID :: UUID -> String
|
|
|
|
uftpUID u = "0x" ++ (take 8 $ show $ sha2_256 $ B8.fromString (fromUUID u))
|
|
|
|
|
|
|
|
withAuthList :: (FilePath -> Annex a) -> Annex a
|
|
|
|
withAuthList a = do
|
|
|
|
m <- knownFingerPrints
|
|
|
|
withTmpFile "authlist" $ \t h -> do
|
|
|
|
liftIO $ hPutStr h (genAuthList m)
|
|
|
|
liftIO $ hClose h
|
|
|
|
a t
|
|
|
|
|
|
|
|
genAuthList :: M.Map UUID Fingerprint -> String
|
|
|
|
genAuthList = unlines . map fmt . M.toList
|
|
|
|
where
|
|
|
|
fmt (u, Fingerprint f) = uftpUID u ++ "|" ++ f
|