- forever $ do
- l <- getLine
- case pdnsParse ver l of
- Left e -> putStr $ pdnsReport e
- Right preq -> do
- case preq of
- PdnsRequestQ qname qtype id _ _ _ ->
- queryNmc mgr cfg qname id >>= putStr . (pdnsOut ver id qname qtype)
- PdnsRequestAXFR xfrreq ->
- putStr $ pdnsReport ("No support for AXFR " ++ xfrreq)
- PdnsRequestPing -> putStrLn "END"
-
--- for testing
-
-ask str = do
+ 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