summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-11-18 18:48:55 -0500
committerjoe <joe@jerkface.net>2013-11-18 18:48:55 -0500
commit2eec39f7eb0f306752fa4223db2c39b517ac353e (patch)
tree8866fc6866fdc9790bf7a19adabf512fa4cf3444
parent274f90dca1a12844c797c86f12754475b42a65d8 (diff)
updates buddy list on ping timeout.
TODO: send probe when in-bound peer connection re-appears.
-rw-r--r--Presence/XMPP.hs8
-rw-r--r--Presence/XMPPTypes.hs7
2 files changed, 12 insertions, 3 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index c7525159..4db055ea 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -922,12 +922,14 @@ fromPeer sock session = doNestingXML $ do
922 withJust (elementAttrs "stream" xml) $ \stream_attrs -> do 922 withJust (elementAttrs "stream" xml) $ \stream_attrs -> do
923 log $ "stream atributes: " <++> bshow stream_attrs 923 log $ "stream atributes: " <++> bshow stream_attrs
924 924
925 let doTimeout = Thunk (closePeerSession session)
926
925 fix $ \loop -> do 927 fix $ \loop -> do
926 log "waiting for stanza." 928 log "waiting for stanza."
927 whenJust nextElement $ \stanza -> do 929 whenJust nextElement $ \stanza -> do
928 stanza_lvl <- nesting 930 stanza_lvl <- nesting
929 931
930 liftIO $ sendPeerMessage session (ActivityBump sock) -- reset ping timer 932 liftIO $ sendPeerMessage session (ActivityBump doTimeout) -- reset ping timer
931 933
932 let unhandledStanza = do 934 let unhandledStanza = do
933 xs <- gatherElement stanza Seq.empty 935 xs <- gatherElement stanza Seq.empty
@@ -1181,7 +1183,9 @@ toPeer sock cache chan fail = do
1181 remote <- liftIO $ getPeerName sock 1183 remote <- liftIO $ getPeerName sock
1182 liftIO . debugL $ "PING TIMEOUT: " <++> showPeer (RemotePeer remote) 1184 liftIO . debugL $ "PING TIMEOUT: " <++> showPeer (RemotePeer remote)
1183 fromsock <- liftIO $ atomically $ readTMVar sockref 1185 fromsock <- liftIO $ atomically $ readTMVar sockref
1184 liftIO $ sClose fromsock 1186 -- liftIO $ sClose fromsock
1187 liftIO $ runThunk fromsock
1188
1185 return () -- PING TIMEOUT (loop quits) 1189 return () -- PING TIMEOUT (loop quits)
1186 x -> error ("What? "++show x) 1190 x -> error ("What? "++show x)
1187 where makePing = do 1191 where makePing = do
diff --git a/Presence/XMPPTypes.hs b/Presence/XMPPTypes.hs
index f6ffe66e..d9ebbce9 100644
--- a/Presence/XMPPTypes.hs
+++ b/Presence/XMPPTypes.hs
@@ -284,9 +284,14 @@ data OutBoundMessage = OutBoundPresence Presence
284 | Pong JID JID (Maybe Content) 284 | Pong JID JID (Maybe Content)
285 | Unsupported JID JID (Maybe Content) XML.Name 285 | Unsupported JID JID (Maybe Content) XML.Name
286 | Disconnect 286 | Disconnect
287 | ActivityBump RestrictedSocket 287 | ActivityBump Thunk
288 deriving Prelude.Show 288 deriving Prelude.Show
289 289
290newtype Thunk = Thunk { runThunk :: IO () }
291
292instance Show Thunk where
293 show s = "thunk"
294
290getNamesForPeer :: Peer -> IO [S.ByteString] 295getNamesForPeer :: Peer -> IO [S.ByteString]
291getNamesForPeer LocalHost = fmap ((:[]) . S.pack) getHostName 296getNamesForPeer LocalHost = fmap ((:[]) . S.pack) getHostName
292getNamesForPeer peer@(RemotePeer addr) = do 297getNamesForPeer peer@(RemotePeer addr) = do