summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-20 00:01:29 -0400
committerjoe <joe@jerkface.net>2017-07-20 00:01:29 -0400
commitfbd053967c814697ad21fde2dc8e95f7a4683302 (patch)
tree5aa07550819aedb74c4a806bd4fc3147d5cb4da4 /src/Network/BitTorrent/DHT
parentb3c832ebd86281bfaa4fe6bb88aaacacbed0eadc (diff)
Update MinMaxPSQ to use HashPSQ.
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r--src/Network/BitTorrent/DHT/Search.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/DHT/Search.hs b/src/Network/BitTorrent/DHT/Search.hs
index 356f6fd9..07240755 100644
--- a/src/Network/BitTorrent/DHT/Search.hs
+++ b/src/Network/BitTorrent/DHT/Search.hs
@@ -23,7 +23,7 @@ import System.IO
23import qualified Data.MinMaxPSQ as MM 23import qualified Data.MinMaxPSQ as MM
24 ;import Data.MinMaxPSQ (MinMaxPSQ) 24 ;import Data.MinMaxPSQ (MinMaxPSQ)
25import qualified Data.Wrapper.PSQ as PSQ 25import qualified Data.Wrapper.PSQ as PSQ
26 ;import Data.Wrapper.PSQ (pattern (:->), Binding, PSQ) 26 ;import Data.Wrapper.PSQ (pattern (:->), Binding, PSQ, PSQKey)
27import Network.Address hiding (NodeId) 27import Network.Address hiding (NodeId)
28import Network.DatagramServer.Types 28import Network.DatagramServer.Types
29import Data.Bits 29import Data.Bits
@@ -39,7 +39,8 @@ data IterativeSearch dht u ip r = IterativeSearch
39 } 39 }
40 40
41newSearch :: ( Eq ip 41newSearch :: ( Eq ip
42 , Ord (NodeId dht) 42 , PSQKey (NodeId dht)
43 , PSQKey (NodeInfo dht ip u)
43 , FiniteBits (NodeId dht) 44 , FiniteBits (NodeId dht)
44 ) => (NodeInfo dht ip u -> IO ([NodeInfo dht ip u], [r])) 45 ) => (NodeInfo dht ip u -> IO ([NodeInfo dht ip u], [r]))
45 -> NodeId dht -> [NodeInfo dht ip u] -> IO (IterativeSearch dht u ip r) 46 -> NodeId dht -> [NodeInfo dht ip u] -> IO (IterativeSearch dht u ip r)
@@ -60,7 +61,8 @@ searchK = 8
60sendQuery :: forall a ip dht u. 61sendQuery :: forall a ip dht u.
61 ( Ord a 62 ( Ord a
62 , Ord ip 63 , Ord ip
63 , Ord (NodeId dht) 64 , PSQKey (NodeId dht)
65 , PSQKey (NodeInfo dht ip u)
64 , FiniteBits (NodeId dht) 66 , FiniteBits (NodeId dht)
65 ) => 67 ) =>
66 IterativeSearch dht u ip a 68 IterativeSearch dht u ip a
@@ -85,7 +87,8 @@ sendQuery IterativeSearch{..} (ni :-> d) = do
85 87
86 88
87searchIsFinished :: ( Ord ip 89searchIsFinished :: ( Ord ip
88 , Ord (NodeId dht) 90 , PSQKey (NodeId dht)
91 , PSQKey (NodeInfo dht ip u)
89 ) => IterativeSearch dht u ip r -> STM Bool 92 ) => IterativeSearch dht u ip r -> STM Bool
90searchIsFinished IterativeSearch{..} = do 93searchIsFinished IterativeSearch{..} = do
91 q <- readTVar searchQueued 94 q <- readTVar searchQueued
@@ -98,7 +101,7 @@ searchIsFinished IterativeSearch{..} = do
98 <= PSQ.prio (fromJust $ MM.findMin q)))) 101 <= PSQ.prio (fromJust $ MM.findMin q))))
99 102
100search :: 103search ::
101 (Ord r, Ord ip, Ord (NodeId dht), FiniteBits (NodeId dht)) => 104 (Ord r, Ord ip, PSQKey (NodeId dht), PSQKey (NodeInfo dht ip u), FiniteBits (NodeId dht)) =>
102 IterativeSearch dht u ip r -> IO () 105 IterativeSearch dht u ip r -> IO ()
103search s@IterativeSearch{..} = withTaskGroup searchAlpha $ \g -> do 106search s@IterativeSearch{..} = withTaskGroup searchAlpha $ \g -> do
104 fix $ \again -> do 107 fix $ \again -> do