summaryrefslogtreecommitdiff
path: root/Presence/PeerResolve.hs
blob: 62becfe19e3bdec302d66f5d5a5159fe6752144b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module PeerResolve
    ( peerKeyToResolvedNames
    , resolvePeer
    , parseAddress
    , unsafeParseAddress
    , strip_brackets
    , withPort
    ) where

import Data.Text       ( Text )
import Network.Socket  ( SockAddr(..) )
import System.IO.Unsafe

import DNSCache
import ConnectionKey

{-# NOINLINE global_dns_cache #-}
global_dns_cache :: DNSCache
global_dns_cache = unsafePerformIO $ newDNSCache

resolvePeer :: Text -> IO [PeerAddress]
resolvePeer addrtext = map PeerAddress <$> forwardResolve global_dns_cache addrtext

peerKeyToResolvedNames :: PeerAddress -> IO [Text]
peerKeyToResolvedNames (PeerAddress addr)
    = reverseResolve global_dns_cache addr