summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/Onion/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox/Onion/Handlers.hs')
-rw-r--r--dht/src/Network/Tox/Onion/Handlers.hs44
1 files changed, 1 insertions, 43 deletions
diff --git a/dht/src/Network/Tox/Onion/Handlers.hs b/dht/src/Network/Tox/Onion/Handlers.hs
index 3ea7395f..b35631a3 100644
--- a/dht/src/Network/Tox/Onion/Handlers.hs
+++ b/dht/src/Network/Tox/Onion/Handlers.hs
@@ -219,7 +219,7 @@ toxidSearch :: (OnionDestination r -> STM (OnionDestination r, Int))
219toxidSearch getTimeout crypto client = Search 219toxidSearch getTimeout crypto client = Search
220 { searchSpace = toxSpace 220 { searchSpace = toxSpace
221 , searchNodeAddress = nodeIP &&& nodePort 221 , searchNodeAddress = nodeIP &&& nodePort
222 , searchQuery = Right $ asyncGetRendezvous getTimeout crypto client 222 , searchQuery = Left $ getRendezvous getTimeout crypto client
223 , searchAlpha = 3 223 , searchAlpha = 3
224 , searchK = 6 224 , searchK = 6
225 } 225 }
@@ -291,28 +291,6 @@ sendOnion getTimeout client req oaddr unwrap =
291 (return . Just . unwrap (onionNodeInfo oaddr)) 291 (return . Just . unwrap (onionNodeInfo oaddr))
292 $ join mb 292 $ join mb
293 293
294asyncOnion :: (OnionDestination r -> STM (OnionDestination r, Int))
295 -> QR.Client
296 err
297 PacketKind
298 TransactionId
299 (OnionDestination r)
300 (OnionMessage Identity)
301 -> AnnounceRequest
302 -> OnionDestination r
303 -> (NodeInfo -> AnnounceResponse -> a)
304 -> (Maybe a -> IO ())
305 -> IO ()
306asyncOnion getTimeout client req oaddr unwrap go =
307 -- Four tries and then we tap out.
308 flip fix 4 $ \loop n -> do
309 QR.asyncQuery client (announceSerializer getTimeout) req oaddr
310 $ \mb -> do
311 forM_ mb $ \r -> dput XAnnounce $ show (onionNodeInfo oaddr) ++ " sent response: " ++ show r
312 maybe (if n>0 then loop $! n - 1 else go Nothing)
313 (go . Just . unwrap (onionNodeInfo oaddr))
314 $ join mb
315
316 294
317-- | Lookup the secret counterpart for a given alias key. 295-- | Lookup the secret counterpart for a given alias key.
318getRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int)) 296getRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int))
@@ -332,26 +310,6 @@ getRendezvous getTimeout crypto client nid ni = do
332 oaddr 310 oaddr
333 (unwrapAnnounceResponse rkey) 311 (unwrapAnnounceResponse rkey)
334 312
335asyncGetRendezvous
336 :: (OnionDestination r -> STM (OnionDestination r, Int))
337 -> TransportCrypto
338 -> Client r
339 -> NodeId
340 -> NodeInfo
341 -> (Maybe ([NodeInfo], [Rendezvous], Maybe Nonce32) -> IO ())
342 -> IO ()
343asyncGetRendezvous getTimeout crypto client nid ni go = do
344 asel <- atomically $ selectAlias crypto nid
345 let oaddr = OnionDestination asel ni Nothing
346 rkey = case asel of
347 SearchingAlias -> Nothing
348 _ -> Just $ key2id $ rendezvousPublic crypto
349 asyncOnion getTimeout client
350 (AnnounceRequest zeros32 nid $ fromMaybe zeroID rkey)
351 oaddr
352 (unwrapAnnounceResponse rkey)
353 go
354
355putRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int)) 313putRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int))
356 -> TransportCrypto 314 -> TransportCrypto
357 -> Client r 315 -> Client r