From 46f3063131f7711208c1134b31caf999e375306d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Dec 2016 16:02:43 -0400 Subject: remotedaemon: git change detection over tor hidden service --- P2P/Address.hs | 7 +++++-- P2P/Protocol.hs | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'P2P') diff --git a/P2P/Address.hs b/P2P/Address.hs index 09ffc7973..1b1f66059 100644 --- a/P2P/Address.hs +++ b/P2P/Address.hs @@ -37,15 +37,18 @@ class FormatP2PAddress a where instance FormatP2PAddress P2PAddress where formatP2PAddress (TorAnnex (OnionAddress onionaddr) onionport) = - "tor-annex::" ++ onionaddr ++ ":" ++ show onionport + torAnnexScheme ++ ":" ++ onionaddr ++ ":" ++ show onionport unformatP2PAddress s - | "tor-annex::" `isPrefixOf` s = do + | (torAnnexScheme ++ ":") `isPrefixOf` s = do let s' = dropWhile (== ':') $ dropWhile (/= ':') s let (onionaddr, ps) = separate (== ':') s' onionport <- readish ps return (TorAnnex (OnionAddress onionaddr) onionport) | otherwise = Nothing +torAnnexScheme :: String +torAnnexScheme = "tor-annex:" + instance FormatP2PAddress P2PAddressAuth where formatP2PAddress (P2PAddressAuth addr authtoken) = formatP2PAddress addr ++ ":" ++ T.unpack (fromAuthToken authtoken) diff --git a/P2P/Protocol.hs b/P2P/Protocol.hs index d8be3ff42..c3c362f37 100644 --- a/P2P/Protocol.hs +++ b/P2P/Protocol.hs @@ -441,6 +441,16 @@ sendSuccess :: Bool -> Proto () sendSuccess True = net $ sendMessage SUCCESS sendSuccess False = net $ sendMessage FAILURE +notifyChange :: Proto (Maybe ChangedRefs) +notifyChange = do + net $ sendMessage NOTIFYCHANGE + ack <- net receiveMessage + case ack of + CHANGED rs -> return (Just rs) + _ -> do + net $ sendMessage (ERROR "expected CHANGED") + return Nothing + connect :: Service -> Handle -> Handle -> Proto ExitCode connect service hin hout = do net $ sendMessage (CONNECT service) -- cgit v1.2.3