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.hs49
1 files changed, 45 insertions, 4 deletions
diff --git a/dht/src/Network/Tox/Onion/Handlers.hs b/dht/src/Network/Tox/Onion/Handlers.hs
index 015c758c..45795312 100644
--- a/dht/src/Network/Tox/Onion/Handlers.hs
+++ b/dht/src/Network/Tox/Onion/Handlers.hs
@@ -218,13 +218,14 @@ handlers net _ _ keydb _ = Just $ NoReply Right $ dataToRouteH keydb net
218toxidSearch :: (OnionDestination r -> STM (OnionDestination r, Int)) 218toxidSearch :: (OnionDestination r -> STM (OnionDestination r, Int))
219 -> TransportCrypto 219 -> TransportCrypto
220 -> Client r 220 -> Client r
221 -> Search NodeId (IP, PortNumber) Nonce32 NodeInfo Rendezvous 221 -> Search NodeId (IP, PortNumber) Nonce32 NodeInfo Rendezvous TransactionId
222toxidSearch getTimeout crypto client = Search 222toxidSearch getTimeout crypto client = Search
223 { searchSpace = toxSpace 223 { searchSpace = toxSpace
224 , searchNodeAddress = nodeIP &&& nodePort 224 , searchNodeAddress = nodeIP &&& nodePort
225 , searchQuery = getRendezvous getTimeout crypto client 225 , searchQuery = asyncGetRendezvous getTimeout crypto client
226 , searchAlpha = 3 226 , searchQueryCancel = cancelQuery client
227 , searchK = 6 227 , searchAlpha = 3
228 , searchK = 6
228 } 229 }
229 230
230announceSerializer :: (OnionDestination r -> STM (OnionDestination r, Int)) 231announceSerializer :: (OnionDestination r -> STM (OnionDestination r, Int))
@@ -289,6 +290,25 @@ sendOnion getTimeout client req oaddr unwrap =
289 Canceled -> return Canceled 290 Canceled -> return Canceled
290 TimedOut -> re 291 TimedOut -> re
291 292
293asyncOnion :: (OnionDestination r -> STM (OnionDestination r, Int))
294 -> Client r
295 -> AnnounceRequest
296 -> OnionDestination r
297 -> (NodeInfo -> AnnounceResponse -> t)
298 -> (TransactionId -> QR.Result t -> IO ())
299 -> IO TransactionId
300asyncOnion getTimeout client req oaddr unwrap withResult = do
301 -- TODO: Restore "Four tries and then we tap out" behavior.
302 qid <- QR.asyncQuery client (announceSerializer getTimeout) req oaddr $ \k mb -> do
303 forM_ mb $ \r -> dput XAnnounce $ show (onionNodeInfo oaddr) ++ " async sent response: " ++ show r
304 withResult k $ case mb of
305 Success x -> maybe (TimedOut)
306 (Success . unwrap (onionNodeInfo oaddr))
307 (x :: Maybe AnnounceResponse)
308 Canceled -> Canceled
309 TimedOut -> TimedOut
310 return qid
311
292 312
293-- | Lookup the secret counterpart for a given alias key. 313-- | Lookup the secret counterpart for a given alias key.
294getRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int)) 314getRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int))
@@ -308,6 +328,27 @@ getRendezvous getTimeout crypto client nid ni = do
308 oaddr 328 oaddr
309 (unwrapAnnounceResponse rkey) 329 (unwrapAnnounceResponse rkey)
310 330
331asyncGetRendezvous ::
332 (OnionDestination r -> STM (OnionDestination r, Int))
333 -> TransportCrypto
334 -> Client r
335 -> NodeId
336 -> NodeInfo
337 -> (TransactionId -> Result ([NodeInfo],[Rendezvous],Maybe Nonce32) -> IO ())
338 -> IO TransactionId
339asyncGetRendezvous getTimeout crypto client nid ni withResult = do
340 asel <- atomically $ selectAlias crypto nid
341 let oaddr = OnionDestination asel ni Nothing
342 rkey = case asel of
343 SearchingAlias -> Nothing
344 _ -> Just $ key2id $ rendezvousPublic crypto
345 asyncOnion getTimeout client
346 (AnnounceRequest zeros32 nid $ fromMaybe zeroID rkey)
347 oaddr
348 (unwrapAnnounceResponse rkey)
349 withResult
350
351
311putRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int)) 352putRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int))
312 -> TransportCrypto 353 -> TransportCrypto
313 -> Client r 354 -> Client r