diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r-- | src/Network/BitTorrent/DHT/Search.hs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/Network/BitTorrent/DHT/Search.hs b/src/Network/BitTorrent/DHT/Search.hs index 51b40b2c..12fc29f6 100644 --- a/src/Network/BitTorrent/DHT/Search.hs +++ b/src/Network/BitTorrent/DHT/Search.hs | |||
@@ -83,8 +83,8 @@ newSearch :: ( Ord addr | |||
83 | Search nid addr tok ni r | 83 | Search nid addr tok ni r |
84 | -> nid | 84 | -> nid |
85 | -> [ni] -- Initial nodes to query. | 85 | -> [ni] -- Initial nodes to query. |
86 | -> IO (SearchState nid addr tok ni r) | 86 | -> STM (SearchState nid addr tok ni r) |
87 | newSearch (Search space nAddr qry) target ns = atomically $ do | 87 | newSearch (Search space nAddr qry) target ns = do |
88 | c <- newTVar 0 | 88 | c <- newTVar 0 |
89 | q <- newTVar $ MM.fromList | 89 | q <- newTVar $ MM.fromList |
90 | $ map (\n -> n :-> kademliaXor space target (kademliaLocation space n)) | 90 | $ map (\n -> n :-> kademliaXor space target (kademliaLocation space n)) |
@@ -102,7 +102,6 @@ searchK = 8 | |||
102 | 102 | ||
103 | sendQuery :: forall addr nid tok ni r. | 103 | sendQuery :: forall addr nid tok ni r. |
104 | ( Ord addr | 104 | ( Ord addr |
105 | , Ord r | ||
106 | , PSQKey nid | 105 | , PSQKey nid |
107 | , PSQKey ni | 106 | , PSQKey ni |
108 | , Show nid | 107 | , Show nid |
@@ -144,8 +143,7 @@ sendQuery Search{..} searchTarget searchResult sch@SearchState{..} (ni :-> d) = | |||
144 | [] -> return () | 143 | [] -> return () |
145 | 144 | ||
146 | 145 | ||
147 | searchIsFinished :: ( Ord addr | 146 | searchIsFinished :: ( PSQKey nid |
148 | , PSQKey nid | ||
149 | , PSQKey ni | 147 | , PSQKey ni |
150 | ) => SearchState nid addr tok ni r -> STM Bool | 148 | ) => SearchState nid addr tok ni r -> STM Bool |
151 | searchIsFinished SearchState{ ..} = do | 149 | searchIsFinished SearchState{ ..} = do |
@@ -170,13 +168,13 @@ search :: | |||
170 | , PSQKey ni | 168 | , PSQKey ni |
171 | , Show nid | 169 | , Show nid |
172 | ) => Search nid addr tok ni r -> R.BucketList ni -> nid -> (r -> STM Bool) -> IO (SearchState nid addr tok ni r) | 170 | ) => Search nid addr tok ni r -> R.BucketList ni -> nid -> (r -> STM Bool) -> IO (SearchState nid addr tok ni r) |
173 | search sch@Search{..} buckets target result = do | 171 | search sch buckets target result = do |
174 | let ns = R.kclosest searchSpace searchK target buckets | 172 | let ns = R.kclosest (searchSpace sch) searchK target buckets |
175 | st <- newSearch sch target ns | 173 | st <- atomically $ newSearch sch target ns |
176 | fork $ go st | 174 | fork $ searchLoop sch target result st |
177 | return st | 175 | return st |
178 | where | 176 | |
179 | go s@SearchState{..} = do | 177 | searchLoop sch@Search{..} target result s@SearchState{..} = do |
180 | myThreadId >>= flip labelThread ("search."++show target) | 178 | myThreadId >>= flip labelThread ("search."++show target) |
181 | withTaskGroup searchAlpha $ \g -> fix $ \again -> do | 179 | withTaskGroup searchAlpha $ \g -> fix $ \again -> do |
182 | join $ atomically $ do | 180 | join $ atomically $ do |