diff options
Diffstat (limited to 'dht/src/Network/Tox/Onion/Handlers.hs')
-rw-r--r-- | dht/src/Network/Tox/Onion/Handlers.hs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/dht/src/Network/Tox/Onion/Handlers.hs b/dht/src/Network/Tox/Onion/Handlers.hs index fa7bc83c..015c758c 100644 --- a/dht/src/Network/Tox/Onion/Handlers.hs +++ b/dht/src/Network/Tox/Onion/Handlers.hs | |||
@@ -277,15 +277,17 @@ sendOnion :: (OnionDestination r -> STM (OnionDestination r, Int)) | |||
277 | -> AnnounceRequest | 277 | -> AnnounceRequest |
278 | -> OnionDestination r | 278 | -> OnionDestination r |
279 | -> (NodeInfo -> AnnounceResponse -> t) | 279 | -> (NodeInfo -> AnnounceResponse -> t) |
280 | -> IO (Maybe t) | 280 | -> IO (QR.Result t) |
281 | sendOnion getTimeout client req oaddr unwrap = | 281 | sendOnion getTimeout client req oaddr unwrap = |
282 | -- Four tries and then we tap out. | 282 | -- Four tries and then we tap out. |
283 | flip fix 4 $ \loop n -> do | 283 | flip fix 4 $ \loop n -> do |
284 | mb <- QR.sendQuery client (announceSerializer getTimeout) req oaddr | 284 | mb <- QR.sendQuery client (announceSerializer getTimeout) req oaddr |
285 | forM_ mb $ \r -> dput XAnnounce $ show (onionNodeInfo oaddr) ++ " sent response: " ++ show r | 285 | forM_ mb $ \r -> dput XAnnounce $ show (onionNodeInfo oaddr) ++ " sent response: " ++ show r |
286 | maybe (if n>0 then loop $! n - 1 else return Nothing) | 286 | let re = if n>0 then loop $! n - 1 else return Canceled |
287 | (return . Just . unwrap (onionNodeInfo oaddr)) | 287 | case mb of |
288 | $ join $ resultToMaybe mb | 288 | Success x -> maybe re (return . Success . unwrap (onionNodeInfo oaddr)) x |
289 | Canceled -> return Canceled | ||
290 | TimedOut -> re | ||
289 | 291 | ||
290 | 292 | ||
291 | -- | Lookup the secret counterpart for a given alias key. | 293 | -- | Lookup the secret counterpart for a given alias key. |
@@ -294,7 +296,7 @@ getRendezvous :: (OnionDestination r -> STM (OnionDestination r, Int)) | |||
294 | -> Client r | 296 | -> Client r |
295 | -> NodeId | 297 | -> NodeId |
296 | -> NodeInfo | 298 | -> NodeInfo |
297 | -> IO (Maybe ([NodeInfo],[Rendezvous],Maybe Nonce32)) | 299 | -> IO (Result ([NodeInfo],[Rendezvous],Maybe Nonce32)) |
298 | getRendezvous getTimeout crypto client nid ni = do | 300 | getRendezvous getTimeout crypto client nid ni = do |
299 | asel <- atomically $ selectAlias crypto nid | 301 | asel <- atomically $ selectAlias crypto nid |
300 | let oaddr = OnionDestination asel ni Nothing | 302 | let oaddr = OnionDestination asel ni Nothing |
@@ -319,5 +321,6 @@ putRendezvous getTimeout crypto client pubkey nonce32 ni = do | |||
319 | rendezvousKey = key2id rkey | 321 | rendezvousKey = key2id rkey |
320 | asel <- atomically $ selectAlias crypto longTermKey | 322 | asel <- atomically $ selectAlias crypto longTermKey |
321 | let oaddr = OnionDestination asel ni Nothing | 323 | let oaddr = OnionDestination asel ni Nothing |
322 | sendOnion getTimeout client (AnnounceRequest nonce32 longTermKey rendezvousKey) oaddr | 324 | fmap resultToMaybe |
325 | $ sendOnion getTimeout client (AnnounceRequest nonce32 longTermKey rendezvousKey) oaddr | ||
323 | $ \ni resp -> (Rendezvous rkey ni, resp) | 326 | $ \ni resp -> (Rendezvous rkey ni, resp) |