diff options
Diffstat (limited to 'dht/TCPProber.hs')
-rw-r--r-- | dht/TCPProber.hs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/dht/TCPProber.hs b/dht/TCPProber.hs index 17b68f64..ccdbd8d1 100644 --- a/dht/TCPProber.hs +++ b/dht/TCPProber.hs | |||
@@ -176,11 +176,35 @@ getNodes prober tcp seeking dst = do | |||
176 | return $ Success ts | 176 | return $ Success ts |
177 | _ -> return $ fmap (const $ error "TCPProber.getNodes: The impossible happened!") r | 177 | _ -> return $ fmap (const $ error "TCPProber.getNodes: The impossible happened!") r |
178 | 178 | ||
179 | nodeSearch :: TCPProber -> TCP.TCPClient err Nonce8 -> Search NodeId (IP, PortNumber) () TCP.NodeInfo TCP.NodeInfo | 179 | asyncGetNodes :: TCPProber -> TCP.TCPClient err Nonce8 -> NodeId -> TCP.NodeInfo |
180 | -> (Nonce8 -> Result ([TCP.NodeInfo],[TCP.NodeInfo],Maybe ()) -> IO ()) | ||
181 | -> IO Nonce8 | ||
182 | asyncGetNodes prober tcp seeking dst withResponse = do | ||
183 | TCP.asyncUDPNodes tcp seeking (TCP.udpNodeInfo dst) $ \qid r -> do | ||
184 | dput XTCP $ "Got via TCP nodes: " ++ show r | ||
185 | let tcps (ns,_,mb) = (ns',ns',mb) | ||
186 | where ns' = do | ||
187 | n <- ns | ||
188 | [ TCP.NodeInfo n 0 ] | ||
189 | r' <- case r of | ||
190 | Success (ns,gw) -> do | ||
191 | let ts = tcps ns | ||
192 | if TCP.nodeId gw == TCP.nodeId dst | ||
193 | then return $ Success ts | ||
194 | else do | ||
195 | enqueueProbe prober (TCP.udpNodeInfo dst) | ||
196 | return $ Success ts | ||
197 | return $ Success ts | ||
198 | _ -> return $ fmap (const $ error "TCPProber.getNodes: The impossible happened!") r | ||
199 | withResponse qid r' | ||
200 | |||
201 | |||
202 | nodeSearch :: TCPProber -> TCP.TCPClient err Nonce8 -> Search NodeId (IP, PortNumber) () TCP.NodeInfo TCP.NodeInfo Nonce8 | ||
180 | nodeSearch prober tcp = Search | 203 | nodeSearch prober tcp = Search |
181 | { searchSpace = TCP.tcpSpace | 204 | { searchSpace = TCP.tcpSpace |
182 | , searchNodeAddress = TCP.nodeIP &&& TCP.tcpPort | 205 | , searchNodeAddress = TCP.nodeIP &&& TCP.tcpPort |
183 | , searchQuery = getNodes prober tcp | 206 | , searchQuery = asyncGetNodes prober tcp |
207 | , searchQueryCancel = cancelQuery (TCP.tcpClient tcp) | ||
184 | , searchAlpha = 8 | 208 | , searchAlpha = 8 |
185 | , searchK = 16 | 209 | , searchK = 16 |
186 | } | 210 | } |