summaryrefslogtreecommitdiff
path: root/xmppServer.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-03-04 02:22:30 -0500
committerjoe <joe@jerkface.net>2014-03-04 02:22:30 -0500
commit33fea88dca26e3cc8a000ec1c6e043a9759d252c (patch)
treec22ea7bd569410747485ac08528c19076be05007 /xmppServer.hs
parentcefae0f42db7cae156dfd0c42c9bea3eb534b21c (diff)
Repaired broken stanzaFromList, probes are sent.
Diffstat (limited to 'xmppServer.hs')
-rw-r--r--xmppServer.hs27
1 files changed, 17 insertions, 10 deletions
diff --git a/xmppServer.hs b/xmppServer.hs
index b812e584..a30d15d0 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -15,6 +15,7 @@ import Network.Socket
15 , SockAddr(..) 15 , SockAddr(..)
16 ) 16 )
17import System.Endian (fromBE32) 17import System.Endian (fromBE32)
18import Data.List (nub)
18import Data.Monoid ( (<>) ) 19import Data.Monoid ( (<>) )
19import qualified Data.Text as Text 20import qualified Data.Text as Text
20import qualified Data.Text.IO as Text 21import qualified Data.Text.IO as Text
@@ -244,35 +245,41 @@ getSolicited' = textAdapter ConfigFiles.getSolicited
244 245
245sendProbesAndSolicitations state k laddr chan = do 246sendProbesAndSolicitations state k laddr chan = do
246 -- get all buddies & solicited matching k for all users 247 -- get all buddies & solicited matching k for all users
247 runTraversableT $ do 248 xs <- runTraversableT $ do
248 cbu <- lift $ atomically $ readTVar $ clientsByUser state 249 cbu <- lift $ atomically $ readTVar $ clientsByUser state
249 user <- liftT $ Map.keys cbu 250 user <- liftT $ Map.keys cbu
250 (isbud,getter) <- liftT [(True ,getBuddies' ) 251 (isbud,getter) <- liftT [(True ,getBuddies' )
251 ,(False,getSolicited')] 252 ,(False,getSolicited')]
252 bud <- liftMT $ getter user 253 bud <- liftMT $ getter user
253 let (u,h,r) = splitJID bud 254 let (u,h,r) = splitJID bud
254 addr <- liftMT $ resolvePeer h 255 addr <- liftMT $ nub `fmap` resolvePeer h
255 liftT $ guard (PeerKey addr == k) 256 liftT $ guard (PeerKey addr == k)
257 -- Note: Earlier I was tempted to do all the IO
258 -- within the TraversableT monad. That apparently
259 -- is a bad idea. Perhaps due to laziness and an
260 -- unforced list? Instead, we will return a list
261 -- of (Bool,Text) for processing outside.
262 return (isbud,u)
263 -- XXX: The following O(n²) nub may be a little
264 -- too onerous.
265 forM_ (nub xs) $ \(isbud,u) -> do
256 let make = if isbud then presenceProbe 266 let make = if isbud then presenceProbe
257 else presenceSolicitation 267 else presenceSolicitation
258 toh = peerKeyToText k 268 toh = peerKeyToText k
259 jid = unsplitJID (u,toh,r) 269 jid = unsplitJID (u,toh,Nothing)
260 me = addrToText laddr 270 me = addrToText laddr
261 stanza <- lift $ make me jid 271 stanza <- make me jid
262 -- send probes for buddies, solicitations for solicited. 272 -- send probes for buddies, solicitations for solicited.
263 lift $ atomically $ writeTChan chan stanza 273 putStrLn $ "probing "++show k++" for: " ++ show (isbud,jid)
264 return () 274 atomically $ writeTChan chan stanza
275 -- reverse xs `seq` return ()
265 276
266newConn state k addr outchan = do 277newConn state k addr outchan = do
267 atomically $ modifyTVar' (keyToChan state) 278 atomically $ modifyTVar' (keyToChan state)
268 $ Map.insert k Conn { connChan = outchan 279 $ Map.insert k Conn { connChan = outchan
269 , auxAddr = addr } 280 , auxAddr = addr }
270 {-
271 -- DISABLED FOR NOW
272 -- (probably is terminating a thread via exception)
273 when (isPeerKey k) 281 when (isPeerKey k)
274 $ sendProbesAndSolicitations state k addr outchan 282 $ sendProbesAndSolicitations state k addr outchan
275 -}
276 283
277eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k 284eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k
278 285