+ let
+ newcache count name = (insert count name)
+ . (delete (if count >= 10 then count - 10 else count + 90))
+ io = liftIO
+ mainloop = forever $ do
+ l <- io getLine
+ (count, cache) <- get
+ case pdnsParse ver l of
+ Left e -> io $ putStr $ pdnsReport e
+ Right preq -> do
+ case preq of
+ PdnsRequestQ qname qtype id _ _ _ -> do
+ io $ queryDom (queryOpNmc cfg mgr id) qname
+ >>= putStr . (pdnsOut ver count qname qtype)
+ 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)
+ PdnsRequestAXFR xrq ->
+ case lookup xrq cache of
+ Nothing ->
+ io $ putStr $
+ pdnsReport ("AXFR for unknown id: " ++ (show xrq))
+ Just qname ->
+ 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
+
+mainOne key = do
+ cfg <- readConfig confFile
+ mgr <- newManager def
+ dom <- queryDom (queryOpNmc cfg mgr (-1)) key
+ putStrLn $ ppShow dom
+ putStr $ pdnsOut 1 (-1) key RRTypeANY dom
+
+-- using file backend for testing json domain data