summaryrefslogtreecommitdiff
path: root/Presence/PeerResolve.hs
blob: 0854b365031bc638e167009b65c70263abcbff98 (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
28
29
30
31
32
33
34
35
36
37
38
39
module PeerResolve
    ( peerKeyToResolvedNames
    , resolvePeer
    , parseAddress
    , strip_brackets
    , withPort
    ) where

import Data.List       ( nub )
import Data.Text       ( Text )
import Network.Socket  ( SockAddr(..) )
import System.Endian   ( fromBE32, toBE32 )
import System.IO.Error ( isDoesNotExistError )
import Control.Exception ( handle, ErrorCall(..) )
import qualified Network.BSD as BSD
import qualified Data.Text   as Text
import Control.Concurrent
import Control.Concurrent.STM
import Control.Monad
import Data.Maybe
import System.IO.Unsafe

import GetHostByAddr
import DNSCache
import ConnectionKey
import ControlMaybe

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

resolvePeer :: Text -> IO [SockAddr]
resolvePeer addrtext = forwardResolve global_dns_cache addrtext

peerKeyToResolvedNames :: ConnectionKey -> IO [Text]
peerKeyToResolvedNames k@(ClientKey { localAddress=addr }) = return []
peerKeyToResolvedNames k@(PeerKey { callBackAddress=addr }) = do
    reverseResolve global_dns_cache addr