summaryrefslogtreecommitdiff
path: root/Assistant/XMPP.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-30 13:22:55 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-30 13:22:55 -0400
commitd12b1fb179bc1744f813ea3f616d503d2b0dfe09 (patch)
treedd4087ad7f6bf5883877c1c37e6a11c89cc5f46a /Assistant/XMPP.hs
parenteba8c5d2610dd916401312e590fab2dcb713548c (diff)
add uuid to all xmpp messages
(Except for the actual streaming of receive-pack through XMPP, which can only run once we've gotten an appropriate uuid in a push initiation message.) Pushes are now only initiated when the initiation message comes from a known uuid. This allows multiple distinct repositories to use the same xmpp address. Note: This probably breaks initial push after xmpp pairing, because at that point we may not know about the paired uuid, and so reject the push from it. It won't break in simple cases, because the annex-uuid of the remote is checked. However, when there are multiple clients behind a single xmpp address, only uuid of the first is recorded in annex-uuid, and so any pushes from the others will be rejected (unless the first remote pushes their uuids to us beforehand.
Diffstat (limited to 'Assistant/XMPP.hs')
-rw-r--r--Assistant/XMPP.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/Assistant/XMPP.hs b/Assistant/XMPP.hs
index 9654fdb4b..fbc351931 100644
--- a/Assistant/XMPP.hs
+++ b/Assistant/XMPP.hs
@@ -131,9 +131,12 @@ decodePairingNotification m = parse . words . T.unpack . tagValue
pushMessage :: PushStage -> JID -> JID -> Message
pushMessage = gitAnnexMessage . encode
where
- encode CanPush = gitAnnexTag canPushAttr T.empty
- encode PushRequest = gitAnnexTag pushRequestAttr T.empty
- encode StartingPush = gitAnnexTag startingPushAttr T.empty
+ encode (CanPush u) =
+ gitAnnexTag canPushAttr $ T.pack $ fromUUID u
+ encode (PushRequest u) =
+ gitAnnexTag pushRequestAttr $ T.pack $ fromUUID u
+ encode (StartingPush u) =
+ gitAnnexTag startingPushAttr $ T.pack $ fromUUID u
encode (ReceivePackOutput n b) =
gitAnnexTagContent receivePackAttr (val n) $ encodeTagContent b
encode (SendPackOutput n b) =
@@ -157,11 +160,11 @@ decodeMessage m = decode =<< gitAnnexTagInfo m
, receivePackDoneAttr
]
[ decodePairingNotification
- , pushdecoder $ const $ Just CanPush
- , pushdecoder $ const $ Just PushRequest
- , pushdecoder $ const $ Just StartingPush
- , pushdecoder $ gen ReceivePackOutput
- , pushdecoder $ gen SendPackOutput
+ , pushdecoder $ gen CanPush
+ , pushdecoder $ gen PushRequest
+ , pushdecoder $ gen StartingPush
+ , pushdecoder $ seqgen ReceivePackOutput
+ , pushdecoder $ seqgen SendPackOutput
, pushdecoder $
fmap (ReceivePackDone . decodeExitCode) . readish .
T.unpack . tagValue
@@ -169,7 +172,8 @@ decodeMessage m = decode =<< gitAnnexTagInfo m
pushdecoder a m' i = Pushing
<$> (formatJID <$> messageFrom m')
<*> a i
- gen c i = do
+ gen c = Just . c . toUUID . T.unpack . tagValue
+ seqgen c i = do
packet <- decodeTagContent $ tagElement i
let seqnum = fromMaybe 0 $ readish $ T.unpack $ tagValue i
return $ c seqnum packet