This does not change the overall license of the git-annex program, which was already AGPL due to a number of sources files being AGPL already. Legally speaking, I'm adding a new license under which these files are now available; I already released their current contents under the GPL license. Now they're dual licensed GPL and AGPL. However, I intend for all my future changes to these files to only be released under the AGPL license, and I won't be tracking the dual licensing status, so I'm simply changing the license statement to say it's AGPL. (In some cases, others wrote parts of the code of a file and released it under the GPL; but in all cases I have contributed a significant portion of the code in each file and it's that code that is getting the AGPL license; the GPL license of other contributors allows combining with AGPL code.)
		
			
				
	
	
		
			64 lines
		
	
	
	
		
			2 KiB
			
		
	
	
	
		
			Haskell
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
	
		
			2 KiB
			
		
	
	
	
		
			Haskell
		
	
	
	
	
	
{- git-remote-tor-annex program
 | 
						|
 -
 | 
						|
 - Copyright 2016 Joey Hess <id@joeyh.name>
 | 
						|
 -
 | 
						|
 - Licensed under the GNU AGPL version 3 or higher.
 | 
						|
 -}
 | 
						|
 | 
						|
module CmdLine.GitRemoteTorAnnex where
 | 
						|
 | 
						|
import Common
 | 
						|
import qualified Annex
 | 
						|
import qualified Git.CurrentRepo
 | 
						|
import P2P.Protocol
 | 
						|
import P2P.IO
 | 
						|
import Utility.Tor
 | 
						|
import Utility.AuthToken
 | 
						|
import Annex.UUID
 | 
						|
import P2P.Address
 | 
						|
import P2P.Auth
 | 
						|
 | 
						|
run :: [String] -> IO ()
 | 
						|
run (_remotename:address:[]) = forever $
 | 
						|
	getLine >>= \case
 | 
						|
		"capabilities" -> putStrLn "connect" >> ready
 | 
						|
		"connect git-upload-pack" -> go UploadPack
 | 
						|
		"connect git-receive-pack" -> go ReceivePack
 | 
						|
		l -> error $ "git-remote-helpers protocol error at " ++ show l
 | 
						|
  where
 | 
						|
	(onionaddress, onionport)
 | 
						|
		| '/' `elem` address = parseAddressPort $
 | 
						|
			reverse $ takeWhile (/= '/') $ reverse address
 | 
						|
		| otherwise = parseAddressPort address
 | 
						|
	go service = do
 | 
						|
		ready
 | 
						|
		connectService onionaddress onionport service >>= \case
 | 
						|
			Right exitcode -> exitWith exitcode
 | 
						|
			Left e -> giveup $ describeProtoFailure e
 | 
						|
	ready = do
 | 
						|
		putStrLn ""
 | 
						|
		hFlush stdout
 | 
						|
		
 | 
						|
run (_remotename:[]) = giveup "remote address not configured"
 | 
						|
run _ = giveup "expected remote name and address parameters"
 | 
						|
 | 
						|
parseAddressPort :: String -> (OnionAddress, OnionPort)
 | 
						|
parseAddressPort s = 
 | 
						|
	let (a, sp) = separate (== ':') s
 | 
						|
	in case readish sp of
 | 
						|
		Nothing -> giveup "onion address must include port number"
 | 
						|
		Just p -> (OnionAddress a, p)
 | 
						|
 | 
						|
connectService :: OnionAddress -> OnionPort -> Service -> IO (Either ProtoFailure ExitCode)
 | 
						|
connectService address port service = do
 | 
						|
	state <- Annex.new =<< Git.CurrentRepo.get
 | 
						|
	Annex.eval state $ do
 | 
						|
		authtoken <- fromMaybe nullAuthToken
 | 
						|
			<$> loadP2PRemoteAuthToken (TorAnnex address port)
 | 
						|
		myuuid <- getUUID
 | 
						|
		g <- Annex.gitRepo
 | 
						|
		conn <- liftIO $ connectPeer g (TorAnnex address port)
 | 
						|
		runst <- liftIO $ mkRunState Client
 | 
						|
		liftIO $ runNetProto runst conn $ auth myuuid authtoken noop >>= \case
 | 
						|
			Just _theiruuid -> connect service stdin stdout
 | 
						|
			Nothing -> giveup $ "authentication failed, perhaps you need to set " ++ p2pAuthTokenEnv
 |