Skip to content

Commit

Permalink
naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodile-dentist committed Jan 17, 2025
1 parent f6a0670 commit 5ec7ebc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ ioDNSActions tracer lookupType toPeerAddr =
DNSActions {
dnsResolverResource = resolverResource,
dnsAsyncResolverResource = asyncResolverResource,
dnsLookupWithTTL = dispatchLookupWithTTL lookupType mkIOAction tracer toPeerAddr
dnsLookupWithTTL = dispatchLookupWithTTL lookupType mkResolveDNSIOAction tracer toPeerAddr
}
where
mkIOAction resolver resolvConf domain ofType =
mkResolveDNSIOAction resolver resolvConf domain ofType =
timeout (microsecondsAsIntToDiffTime
$ DNS.resolvTimeout resolvConf)
(DNS.lookupRaw resolver domain ofType)
Expand Down Expand Up @@ -372,8 +372,8 @@ srvRecordLookupWithTTL :: forall peerAddr m. (MonadAsync m)
-> m (Maybe (Either DNSError DNSMessage)))
-> StdGen
-> m (DNSLookupResult peerAddr)
srvRecordLookupWithTTL ofType tracer toPeerAddr peerType domainSRV mkAction2 rng = do
reply <- mkAction2 domainSRV DNS.SRV
srvRecordLookupWithTTL ofType tracer toPeerAddr peerType domainSRV resolveDNS rng = do
reply <- resolveDNS domainSRV DNS.SRV
case reply of
Nothing -> do
traceWith tracer $ DnsTraceLookupError peerType Nothing domainSRV DNS.TimeoutExpired
Expand All @@ -394,7 +394,7 @@ srvRecordLookupWithTTL ofType tracer toPeerAddr peerType domainSRV mkAction2 rng
Just topPriority ->
case topPriority of
(domain, _, _, port) NE.:| [] -> do -- fast path
result <- domainLookupWithTTL tracer ofType domain peerType mkAction2
result <- domainLookupWithTTL tracer ofType domain peerType resolveDNS
let result' = ipsttlsWithPort port <$> result
return (result', domain)
many -> -- general path
Expand All @@ -415,7 +415,7 @@ srvRecordLookupWithTTL ofType tracer toPeerAddr peerType domainSRV mkAction2 rng
mapCdf = Map.fromList cdf
(pick, _) = randomR (0, upperBound) rng
(domain, _, _, port) = snd . fromJust $ Map.lookupGE pick mapCdf
in (,domain) . fmap (ipsttlsWithPort port) <$> domainLookupWithTTL tracer ofType domain peerType mkAction2
in (,domain) . fmap (ipsttlsWithPort port) <$> domainLookupWithTTL tracer ofType domain peerType resolveDNS

aggregate (!upper, cdf) srv =
let upper' = weight srv + upper
Expand Down Expand Up @@ -446,15 +446,15 @@ dispatchLookupWithTTL :: (MonadAsync m)
-> resolver
-> StdGen
-> m (DNSLookupResult peerAddr)
dispatchLookupWithTTL lookupType mkAction4 tracer toPeerAddr peerType domain conf resolver rng =
let mkAction2 = mkAction4 resolver conf
dispatchLookupWithTTL lookupType mkResolveDNS tracer toPeerAddr peerType domain conf resolver rng =
let resolveDNS = mkResolveDNS resolver conf
in case domain of
RelayAccessDomain d p -> do
result <- domainLookupWithTTL tracer lookupType d peerType mkAction2
result <- domainLookupWithTTL tracer lookupType d peerType resolveDNS
let trace = map (\(ip, ttl) -> (ip, p, ttl)) <$> result
Fold.traverse_ (traceWith tracer . DnsResult peerType d Nothing) trace
return $ map (\(ip, _ttl) -> (toPeerAddr ip p, _ttl)) <$> result
RelayAccessSRVDomain d -> srvRecordLookupWithTTL lookupType tracer toPeerAddr peerType d mkAction2 rng
RelayAccessSRVDomain d -> srvRecordLookupWithTTL lookupType tracer toPeerAddr peerType d resolveDNS rng
RelayAccessAddress addr p -> return . Right $ [(toPeerAddr addr p, maxBound)]

domainLookupWithTTL :: (MonadAsync m)
Expand All @@ -466,25 +466,25 @@ domainLookupWithTTL :: (MonadAsync m)
-> DNS.TYPE
-> m (Maybe (Either DNSError DNSMessage)))
-> m (Either [DNSError] [(IP, DNS.TTL)])
domainLookupWithTTL tracer look@LookupReqAOnly d peerType resolveDNS = do
domainLookupWithTTL tracer LookupReqAOnly d peerType resolveDNS = do
res <- domainALookupWithTTL (resolveDNS d DNS.A)
case res of
Left err -> do
traceWith tracer $ DnsTraceLookupError peerType (Just look) d err
return . Left $ [err]
Right r -> return . Right $ r

domainLookupWithTTL tracer look@LookupReqAAAAOnly d peerType action2 = do
res <- domainAAAALookupWithTTL (action2 d DNS.AAAA)
domainLookupWithTTL tracer look@LookupReqAAAAOnly d peerType resolveDNS = do
res <- domainAAAALookupWithTTL (resolveDNS d DNS.AAAA)
case res of
Left err -> do
traceWith tracer $ DnsTraceLookupError peerType (Just look) d err
return . Left $ [err] --([err], [])
Right r -> return . Right $ r

domainLookupWithTTL tracer LookupReqAAndAAAA d peerType action2 = do
(r_ipv6, r_ipv4) <- concurrently (domainAAAALookupWithTTL (action2 d DNS.AAAA))
(domainALookupWithTTL (action2 d DNS.A))
domainLookupWithTTL tracer LookupReqAAndAAAA d peerType resolveDNS = do
(r_ipv6, r_ipv4) <- concurrently (domainAAAALookupWithTTL (resolveDNS d DNS.AAAA))
(domainALookupWithTTL (resolveDNS d DNS.A))
case (r_ipv6, r_ipv4) of
(Left e6, Left e4) -> do
traceWith tracer $ DnsTraceLookupError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ publicRootPeersProvider tracer
toPeerAddr
dnsSemaphore
resolvConf
readServices
readDomains
DNSActions {
dnsResolverResource,
dnsLookupWithTTL
}
rng0
action = do
services <- atomically readServices
traceWith tracer (TracePublicRootRelayAccessPoint services)
domains <- atomically readDomains
traceWith tracer (TracePublicRootRelayAccessPoint domains)
rr <- dnsResolverResource resolvConf
resourceVar <- newTVarIO rr
action (requestPublicRootPeers resourceVar)
Expand All @@ -79,8 +79,8 @@ publicRootPeersProvider tracer
-> Int
-> m (Map peerAddr PeerAdvertise, DiffTime)
requestPublicRootPeers resourceVar _numRequested = do
services <- atomically readServices
traceWith tracer (TracePublicRootRelayAccessPoint services)
domains <- atomically readDomains
traceWith tracer (TracePublicRootRelayAccessPoint domains)
rr <- readTVarIO resourceVar
(er, rr') <- withResource rr
atomically $ writeTVar resourceVar rr'
Expand All @@ -89,7 +89,7 @@ publicRootPeersProvider tracer
Left (IOError err) -> throwIO err
Right resolver -> do
let (doms, relayAddrs) =
flip partition (Map.assocs services) $ \case
flip partition (Map.assocs domains) $ \case
(RelayAccessAddress {}, _) -> False
_otherwise -> True
lookups =
Expand Down

0 comments on commit 5ec7ebc

Please sign in to comment.