summaryrefslogtreecommitdiff
path: root/OnionRouter.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-11-03 23:23:47 -0400
committerjoe <joe@jerkface.net>2017-11-03 23:23:47 -0400
commitfd7327e8974aa6a79a6be07005223233d107dfb0 (patch)
treed7f324ae857e40316109654841d83b357ba49ccc /OnionRouter.hs
parente8edad1852aa245a994c72d8331474b521042a25 (diff)
Improved search parameters for tox onion routed queries.
Diffstat (limited to 'OnionRouter.hs')
-rw-r--r--OnionRouter.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/OnionRouter.hs b/OnionRouter.hs
index eb79b70b..757214cd 100644
--- a/OnionRouter.hs
+++ b/OnionRouter.hs
@@ -32,6 +32,7 @@ import qualified Data.Word64Map as W64
32import Network.Socket 32import Network.Socket
33import System.Endian 33import System.Endian
34import System.IO 34import System.IO
35import System.Timeout
35 36
36-- Toxcore saves a maximum of 12 paths: 6 paths are reserved for announcing 37-- Toxcore saves a maximum of 12 paths: 6 paths are reserved for announcing
37-- ourselves and 6 others are used to search for friends. 38-- ourselves and 6 others are used to search for friends.
@@ -269,13 +270,18 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do
269 forkIO $ sendq asel aq (ts !! 0) >>= atomically . writeTVar av . Just 270 forkIO $ sendq asel aq (ts !! 0) >>= atomically . writeTVar av . Just
270 forkIO $ sendq bsel bq (ts !! 1) >>= atomically . writeTVar bv . Just 271 forkIO $ sendq bsel bq (ts !! 1) >>= atomically . writeTVar bv . Just
271 forkIO $ sendq csel cq (ts !! 2) >>= atomically . writeTVar cv . Just 272 forkIO $ sendq csel cq (ts !! 2) >>= atomically . writeTVar cv . Just
272 atomically $ do -- Wait for all 3 results. 273 -- This timeout should be unnecessary... But I'm paranoid.
274 -- Note: 10 seconds should be sufficient for typical get-nodes queries.
275 tm <- timeout 20000000 $ atomically $ do -- Wait for all 3 results.
273 rs <- catMaybes <$> sequence [readTVar av,readTVar bv,readTVar cv] 276 rs <- catMaybes <$> sequence [readTVar av,readTVar bv,readTVar cv]
274 case rs of [_,_,_] -> do 277 case rs of [_,_,_] -> do
275 return $ catMaybes $ catMaybes rs 278 return $ catMaybes $ catMaybes rs
276 -- self <- IntMap.lookup (-1) <$> readTVar (trampolineNodes or) 279 -- self <- IntMap.lookup (-1) <$> readTVar (trampolineNodes or)
277 -- return $ maybe (catMaybes rs) (\x -> [x,x,x]) self 280 -- return $ maybe (catMaybes rs) (\x -> [x,x,x]) self
278 _ -> retry 281 _ -> retry
282 maybe (hPutStrLn stderr "ONION: Unexpected sendq timeout!" >> return [])
283 return
284 tm
279 return $ do 285 return $ do
280 myThreadId >>= flip labelThread ("OnionRouter.sendqs") 286 myThreadId >>= flip labelThread ("OnionRouter.sendqs")
281 nodes <- case ts of 287 nodes <- case ts of