summaryrefslogtreecommitdiff
path: root/xmppServer.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-03-03 15:02:53 -0500
committerjoe <joe@jerkface.net>2014-03-03 15:02:53 -0500
commit8b7d614ad7722b426e88ecb536e17b381e23e138 (patch)
treed0640f41debad4565a807acba013703105ebd5da /xmppServer.hs
parent9a3ef90169a1cab8f62ca4aa465f15fb75e33112 (diff)
send probes and solicitations
Diffstat (limited to 'xmppServer.hs')
-rw-r--r--xmppServer.hs34
1 files changed, 20 insertions, 14 deletions
diff --git a/xmppServer.hs b/xmppServer.hs
index 0f2b7c89..d450988c 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -4,6 +4,7 @@ import System.Posix.Signals
4import Control.Concurrent.STM 4import Control.Concurrent.STM
5import Control.Concurrent.STM.TMVar 5import Control.Concurrent.STM.TMVar
6import Control.Monad.Trans.Resource (runResourceT) 6import Control.Monad.Trans.Resource (runResourceT)
7import Control.Monad.Trans
7import Control.Monad.IO.Class (MonadIO, liftIO) 8import Control.Monad.IO.Class (MonadIO, liftIO)
8import Network.Socket 9import Network.Socket
9 ( addrAddress 10 ( addrAddress
@@ -240,21 +241,26 @@ getBuddies' = textAdapter ConfigFiles.getBuddies
240getSolicited' :: Text -> IO [Text] 241getSolicited' :: Text -> IO [Text]
241getSolicited' = textAdapter ConfigFiles.getSolicited 242getSolicited' = textAdapter ConfigFiles.getSolicited
242 243
243sendProbesAndSolicitations state k chan = do 244sendProbesAndSolicitations state k laddr chan = do
244 cbu <- atomically $ readTVar $ clientsByUser state 245 cbu <- atomically $ readTVar $ clientsByUser state
245 -- get all buddies & solicited matching k for all users 246 -- get all buddies & solicited matching k for all users
246 us <- runTraversableT $ do 247 runTraversableT $ do
247 user <- liftT $ Map.keys cbu 248 user <- liftT $ Map.keys cbu
248 (isbud,getter) <- liftT [(True ,getBuddies' ) 249 (isbud,getter) <- liftT [(True ,getBuddies' )
249 ,(False,getSolicited')] 250 ,(False,getSolicited')]
250 bud <- liftMT $ getter user 251 bud <- liftMT $ getter user
251 let (u,h,r) = splitJID bud 252 let (u,h,r) = splitJID bud
252 addr <- liftMT $ resolvePeer h 253 addr <- liftMT $ resolvePeer h
253 liftT $ guard (PeerKey addr == k) 254 liftT $ guard (PeerKey addr == k)
254 return (isbud,u) 255 -- return (isbud,u)
255 256 let make = if isbud then presenceProbe
256 let _ = us :: [(Bool,Maybe UserName)] 257 else presenceSolicitation
257 -- send probes for buddies, solicitations for solicited. 258 toh = peerKeyToText k
259 jid = unsplitJID (u,toh,r)
260 me = addrToText laddr
261 stanza <- lift $ make me jid
262 -- send probes for buddies, solicitations for solicited.
263 lift $ atomically $ writeTChan chan stanza
258 return () 264 return ()
259 265
260newConn state k addr outchan = do 266newConn state k addr outchan = do
@@ -262,7 +268,7 @@ newConn state k addr outchan = do
262 $ Map.insert k Conn { connChan = outchan 268 $ Map.insert k Conn { connChan = outchan
263 , auxAddr = addr } 269 , auxAddr = addr }
264 when (isPeerKey k) 270 when (isPeerKey k)
265 $ sendProbesAndSolicitations state k outchan 271 $ sendProbesAndSolicitations state k addr outchan
266 272
267eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k 273eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k
268 274