summaryrefslogtreecommitdiff
path: root/Presence/XMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPP.hs')
-rw-r--r--Presence/XMPP.hs29
1 files changed, 19 insertions, 10 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 853b015a..c7525159 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -933,7 +933,7 @@ fromPeer sock session = doNestingXML $ do
933 xs <- gatherElement stanza Seq.empty 933 xs <- gatherElement stanza Seq.empty
934 prettyPrint "P: " (toList xs) 934 prettyPrint "P: " (toList xs)
935 case () of 935 case () of
936 _ | stanza `isIQOf` iqTypeGet -> handlePeerIQGet session stanza 936 _ | stanza `isServerIQOf` iqTypeGet -> handlePeerIQGet session stanza
937 _ | stanza `isPresenceOf` presenceTypeOnline 937 _ | stanza `isPresenceOf` presenceTypeOnline
938 -> handlePeerPresence session stanza True 938 -> handlePeerPresence session stanza True
939 _ | stanza `isPresenceOf` presenceTypeOffline 939 _ | stanza `isPresenceOf` presenceTypeOffline
@@ -985,7 +985,7 @@ instance CommandCache CachedMessages where
985 updateCache (Rejection from to) cache = 985 updateCache (Rejection from to) cache =
986 cache { approvals= mmInsert (False,from) to $ approvals cache } 986 cache { approvals= mmInsert (False,from) to $ approvals cache }
987 updateCache (OutBoundMessage msg) cache = cache -- TODO: cache chat? 987 updateCache (OutBoundMessage msg) cache = cache -- TODO: cache chat?
988 updateCache (Pong _ _ _) cache = cache -- pings are not cached 988 updateCache (Pong _ _ _) cache = trace "(DISCARDING Pong)" cache -- pings are not cached
989 updateCache (Unsupported _ _ _ _) cache = cache -- error messages are not cached 989 updateCache (Unsupported _ _ _ _) cache = cache -- error messages are not cached
990 updateCache (ActivityBump sock) cache = cache 990 updateCache (ActivityBump sock) cache = cache
991 991
@@ -1078,7 +1078,8 @@ toPeer sock cache chan fail = do
1078 sendOrFail (xmlifyMessageForPeer sock msg) 1078 sendOrFail (xmlifyMessageForPeer sock msg)
1079 (OutBoundMessage msg) 1079 (OutBoundMessage msg)
1080 1080
1081 sendPong from to mid = 1081 sendPong from to mid = do
1082 liftIO . debugL $ "SEND PONG"
1082 sendOrFail (xmlifyPong sock from to mid) 1083 sendOrFail (xmlifyPong sock from to mid)
1083 (Pong from to mid) 1084 (Pong from to mid)
1084 where 1085 where
@@ -1146,9 +1147,11 @@ toPeer sock cache chan fail = do
1146 1147
1147 sockref <- liftIO $ atomically newEmptyTMVar 1148 sockref <- liftIO $ atomically newEmptyTMVar
1148 let bump fromsock = do 1149 let bump fromsock = do
1149 remote <- getPeerName sock 1150 remote <- liftIO $ catchIO (fmap Just $ getPeerName sock)
1150 debugL $ "PING BUMP" <++> showPeer (RemotePeer remote) 1151 (\_ -> return Nothing)
1152 debugL $ "PING BUMP" <++?> fmap (showPeer . RemotePeer) remote
1151 timer <- atomically $ do 1153 timer <- atomically $ do
1154 tryTakeTMVar sockref
1152 putTMVar sockref fromsock 1155 putTMVar sockref fromsock
1153 (timer,v) <- readTVar pingref 1156 (timer,v) <- readTVar pingref
1154 writeTVar pingref (timer,0) 1157 writeTVar pingref (timer,0)
@@ -1160,23 +1163,27 @@ toPeer sock cache chan fail = do
1160 return v 1163 return v
1161 1164
1162 fix $ \loop -> do 1165 fix $ \loop -> do
1166 liftIO . debugStr $ "LOOP waiting..."
1163 event <- lift . atomically $ orElse (Left `fmap` readTChan chan) 1167 event <- lift . atomically $ orElse (Left `fmap` readTChan chan)
1164 (Right `fmap` waitPing) 1168 (Right `fmap` waitPing)
1169 liftIO . debugStr $ "LOOP event = " ++ show event
1165 let sendPing n = do 1170 let sendPing n = do
1166 ping_timer <- liftIO $ newDelay five_sec
1167 liftIO . atomically $ writeTVar pingref (ping_timer,1)
1168 case n of 1171 case n of
1169 0 -> do 1172 0 -> do
1170 ping <- liftIO makePing 1173 ping <- liftIO makePing
1171 yield ping 1174 yield ping
1175 liftIO . debugL $ "SEND PING"
1172 prettyPrint ">P: " ping 1176 prettyPrint ">P: " ping
1177 ping_timer <- liftIO $ newDelay five_sec
1178 liftIO . atomically $ writeTVar pingref (ping_timer,1)
1173 loop 1179 loop
1174 _ -> do 1180 1 -> do
1175 remote <- liftIO $ getPeerName sock 1181 remote <- liftIO $ getPeerName sock
1176 liftIO . debugL $ "PING TIMEOUT: " <++> showPeer (RemotePeer remote) 1182 liftIO . debugL $ "PING TIMEOUT: " <++> showPeer (RemotePeer remote)
1177 fromsock <- liftIO $ atomically $ readTMVar sockref 1183 fromsock <- liftIO $ atomically $ readTMVar sockref
1178 liftIO $ sClose fromsock 1184 liftIO $ sClose fromsock
1179 return () -- PING TIMEOUT (loop quits) 1185 return () -- PING TIMEOUT (loop quits)
1186 x -> error ("What? "++show x)
1180 where makePing = do 1187 where makePing = do
1181 addr <- getSocketName sock 1188 addr <- getSocketName sock
1182 remote <- getPeerName sock 1189 remote <- getPeerName sock
@@ -1188,7 +1195,7 @@ toPeer sock cache chan fail = do
1188 $ (case mid of 1195 $ (case mid of
1189 Just c -> (("id",[c]):) 1196 Just c -> (("id",[c]):)
1190 _ -> id ) 1197 _ -> id )
1191 [("type",[ContentText "error"]) 1198 [ ("type",[ContentText "get"])
1192 , attr "to" to 1199 , attr "to" to
1193 , attr "from" from 1200 , attr "from" from
1194 ] 1201 ]
@@ -1211,7 +1218,9 @@ toPeer sock cache chan fail = do
1211 liftIO . debugL $ "sending rejection "<++>bshow (from,to) 1218 liftIO . debugL $ "sending rejection "<++>bshow (from,to)
1212 sendApproval False from to 1219 sendApproval False from to
1213 OutBoundMessage msg -> sendMessage msg 1220 OutBoundMessage msg -> sendMessage msg
1214 Pong from to mid -> sendPong from to mid 1221 Pong from to mid -> do
1222 liftIO . debugL $ "sending pong "<++>bshow (from,to)
1223 sendPong from to mid
1215 Unsupported from to mid tag -> sendUnsupported from to mid tag 1224 Unsupported from to mid tag -> sendUnsupported from to mid tag
1216 Disconnect -> return () 1225 Disconnect -> return ()
1217 ActivityBump fromsock -> liftIO (bump fromsock) 1226 ActivityBump fromsock -> liftIO (bump fromsock)