diff options
-rw-r--r-- | OnionRouter.hs | 6 | ||||
-rw-r--r-- | src/Network/Tox/Onion/Transport.hs | 19 |
2 files changed, 12 insertions, 13 deletions
diff --git a/OnionRouter.hs b/OnionRouter.hs index 40112e6a..04df18b6 100644 --- a/OnionRouter.hs +++ b/OnionRouter.hs | |||
@@ -33,7 +33,7 @@ newtype RouteId = RouteId Int | |||
33 | deriving Show | 33 | deriving Show |
34 | 34 | ||
35 | data OnionRouter = OnionRouter | 35 | data OnionRouter = OnionRouter |
36 | { pendingQueries :: TVar (Word64Map NodeId) -- TODO: routeNonce belongs here instead of in routeMap, or just remove routeNonce and use transaction nonce. | 36 | { pendingQueries :: TVar (Word64Map NodeId) |
37 | , routeMap :: TVar (IntMap RouteRecord) | 37 | , routeMap :: TVar (IntMap RouteRecord) |
38 | , trampolineNodes :: TVar (IntMap NodeInfo) | 38 | , trampolineNodes :: TVar (IntMap NodeInfo) |
39 | , trampolineIds :: TVar (HashMap NodeId Int) | 39 | , trampolineIds :: TVar (HashMap NodeId Int) |
@@ -201,7 +201,6 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do | |||
201 | drg <- readTVar (onionDRG or) | 201 | drg <- readTVar (onionDRG or) |
202 | [av,bv,cv] <- sequence $ replicate 3 (newTVar Nothing) | 202 | [av,bv,cv] <- sequence $ replicate 3 (newTVar Nothing) |
203 | let (getr, drg') = withDRG drg $ do | 203 | let (getr, drg') = withDRG drg $ do |
204 | n24 <- Nonce24 <$> getRandomBytes 24 | ||
205 | asec <- generateSecretKey -- Three aliases | 204 | asec <- generateSecretKey -- Three aliases |
206 | bsec <- generateSecretKey | 205 | bsec <- generateSecretKey |
207 | csec <- generateSecretKey | 206 | csec <- generateSecretKey |
@@ -233,8 +232,7 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do | |||
233 | [a,b,c] | distinct3by nodeClass a b c -> do | 232 | [a,b,c] | distinct3by nodeClass a b c -> do |
234 | atomically $ writeTChan (routeLog or) $ unwords [ "ONION using route:", show $ nodeAddr a, show $ nodeAddr b, show $ nodeAddr c] | 233 | atomically $ writeTChan (routeLog or) $ unwords [ "ONION using route:", show $ nodeAddr a, show $ nodeAddr b, show $ nodeAddr c] |
235 | return $ Just OnionRoute | 234 | return $ Just OnionRoute |
236 | { routeNonce = n24 | 235 | { routeAliasA = asec |
237 | , routeAliasA = asec | ||
238 | , routeAliasB = bsec | 236 | , routeAliasB = bsec |
239 | , routeAliasC = csec | 237 | , routeAliasC = csec |
240 | , routeNodeA = a | 238 | , routeNodeA = a |
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs index eabd9473..989b06fd 100644 --- a/src/Network/Tox/Onion/Transport.hs +++ b/src/Network/Tox/Onion/Transport.hs | |||
@@ -192,8 +192,7 @@ encodeOnionAddr _ (msg,OnionDestination _ Nothing ) = do | |||
192 | hPutStrLn stderr $ "ONION encode missing routeid" | 192 | hPutStrLn stderr $ "ONION encode missing routeid" |
193 | return Nothing | 193 | return Nothing |
194 | encodeOnionAddr getRoute (msg,OnionDestination ni (Just rid)) = do | 194 | encodeOnionAddr getRoute (msg,OnionDestination ni (Just rid)) = do |
195 | let go route0 = do | 195 | let go route = do |
196 | let route = route0 { routeNonce = msgNonce msg } -- TODO: This necessary? | ||
197 | return ( runPut $ putRequest $ wrapForRoute msg ni route | 196 | return ( runPut $ putRequest $ wrapForRoute msg ni route |
198 | , nodeAddr $ routeNodeA route) | 197 | , nodeAddr $ routeNodeA route) |
199 | mapM' f x = do | 198 | mapM' f x = do |
@@ -635,8 +634,7 @@ transcode f (OnionToRouteResponse a) = OnionToRouteResponse a | |||
635 | 634 | ||
636 | 635 | ||
637 | data OnionRoute = OnionRoute | 636 | data OnionRoute = OnionRoute |
638 | { routeNonce :: Nonce24 | 637 | { routeAliasA :: SecretKey |
639 | , routeAliasA :: SecretKey | ||
640 | , routeAliasB :: SecretKey | 638 | , routeAliasB :: SecretKey |
641 | , routeAliasC :: SecretKey | 639 | , routeAliasC :: SecretKey |
642 | , routeNodeA :: NodeInfo | 640 | , routeNodeA :: NodeInfo |
@@ -645,18 +643,21 @@ data OnionRoute = OnionRoute | |||
645 | } | 643 | } |
646 | 644 | ||
647 | wrapForRoute :: OnionMessage Encrypted -> NodeInfo -> OnionRoute -> OnionRequest N0 | 645 | wrapForRoute :: OnionMessage Encrypted -> NodeInfo -> OnionRoute -> OnionRequest N0 |
648 | wrapForRoute msg ni r = OnionRequest | 646 | wrapForRoute msg ni r = |
649 | { onionNonce = routeNonce r | 647 | -- We needn't use the same nonce value here, but I think it is safe to do so. |
648 | let nonce = msgNonce msg | ||
649 | in OnionRequest | ||
650 | { onionNonce = nonce | ||
650 | , onionForward = wrapOnion (routeAliasA r) | 651 | , onionForward = wrapOnion (routeAliasA r) |
651 | (routeNonce r) | 652 | nonce |
652 | (id2key . nodeId $ routeNodeA r) | 653 | (id2key . nodeId $ routeNodeA r) |
653 | (nodeAddr $ routeNodeB r) | 654 | (nodeAddr $ routeNodeB r) |
654 | $ wrapOnion (routeAliasB r) | 655 | $ wrapOnion (routeAliasB r) |
655 | (routeNonce r) | 656 | nonce |
656 | (id2key . nodeId $ routeNodeB r) | 657 | (id2key . nodeId $ routeNodeB r) |
657 | (nodeAddr $ routeNodeC r) | 658 | (nodeAddr $ routeNodeC r) |
658 | $ wrapOnion (routeAliasC r) | 659 | $ wrapOnion (routeAliasC r) |
659 | (routeNonce r) | 660 | nonce |
660 | (id2key . nodeId $ routeNodeC r) | 661 | (id2key . nodeId $ routeNodeC r) |
661 | (nodeAddr ni) | 662 | (nodeAddr ni) |
662 | $ NotForwarded msg | 663 | $ NotForwarded msg |