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 /Presence/DNSCache.hs | |
parent | e0869b7109ac5cb8902e0718c315869e3f135866 (diff) |
DNS fixes
Diffstat (limited to 'Presence/DNSCache.hs')
-rw-r--r-- | Presence/DNSCache.hs | 17 |
1 files changed, 11 insertions, 6 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 | |||