summaryrefslogtreecommitdiff
path: root/dht/examples/dhtd.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/examples/dhtd.hs')
-rw-r--r--dht/examples/dhtd.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs
index 6b057af9..3078831d 100644
--- a/dht/examples/dhtd.hs
+++ b/dht/examples/dhtd.hs
@@ -811,8 +811,14 @@ clientSession s@Session{..} sock cnum h = do
811 where 811 where
812 go | null destination = fmap Right . qhandler self 812 go | null destination = fmap Right . qhandler self
813 | otherwise = case readEither destination of 813 | otherwise = case readEither destination of
814 Right ni -> fmap (maybe (Left "Timeout.") Right . resultToMaybe) 814 Right ni -> \nid -> do
815 . flip (searchQuery qsearch) ni -- TODO report canceled 815 v <- newEmptyMVar
816 _ <- searchQuery qsearch nid ni $ \_ r -> putMVar v r
817 r <- takeMVar v
818 return $ case r of
819 Success x -> Right x
820 Canceled -> Left "Canceled."
821 TimedOut -> Left "Timeout."
816 Left e -> const $ return $ Left ("Bad destination: "++e) 822 Left e -> const $ return $ Left ("Bad destination: "++e)
817 maybe (hPutClient h ("Unsupported method: "++method)) 823 maybe (hPutClient h ("Unsupported method: "++method))
818 goQuery 824 goQuery
@@ -938,14 +944,14 @@ clientSession s@Session{..} sock cnum h = do
938 , Typeable ptok 944 , Typeable ptok
939 , Typeable sni 945 , Typeable sni
940 , Typeable pni ) 946 , Typeable pni )
941 => Search nid addr stok sni sr 947 => Search nid addr stok sni sr qk
942 -> (pr -> ptok -> Maybe pni -> IO (Maybe pubr)) 948 -> (pr -> ptok -> Maybe pni -> IO (Maybe pubr))
943 -> Maybe (stok :~: ptok, sni :~: pni) 949 -> Maybe (stok :~: ptok, sni :~: pni)
944 matchingResult _ _ = liftA2 (,) eqT eqT 950 matchingResult _ _ = liftA2 (,) eqT eqT
945 matchingResult2 :: 951 matchingResult2 ::
946 ( Typeable sr 952 ( Typeable sr
947 , Typeable pr ) 953 , Typeable pr )
948 => Search nid addr stok sni sr 954 => Search nid addr stok sni sr qk
949 -> (PublicKey -> pdta -> pr -> IO ()) 955 -> (PublicKey -> pdta -> pr -> IO ())
950 -> (pdta -> nid) 956 -> (pdta -> nid)
951 -> Maybe (pr :~: sr) 957 -> Maybe (pr :~: sr)
@@ -1913,7 +1919,7 @@ main = do
1913 btSaved <- loadNodes netname -- :: IO [Mainline.NodeInfo] 1919 btSaved <- loadNodes netname -- :: IO [Mainline.NodeInfo]
1914 putStrLn $ "Loaded "++show (length btSaved)++" nodes for "++netname++"." 1920 putStrLn $ "Loaded "++show (length btSaved)++" nodes for "++netname++"."
1915 fallbackNodes <- getBootstrapNodes 1921 fallbackNodes <- getBootstrapNodes
1916 let isNodesSearch :: ni :~: r -> Search nid addr tok ni r -> Search nid addr tok ni ni 1922 let isNodesSearch :: ni :~: r -> Search nid addr tok ni r qk -> Search nid addr tok ni ni qk
1917 isNodesSearch Refl sch = sch 1923 isNodesSearch Refl sch = sch
1918 ping = maybe (const $ return False) 1924 ping = maybe (const $ return False)
1919 (\DHTPing{pingQuery} -> fmap (maybe False (const True)) . pingQuery []) 1925 (\DHTPing{pingQuery} -> fmap (maybe False (const True)) . pingQuery [])