summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/DNSCache.hs17
-rw-r--r--Presence/XMPPServer.hs4
-rw-r--r--xmppServer.hs14
3 files changed, 20 insertions, 15 deletions
diff --git a/Presence/DNSCache.hs b/Presence/DNSCache.hs
index 35493b19..854aa6c3 100644
--- a/Presence/DNSCache.hs
+++ b/Presence/DNSCache.hs
@@ -6,6 +6,7 @@ module DNSCache
6 , newDNSCache 6 , newDNSCache
7 , parseAddress 7 , parseAddress
8 , strip_brackets 8 , strip_brackets
9 , withPort
9 ) where 10 ) where
10 11
11import Control.Concurrent 12import Control.Concurrent
@@ -40,9 +41,8 @@ data DNSCache =
40 41
41newDNSCache :: IO DNSCache 42newDNSCache :: IO DNSCache
42newDNSCache = do 43newDNSCache = do
43 atomically $ do 44 fcache <- newTVarIO Map.empty
44 fcache <- newTVar Map.empty 45 rcache <- newTVarIO Map.empty
45 rcache <- newTVar Map.empty
46 return DNSCache { fcache=fcache, rcache=rcache } 46 return DNSCache { fcache=fcache, rcache=rcache }
47 47
48equivBy f a b = f a == f b 48equivBy f a b = f a == f b
@@ -64,13 +64,14 @@ dnsObserve :: DNSCache -> Bool -> TimeStamp -> [(Text,SockAddr)] -> STM ()
64dnsObserve dns withScrub utc obs = do 64dnsObserve dns withScrub utc obs = do
65 f <- readTVar $ fcache dns 65 f <- readTVar $ fcache dns
66 r <- readTVar $ rcache dns 66 r <- readTVar $ rcache dns
67 let gs = do 67 let obs' = map (\(n,a)->(n,a `withPort` 0)) obs
68 g <- groupBy (equivBy fst) $ sortBy (comparing fst) obs 68 gs = do
69 g <- groupBy (equivBy fst) $ sortBy (comparing fst) obs'
69 (n,_) <- take 1 g 70 (n,_) <- take 1 g
70 return (n,map snd g) 71 return (n,map snd g)
71 f' = foldl' updatef f gs 72 f' = foldl' updatef f gs
72 hs = do 73 hs = do
73 h <- groupBy (equivBy snd) $ sortBy (comparing snd) obs 74 h <- groupBy (equivBy snd) $ sortBy (comparing snd) obs'
74 (_,a) <- take 1 h 75 (_,a) <- take 1 h
75 return (a,map fst h) 76 return (a,map fst h)
76 r' = foldl' updater r hs 77 r' = foldl' updater r hs
@@ -206,3 +207,7 @@ parseAddress addr_str = do
206 (Just "0") 207 (Just "0")
207 return . listToMaybe $ map addrAddress info 208 return . listToMaybe $ map addrAddress info
208 209
210withPort :: SockAddr -> Int -> SockAddr
211withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a
212withPort (SockAddrInet6 _ a b c) port = SockAddrInet6 (toEnum port) a b c
213
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index efd865d8..bfaaa751 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -76,10 +76,6 @@ import ControlMaybe
76import LockedChan 76import LockedChan
77import PeerResolve 77import PeerResolve
78 78
79withPort :: SockAddr -> Int -> SockAddr
80withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a
81withPort (SockAddrInet6 _ a b c) port = SockAddrInet6 (toEnum port) a b c
82
83 79
84peerport :: PortNumber 80peerport :: PortNumber
85peerport = 5269 81peerport = 5269
diff --git a/xmppServer.hs b/xmppServer.hs
index babde683..1dfb6496 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -163,6 +163,12 @@ chooseResourceName state k addr desired = do
163 , clientStatus = status 163 , clientStatus = status
164 , clientFlags = flgs } 164 , clientFlags = flgs }
165 165
166 do -- forward-lookup of the buddies so that it is cached for reversing.
167 buds <- configText ConfigFiles.getBuddies (clientUser client)
168 forM_ buds $ \bud -> do
169 let (_,h,_) = splitJID bud
170 forkIO $ void $ resolvePeer h
171
166 atomically $ do 172 atomically $ do
167 modifyTVar' (clients state) $ Map.insert k client 173 modifyTVar' (clients state) $ Map.insert k client
168 modifyTVar' (clientsByUser state) $ flip Map.alter (clientUser client) 174 modifyTVar' (clientsByUser state) $ flip Map.alter (clientUser client)
@@ -345,9 +351,6 @@ ip6literal addr = Text.map dash addr <> ".ipv6-literal.net"
345 dash ':' = '-' 351 dash ':' = '-'
346 dash x = x 352 dash x = x
347 353
348withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a
349withPort (SockAddrInet6 _ a b c) port = SockAddrInet6 (toEnum port) a b c
350
351-- | The given address is taken to be the local address for the socket this JID 354-- | The given address is taken to be the local address for the socket this JID
352-- came in on. The returned JID parts are suitable for unsplitJID to create a 355-- came in on. The returned JID parts are suitable for unsplitJID to create a
353-- valid JID for communicating to a client. The returned Bool is True when the 356-- valid JID for communicating to a client. The returned Bool is True when the
@@ -370,7 +373,8 @@ peerKeyToResolvedName :: [Text] -> ConnectionKey -> IO Text
370peerKeyToResolvedName buds k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1" 373peerKeyToResolvedName buds k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1"
371peerKeyToResolvedName buds pk = do 374peerKeyToResolvedName buds pk = do
372 ns <- peerKeyToResolvedNames pk 375 ns <- peerKeyToResolvedNames pk
373 let ns' = sortBy (comparing $ not . flip elem buds) ns 376 let hs = map (\jid -> let (_,h,_)=splitJID jid in h) buds
377 ns' = sortBy (comparing $ not . flip elem hs) ns
374 return $ maybe (peerKeyToText pk) id (listToMaybe ns') 378 return $ maybe (peerKeyToText pk) id (listToMaybe ns')
375 379
376 380
@@ -447,7 +451,7 @@ deliverMessage state fail msg =
447 buds <- configText ConfigFiles.getBuddies n 451 buds <- configText ConfigFiles.getBuddies n
448 from' <- do 452 from' <- do
449 flip (maybe $ return Nothing) (stanzaFrom msg) $ \from -> do 453 flip (maybe $ return Nothing) (stanzaFrom msg) $ \from -> do
450 (_,trip) <- rewriteJIDForClient laddr from [] -- XXX 454 (_,trip) <- rewriteJIDForClient laddr from buds
451 return . Just $ unsplitJID trip 455 return . Just $ unsplitJID trip
452 let ks = Map.keys (networkClients presence_container) 456 let ks = Map.keys (networkClients presence_container)
453 chans = mapMaybe (flip Map.lookup key_to_chan) ks 457 chans = mapMaybe (flip Map.lookup key_to_chan) ks