summaryrefslogtreecommitdiff
path: root/OnionRouter.hs
diff options
context:
space:
mode:
Diffstat (limited to 'OnionRouter.hs')
-rw-r--r--OnionRouter.hs28
1 files changed, 1 insertions, 27 deletions
diff --git a/OnionRouter.hs b/OnionRouter.hs
index 289dc7f4..26bc6525 100644
--- a/OnionRouter.hs
+++ b/OnionRouter.hs
@@ -31,9 +31,6 @@ import Network.Socket
31import System.Endian 31import System.Endian
32import System.IO 32import System.IO
33 33
34newtype RouteId = RouteId Int
35 deriving Show
36
37-- Toxcore saves a maximum of 12 paths: 6 paths are reserved for announcing 34-- Toxcore saves a maximum of 12 paths: 6 paths are reserved for announcing
38-- ourselves and 6 others are used to search for friends. 35-- ourselves and 6 others are used to search for friends.
39-- 36--
@@ -210,8 +207,8 @@ randomIvalInteger (l,h) rng
210selectTrampolines :: OnionRouter -> STM [NodeInfo] 207selectTrampolines :: OnionRouter -> STM [NodeInfo]
211selectTrampolines or = do 208selectTrampolines or = do
212 cnt <- readTVar (trampolineCount or) 209 cnt <- readTVar (trampolineCount or)
213 drg0 <- readTVar (onionDRG or)
214 ts <- readTVar (trampolineNodes or) 210 ts <- readTVar (trampolineNodes or)
211 drg0 <- readTVar (onionDRG or)
215 let (a, drg1) = randomR (0,cnt - 1) drg0 212 let (a, drg1) = randomR (0,cnt - 1) drg0
216 (b0, drg2) = randomR (0,cnt - 2) drg1 213 (b0, drg2) = randomR (0,cnt - 2) drg1
217 (c0, drg ) = randomR (0,cnt - 3) drg2 214 (c0, drg ) = randomR (0,cnt - 3) drg2
@@ -289,29 +286,6 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do
289 Just _ -> hPutStrLn stderr $ "ONION Finished RouteId " ++ show rid 286 Just _ -> hPutStrLn stderr $ "ONION Finished RouteId " ++ show rid
290 Nothing -> hPutStrLn stderr $ "ONION Failed RouteId " ++ show rid 287 Nothing -> hPutStrLn stderr $ "ONION Failed RouteId " ++ show rid
291 288
292-- We used to derive the RouteId from the Nonce8 associated with the query.
293-- This is problematic because a nonce generated by toxcore will not validate
294-- if it is received via a different route than it was issued. This is
295-- described by the Tox spec:
296--
297-- Toxcore generates `ping_id`s by taking a 32 byte sha hash of the current
298-- time, some secret bytes generated when the instance is created, the
299-- current time divided by a 20 second timeout, the public key of the
300-- requester and the source ip/port that the packet was received from. Since
301-- the ip/port that the packet was received from is in the `ping_id`, the
302-- announce packets being sent with a ping id must be sent using the same
303-- path as the packet that we received the `ping_id` from or announcing will
304-- fail.
305--
306-- The original idea was:
307--
308-- > routeId :: Nonce8 -> RouteId
309-- > routeId (Nonce8 w8) = RouteId $ mod (fromIntegral w8) 12
310--
311-- Instead, we'll just hash the destination node id.
312routeId :: NodeId -> RouteId
313routeId nid = RouteId $ mod (hash nid) 12
314
315lookupSender :: OnionRouter -> SockAddr -> Nonce8 -> IO (Maybe (OnionDestination RouteId)) 289lookupSender :: OnionRouter -> SockAddr -> Nonce8 -> IO (Maybe (OnionDestination RouteId))
316lookupSender or saddr (Nonce8 w8) = do 290lookupSender or saddr (Nonce8 w8) = do
317 result <- atomically $ do 291 result <- atomically $ do