summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Onion/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Onion/Handlers.hs')
-rw-r--r--src/Network/Tox/Onion/Handlers.hs46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/Network/Tox/Onion/Handlers.hs b/src/Network/Tox/Onion/Handlers.hs
index edbbbb49..f44dd79c 100644
--- a/src/Network/Tox/Onion/Handlers.hs
+++ b/src/Network/Tox/Onion/Handlers.hs
@@ -218,7 +218,7 @@ toxidSearch :: (TransactionId -> OnionDestination r -> STM (OnionDestination r,
218toxidSearch getTimeout crypto client = Search 218toxidSearch getTimeout crypto client = Search
219 { searchSpace = toxSpace 219 { searchSpace = toxSpace
220 , searchNodeAddress = nodeIP &&& nodePort 220 , searchNodeAddress = nodeIP &&& nodePort
221 , searchQuery = Left $ getRendezvous getTimeout crypto client 221 , searchQuery = Right $ asyncGetRendezvous getTimeout crypto client
222 , searchAlpha = 3 222 , searchAlpha = 3
223 , searchK = 6 223 , searchK = 6
224 } 224 }
@@ -290,6 +290,30 @@ sendOnion getTimeout client req oaddr unwrap =
290 (return . Just . unwrap (onionNodeInfo oaddr)) 290 (return . Just . unwrap (onionNodeInfo oaddr))
291 $ join mb 291 $ join mb
292 292
293asyncOnion :: (TransactionId
294 -> 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
293-- | Lookup the secret counterpart for a given alias key. 317-- | Lookup the secret counterpart for a given alias key.
294getRendezvous :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) 318getRendezvous :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int))
295 -> TransportCrypto 319 -> TransportCrypto
@@ -308,6 +332,26 @@ getRendezvous getTimeout crypto client nid ni = do
308 oaddr 332 oaddr
309 (unwrapAnnounceResponse rkey) 333 (unwrapAnnounceResponse rkey)
310 334
335asyncGetRendezvous
336 :: (TransactionId -> 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
311putRendezvous :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) 355putRendezvous :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int))
312 -> TransportCrypto 356 -> TransportCrypto
313 -> Client r 357 -> Client r