diff options
author | joe <joe@jerkface.net> | 2014-03-03 15:02:53 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-03-03 15:02:53 -0500 |
commit | 8b7d614ad7722b426e88ecb536e17b381e23e138 (patch) | |
tree | d0640f41debad4565a807acba013703105ebd5da | |
parent | 9a3ef90169a1cab8f62ca4aa465f15fb75e33112 (diff) |
send probes and solicitations
-rw-r--r-- | Presence/XMPPServer.hs | 15 | ||||
-rw-r--r-- | xmppServer.hs | 34 |
2 files changed, 35 insertions, 14 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index 5dda4f4d..b895597f 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -19,6 +19,8 @@ module XMPPServer | |||
19 | , addrToText | 19 | , addrToText |
20 | , sendModifiedStanzaToPeer | 20 | , sendModifiedStanzaToPeer |
21 | , sendModifiedStanzaToClient | 21 | , sendModifiedStanzaToClient |
22 | , presenceProbe | ||
23 | , presenceSolicitation | ||
22 | ) where | 24 | ) where |
23 | 25 | ||
24 | import Debug.Trace | 26 | import Debug.Trace |
@@ -1025,6 +1027,19 @@ simulateChatError err mfrom = | |||
1025 | ] | 1027 | ] |
1026 | 1028 | ||
1027 | 1029 | ||
1030 | presenceSolicitation = presenceStanza (PresenceRequestSubscription True) "subscribe" | ||
1031 | |||
1032 | presenceProbe = presenceStanza PresenceRequestStatus "probe" | ||
1033 | |||
1034 | presenceStanza stanza_type type_attr me jid = | ||
1035 | stanzaFromList stanza_type | ||
1036 | [ EventBeginElement "{jabber:server}presence" | ||
1037 | [ attr "to" jid | ||
1038 | , attr "from" me | ||
1039 | , attr "type" type_attr | ||
1040 | ] | ||
1041 | , EventEndElement "{jabber:server}presence" ] | ||
1042 | |||
1028 | forkConnection :: Server ConnectionKey SockAddr | 1043 | forkConnection :: Server ConnectionKey SockAddr |
1029 | -> XMPPServerParameters | 1044 | -> XMPPServerParameters |
1030 | -> ConnectionKey | 1045 | -> ConnectionKey |
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 | |||
4 | import Control.Concurrent.STM | 4 | import Control.Concurrent.STM |
5 | import Control.Concurrent.STM.TMVar | 5 | import Control.Concurrent.STM.TMVar |
6 | import Control.Monad.Trans.Resource (runResourceT) | 6 | import Control.Monad.Trans.Resource (runResourceT) |
7 | import Control.Monad.Trans | ||
7 | import Control.Monad.IO.Class (MonadIO, liftIO) | 8 | import Control.Monad.IO.Class (MonadIO, liftIO) |
8 | import Network.Socket | 9 | import Network.Socket |
9 | ( addrAddress | 10 | ( addrAddress |
@@ -240,21 +241,26 @@ getBuddies' = textAdapter ConfigFiles.getBuddies | |||
240 | getSolicited' :: Text -> IO [Text] | 241 | getSolicited' :: Text -> IO [Text] |
241 | getSolicited' = textAdapter ConfigFiles.getSolicited | 242 | getSolicited' = textAdapter ConfigFiles.getSolicited |
242 | 243 | ||
243 | sendProbesAndSolicitations state k chan = do | 244 | sendProbesAndSolicitations 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 | ||
260 | newConn state k addr outchan = do | 266 | newConn 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 | ||
267 | eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k | 273 | eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k |
268 | 274 | ||