summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--OnionRouter.hs26
1 files changed, 15 insertions, 11 deletions
diff --git a/OnionRouter.hs b/OnionRouter.hs
index 5f66dc68..ddccb531 100644
--- a/OnionRouter.hs
+++ b/OnionRouter.hs
@@ -443,12 +443,16 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do
443 let asel = sel .&. 0x3 443 let asel = sel .&. 0x3
444 bsel = shiftR sel 2 .&. 0x3 444 bsel = shiftR sel 2 .&. 0x3
445 csel = shiftR sel 4 .&. 0x3 445 csel = shiftR sel 4 .&. 0x3
446 sendq s q ni = fmap (listToMaybe . drop (fromIntegral s)) <$> getnodes q ni 446 sendq s q ni
447 | Right ts <- mts = fmap (listToMaybe . drop (fromIntegral s)) <$> getnodes q (ts !! ni)
448 | Left ts <- mts = case ni of
449 0 -> return $ Just $ Just $ TCP.udpNodeInfo (ts !! 0)
450 n -> fmap (listToMaybe . drop (fromIntegral s) . (\(ns,_,_)->ns))
451 <$> TCP.getUDPNodes (tcpKademliaClient or) q (TCP.udpNodeInfo $ ts !! n)
447 sendqs = do 452 sendqs = do
448 let Right ts = mts 453 forkIO $ sendq asel aq 0 >>= atomically . writeTVar av . Just
449 forkIO $ sendq asel aq (ts !! 0) >>= atomically . writeTVar av . Just 454 forkIO $ sendq bsel bq 1 >>= atomically . writeTVar bv . Just
450 forkIO $ sendq bsel bq (ts !! 1) >>= atomically . writeTVar bv . Just 455 forkIO $ sendq csel cq 2 >>= atomically . writeTVar cv . Just
451 forkIO $ sendq csel cq (ts !! 2) >>= atomically . writeTVar cv . Just
452 -- This timeout should be unnecessary... But I'm paranoid. 456 -- This timeout should be unnecessary... But I'm paranoid.
453 -- Note: 10 seconds should be sufficient for typical get-nodes queries. 457 -- Note: 10 seconds should be sufficient for typical get-nodes queries.
454 tm <- timeout 20000000 $ atomically $ do -- Wait for all 3 results. 458 tm <- timeout 20000000 $ atomically $ do -- Wait for all 3 results.
@@ -463,14 +467,14 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do
463 tm 467 tm
464 return $ do 468 return $ do
465 myThreadId >>= flip labelThread ("OnionRouter.sendqs") 469 myThreadId >>= flip labelThread ("OnionRouter.sendqs")
466 let Right ts = mts 470 let mtcpport = either (Just . TCP.tcpPort . head) (const Nothing) mts
467 mtcpport = Nothing -- TODO 471 nodes <- case mts of
468 nodes <- case ts of 472 Right [_,_,_] -> sendqs
469 [_,_,_] -> sendqs 473 Left [_,_,_] -> sendqs
470 _ -> return [] 474 _ -> return []
471 myThreadId >>= flip labelThread ("OnionRouter") 475 myThreadId >>= flip labelThread ("OnionRouter")
472 routeLogger or $ unlines 476 routeLogger or $ unlines
473 [ "ONION trampolines: " ++ show ts 477 [ "ONION trampolines: " ++ show mts
474 , "ONION query results: " ++ show nodes ] 478 , "ONION query results: " ++ show nodes ]
475 case nodes of 479 case nodes of
476 [a,b,c] | distinct3by nodeClass a b c -> do 480 [a,b,c] | distinct3by nodeClass a b c -> do