summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
Diffstat (limited to 'Presence')
-rw-r--r--Presence/XMPP.hs14
-rw-r--r--Presence/main.hs15
2 files changed, 20 insertions, 9 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 4db055ea..55aab3d4 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -646,10 +646,12 @@ handlePeer st src snk = do
646 debugL $ "(P) connected " <++> name 646 debugL $ "(P) connected " <++> name
647 session <- newPeerSession session_factory sock 647 session <- newPeerSession session_factory sock
648 648
649 finally ( src $= parseBytes def $$ fromPeer sock session ) 649 didClose <- newTVarIO False
650 finally ( src $= parseBytes def $$ fromPeer sock session didClose )
650 $ do 651 $ do
651 debugL $ "(P) disconnected " <++> name 652 debugL $ "(P) disconnected " <++> name
652 closePeerSession session 653 didc <- readTVarIO didClose
654 when (not didc) $ closePeerSession session
653 655
654 656
655handlePeerPresence session stanza False = do 657handlePeerPresence session stanza False = do
@@ -912,8 +914,8 @@ handlePeerIQGet session tag = do
912 req -> unhandledGet req 914 req -> unhandledGet req
913 915
914fromPeer :: (MonadThrow m,MonadIO m, JabberPeerSession session) => 916fromPeer :: (MonadThrow m,MonadIO m, JabberPeerSession session) =>
915 RestrictedSocket -> session -> Sink XML.Event m () 917 RestrictedSocket -> session -> TVar Bool -> Sink XML.Event m ()
916fromPeer sock session = doNestingXML $ do 918fromPeer sock session didClose = doNestingXML $ do
917 let log = liftIO . debugL . ("(P) " <++>) 919 let log = liftIO . debugL . ("(P) " <++>)
918 withXML $ \begindoc -> do 920 withXML $ \begindoc -> do
919 when (begindoc==EventBeginDocument) $ do 921 when (begindoc==EventBeginDocument) $ do
@@ -922,7 +924,9 @@ fromPeer sock session = doNestingXML $ do
922 withJust (elementAttrs "stream" xml) $ \stream_attrs -> do 924 withJust (elementAttrs "stream" xml) $ \stream_attrs -> do
923 log $ "stream atributes: " <++> bshow stream_attrs 925 log $ "stream atributes: " <++> bshow stream_attrs
924 926
925 let doTimeout = Thunk (closePeerSession session) 927 let doTimeout = Thunk $ do
928 atomically $ writeTVar didClose True
929 closePeerSession session
926 930
927 fix $ \loop -> do 931 fix $ \loop -> do
928 log "waiting for stanza." 932 log "waiting for stanza."
diff --git a/Presence/main.hs b/Presence/main.hs
index 45b8729a..f0dfc9bd 100644
--- a/Presence/main.hs
+++ b/Presence/main.hs
@@ -434,7 +434,11 @@ instance JabberPeerSession PeerSession where
434 me <- fmap (RemotePeer . withoutPort) (getPeerName sock) 434 me <- fmap (RemotePeer . withoutPort) (getPeerName sock)
435 debugL $ "PEER SESSION: open "<++>showPeer me 435 debugL $ "PEER SESSION: open "<++>showPeer me
436 let remotes = remoteUsers state 436 let remotes = remoteUsers state
437 jids <- atomically $ getRefFromMap remotes me (newTVar MM.empty) return 437 (jids,us) <- atomically $ do
438 jids <- getRefFromMap remotes me (newTVar MM.empty) return
439 us <- readTVar (activeUsers state)
440 return (jids,map tupleToJID . Set.toList . Map.keysSet $ us)
441 forM_ us $ sendProbes state (Just me)
438 return $ PeerSession jids me state 442 return $ PeerSession jids me state
439 443
440 closePeerSession session = do 444 closePeerSession session = do
@@ -710,7 +714,7 @@ update_presence locals_greedy subscribers state getStatus =
710 sendPresence chan jid status 714 sendPresence chan jid status
711 debugL $ bshow jid <++> " " <++> bshow status 715 debugL $ bshow jid <++> " " <++> bshow status
712 716
713sendProbes state jid = do 717sendProbes state mbpeer jid = do
714 debugL $ "sending probes for " <++> bshow jid 718 debugL $ "sending probes for " <++> bshow jid
715 withJust (name jid) $ \user -> do 719 withJust (name jid) $ \user -> do
716 let parseHostNameJID' str = do 720 let parseHostNameJID' str = do
@@ -718,7 +722,10 @@ sendProbes state jid = do
718 (fmap Just . parseHostNameJID $ str) 722 (fmap Just . parseHostNameJID $ str)
719 buddies <- do 723 buddies <- do
720 buddies <- ConfigFiles.getBuddies user 724 buddies <- ConfigFiles.getBuddies user
721 fmap catMaybes (mapM parseHostNameJID' buddies) 725 buddies' <- fmap catMaybes (mapM parseHostNameJID' buddies)
726 case mbpeer of
727 Nothing -> return buddies'
728 Just p -> return (filter (\jid-> peer jid == p) buddies')
722 debugL $ "buddies for " <++> bshow jid <++> " = " <++> bshow buddies 729 debugL $ "buddies for " <++> bshow jid <++> " = " <++> bshow buddies
723 wanted <- do 730 wanted <- do
724 wanted <- ConfigFiles.getSolicited user 731 wanted <- ConfigFiles.getSolicited user
@@ -762,7 +769,7 @@ track_login host state e = do
762 update_presence locals_greedy subs departures $ const Offline 769 update_presence locals_greedy subs departures $ const Offline
763 update_presence locals_greedy subs arrivals $ matchResource active_users tty 770 update_presence locals_greedy subs arrivals $ matchResource active_users tty
764 forM_ arrivals 771 forM_ arrivals
765 $ sendProbes state 772 $ sendProbes state Nothing
766 773
767on_chvt state vtnum = do 774on_chvt state vtnum = do
768 let tty = L.snoc "tty" $ intToDigit (fromIntegral vtnum) 775 let tty = L.snoc "tty" $ intToDigit (fromIntegral vtnum)