diff options
author | joe <joe@jerkface.net> | 2014-03-11 00:34:28 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-03-11 00:34:28 -0400 |
commit | f92276b3c28e715146bee11d0cdb48b711190fea (patch) | |
tree | a93e91a5dcd2c287e66c114852a7485fb796e584 | |
parent | e0869b7109ac5cb8902e0718c315869e3f135866 (diff) |
DNS fixes
-rw-r--r-- | Presence/DNSCache.hs | 17 | ||||
-rw-r--r-- | Presence/XMPPServer.hs | 4 | ||||
-rw-r--r-- | xmppServer.hs | 14 |
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 | ||
11 | import Control.Concurrent | 12 | import Control.Concurrent |
@@ -40,9 +41,8 @@ data DNSCache = | |||
40 | 41 | ||
41 | newDNSCache :: IO DNSCache | 42 | newDNSCache :: IO DNSCache |
42 | newDNSCache = do | 43 | newDNSCache = 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 | ||
48 | equivBy f a b = f a == f b | 48 | equivBy f a b = f a == f b |
@@ -64,13 +64,14 @@ dnsObserve :: DNSCache -> Bool -> TimeStamp -> [(Text,SockAddr)] -> STM () | |||
64 | dnsObserve dns withScrub utc obs = do | 64 | dnsObserve 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 | ||
210 | withPort :: SockAddr -> Int -> SockAddr | ||
211 | withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a | ||
212 | withPort (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 | |||
76 | import LockedChan | 76 | import LockedChan |
77 | import PeerResolve | 77 | import PeerResolve |
78 | 78 | ||
79 | withPort :: SockAddr -> Int -> SockAddr | ||
80 | withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a | ||
81 | withPort (SockAddrInet6 _ a b c) port = SockAddrInet6 (toEnum port) a b c | ||
82 | |||
83 | 79 | ||
84 | peerport :: PortNumber | 80 | peerport :: PortNumber |
85 | peerport = 5269 | 81 | peerport = 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 | ||
348 | withPort (SockAddrInet _ a) port = SockAddrInet (toEnum port) a | ||
349 | withPort (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 | |||
370 | peerKeyToResolvedName buds k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1" | 373 | peerKeyToResolvedName buds k@(ClientKey { localAddress=addr }) = return "ErrorClIeNt1" |
371 | peerKeyToResolvedName buds pk = do | 374 | peerKeyToResolvedName 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 |