xmpp: --debug now enables a sanitized dump of the XMPP protocol
So I can debug these damn google talk presence issues.
This commit is contained in:
parent
7cfa1d5363
commit
e3354cf19c
3 changed files with 28 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex XMPP client
|
{- git-annex XMPP client
|
||||||
-
|
-
|
||||||
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
- Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -33,10 +33,6 @@ import qualified Data.Map as M
|
||||||
import qualified Git.Branch
|
import qualified Git.Branch
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
|
|
||||||
{- Whether to include verbose protocol dump in debug output. -}
|
|
||||||
protocolDebug :: Bool
|
|
||||||
protocolDebug = False
|
|
||||||
|
|
||||||
xmppClientThread :: UrlRenderer -> NamedThread
|
xmppClientThread :: UrlRenderer -> NamedThread
|
||||||
xmppClientThread urlrenderer = namedThread "XMPPClient" $
|
xmppClientThread urlrenderer = namedThread "XMPPClient" $
|
||||||
restartableClient . xmppClient urlrenderer =<< getAssistant id
|
restartableClient . xmppClient urlrenderer =<< getAssistant id
|
||||||
|
@ -96,8 +92,8 @@ xmppClient urlrenderer d creds =
|
||||||
|
|
||||||
receivenotifications selfjid = forever $ do
|
receivenotifications selfjid = forever $ do
|
||||||
l <- decodeStanza selfjid <$> getStanza
|
l <- decodeStanza selfjid <$> getStanza
|
||||||
when protocolDebug $
|
inAssistant $ debug
|
||||||
inAssistant $ debug ["received:", show l]
|
["received:", show $ map sanitizeXMPPEvent l]
|
||||||
mapM_ (handle selfjid) l
|
mapM_ (handle selfjid) l
|
||||||
|
|
||||||
handle selfjid (PresenceMessage p) = do
|
handle selfjid (PresenceMessage p) = do
|
||||||
|
@ -122,8 +118,13 @@ xmppClient urlrenderer d creds =
|
||||||
(stored, sent) <- inAssistant $
|
(stored, sent) <- inAssistant $
|
||||||
checkImportantNetMessages (formatJID (baseJID jid), c)
|
checkImportantNetMessages (formatJID (baseJID jid), c)
|
||||||
forM_ (S.toList $ S.difference stored sent) $ \msg -> do
|
forM_ (S.toList $ S.difference stored sent) $ \msg -> do
|
||||||
inAssistant $ debug ["sending to new client:", show c, show msg]
|
let msg' = readdressNetMessage msg c
|
||||||
a <- inAssistant $ convertNetMsg (readdressNetMessage msg c) selfjid
|
inAssistant $ debug
|
||||||
|
[ "sending to new client:"
|
||||||
|
, show c
|
||||||
|
, show $ sanitizeNetMessage msg'
|
||||||
|
]
|
||||||
|
a <- inAssistant $ convertNetMsg msg' selfjid
|
||||||
a
|
a
|
||||||
inAssistant $ sentImportantNetMessage msg c
|
inAssistant $ sentImportantNetMessage msg c
|
||||||
resendImportantMessages _ _ = noop
|
resendImportantMessages _ _ = noop
|
||||||
|
@ -136,6 +137,10 @@ data XMPPEvent
|
||||||
| ProtocolError ReceivedStanza
|
| ProtocolError ReceivedStanza
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
|
sanitizeXMPPEvent :: XMPPEvent -> XMPPEvent
|
||||||
|
sanitizeXMPPEvent (GotNetMessage m) = GotNetMessage $ sanitizeNetMessage m
|
||||||
|
sanitizeXMPPEvent v = v
|
||||||
|
|
||||||
{- Decodes an XMPP stanza into one or more events. -}
|
{- Decodes an XMPP stanza into one or more events. -}
|
||||||
decodeStanza :: JID -> ReceivedStanza -> [XMPPEvent]
|
decodeStanza :: JID -> ReceivedStanza -> [XMPPEvent]
|
||||||
decodeStanza selfjid s@(ReceivedPresence p)
|
decodeStanza selfjid s@(ReceivedPresence p)
|
||||||
|
@ -173,8 +178,7 @@ decodeStanza _ s = [Unknown s]
|
||||||
relayNetMessage :: JID -> Assistant (XMPP ())
|
relayNetMessage :: JID -> Assistant (XMPP ())
|
||||||
relayNetMessage selfjid = do
|
relayNetMessage selfjid = do
|
||||||
msg <- waitNetMessage
|
msg <- waitNetMessage
|
||||||
when protocolDebug $
|
debug ["sending:", show $ sanitizeNetMessage msg]
|
||||||
debug ["sending:", show msg]
|
|
||||||
handleImportant msg
|
handleImportant msg
|
||||||
convert msg
|
convert msg
|
||||||
where
|
where
|
||||||
|
@ -189,8 +193,7 @@ relayNetMessage selfjid = do
|
||||||
then do
|
then do
|
||||||
clients <- maybe [] (S.toList . buddyAssistants)
|
clients <- maybe [] (S.toList . buddyAssistants)
|
||||||
<$> getBuddy (genBuddyKey tojid) <<~ buddyList
|
<$> getBuddy (genBuddyKey tojid) <<~ buddyList
|
||||||
when protocolDebug $
|
debug ["exploded undirected message to clients", show clients]
|
||||||
debug ["exploded undirected message to clients", show clients]
|
|
||||||
return $ forM_ (clients) $ \(Client jid) ->
|
return $ forM_ (clients) $ \(Client jid) ->
|
||||||
putStanza $ pushMessage pushstage jid selfjid
|
putStanza $ pushMessage pushstage jid selfjid
|
||||||
else return $ putStanza $ pushMessage pushstage tojid selfjid
|
else return $ putStanza $ pushMessage pushstage tojid selfjid
|
||||||
|
|
|
@ -14,6 +14,7 @@ import Data.Text (Text)
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import Control.Concurrent.MSampleVar
|
import Control.Concurrent.MSampleVar
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
|
import qualified Data.ByteString.Char8 as B8
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
|
@ -60,6 +61,16 @@ readdressNetMessage (PairingNotification stage _ uuid) c = PairingNotification s
|
||||||
readdressNetMessage (Pushing _ stage) c = Pushing c stage
|
readdressNetMessage (Pushing _ stage) c = Pushing c stage
|
||||||
readdressNetMessage m _ = m
|
readdressNetMessage m _ = m
|
||||||
|
|
||||||
|
{- Convert a NetMessage to something that can be logged. -}
|
||||||
|
sanitizeNetMessage :: NetMessage -> NetMessage
|
||||||
|
sanitizeNetMessage (Pushing c stage) = Pushing c $ case stage of
|
||||||
|
ReceivePackOutput _ -> ReceivePackOutput elided
|
||||||
|
SendPackOutput _ -> SendPackOutput elided
|
||||||
|
s -> s
|
||||||
|
where
|
||||||
|
elided = B8.pack "<elided>"
|
||||||
|
sanitizeNetMessage m = m
|
||||||
|
|
||||||
{- Things that initiate either side of a push, but do not actually send data. -}
|
{- Things that initiate either side of a push, but do not actually send data. -}
|
||||||
isPushInitiation :: PushStage -> Bool
|
isPushInitiation :: PushStage -> Bool
|
||||||
isPushInitiation CanPush = True
|
isPushInitiation CanPush = True
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -8,6 +8,7 @@ git-annex (4.20130315) UNRELEASED; urgency=low
|
||||||
* Add incrementalbackup repository group.
|
* Add incrementalbackup repository group.
|
||||||
* webapp: Encourage user to install git-annex on a server when adding
|
* webapp: Encourage user to install git-annex on a server when adding
|
||||||
a ssh server, rather than just funneling them through to rsync.
|
a ssh server, rather than just funneling them through to rsync.
|
||||||
|
* xmpp: --debug now enables a sanitized dump of the XMPP protocol
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Fri, 15 Mar 2013 00:10:07 -0400
|
-- Joey Hess <joeyh@debian.org> Fri, 15 Mar 2013 00:10:07 -0400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue