X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=blobdiff_plain;f=pdns-pipe-nmc.hs;h=1786376112854000b368be6a410432a9875db356;hp=a0d5fa23d417dbf4203d6812382e350a9b959163;hb=db22eaa53c505149f42cb3a7e3df9ea1fa9e1350;hpb=6bd856a8ffad4610f3c1632a337ad05e6277c898 diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index a0d5fa2..1786376 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -79,6 +79,7 @@ mainPdnsNmc = do hSetBuffering stdin LineBuffering hSetBuffering stdout LineBuffering + ver <- do let loopErr e = forever $ do @@ -96,10 +97,18 @@ mainPdnsNmc = do putStrLn $ "OK\tDnsNmc ready to serve, protocol v." ++ (show ver) mgr <- newManager def + let - newcache count name = (insert count name) - . (delete (if count >= 10 then count - 10 else count + 90)) + fetch = lookup + -- Save the name under current count, increment count for the next run + -- so the name is saved under the count that was put into the response. + stow name (count, cache) = + (if count >= 99 then 0 else count + 1 + , insert count name + $ delete (if count >= 10 then count - 10 else count + 90) cache + ) io = liftIO + mainloop = forever $ do l <- io getLine (count, cache) <- get @@ -110,15 +119,16 @@ mainPdnsNmc = do PdnsRequestQ qname qtype id _ _ _ -> do io $ queryDom (queryOpNmc cfg mgr id) qname >>= putStr . (pdnsOut ver count qname qtype) + -- debug io $ putStrLn $ "LOG\tRequest number " ++ (show count) ++ " id: " ++ (show id) ++ " qname: " ++ qname ++ " qtype: " ++ (show qtype) ++ " cache size: " ++ (show (size cache)) - put (if count >= 99 then 0 else count + 1, - newcache count qname cache) + -- end debug + put $ stow qname (count, cache) PdnsRequestAXFR xrq -> - case lookup xrq cache of + case fetch xrq cache of Nothing -> io $ putStr $ pdnsReport ("AXFR for unknown id: " ++ (show xrq)) @@ -126,6 +136,7 @@ mainPdnsNmc = do io $ queryDom (queryOpNmc cfg mgr xrq) qname >>= putStr . (pdnsOutXfr ver count qname) PdnsRequestPing -> io $ putStrLn "END" + runStateT mainloop (0, empty) >> return () -- query by key from Namecoin