diff options
-rw-r--r-- | src/Network/Tox.hs | 2 | ||||
-rw-r--r-- | src/Network/Tox/Onion/Transport.hs | 33 | ||||
-rw-r--r-- | src/Network/Tox/Transport.hs | 4 |
3 files changed, 25 insertions, 14 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 987f742c..eb4c6027 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -208,7 +208,7 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do | |||
208 | data Tox = Tox | 208 | data Tox = Tox |
209 | { toxDHT :: DHT.Client | 209 | { toxDHT :: DHT.Client |
210 | , toxOnion :: Onion.Client RouteId | 210 | , toxOnion :: Onion.Client RouteId |
211 | , toxToRoute :: Transport String Onion.Rendezvous (Asymm (Encrypted Onion.DataToRoute)) | 211 | , toxToRoute :: Transport String Onion.Rendezvous Onion.DataToRoute |
212 | , toxCrypto :: Transport String SockAddr NetCrypto | 212 | , toxCrypto :: Transport String SockAddr NetCrypto |
213 | , toxCryptoKeys :: TransportCrypto | 213 | , toxCryptoKeys :: TransportCrypto |
214 | , toxRouting :: DHT.Routing | 214 | , toxRouting :: DHT.Routing |
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs index bdaef651..4c3de3e6 100644 --- a/src/Network/Tox/Onion/Transport.hs +++ b/src/Network/Tox/Onion/Transport.hs | |||
@@ -738,16 +738,27 @@ instance Show Rendezvous where | |||
738 | parseDataToRoute | 738 | parseDataToRoute |
739 | :: TransportCrypto | 739 | :: TransportCrypto |
740 | -> (OnionMessage Encrypted,OnionDestination r) | 740 | -> (OnionMessage Encrypted,OnionDestination r) |
741 | -> Either (Asymm (Encrypted DataToRoute),Rendezvous) (OnionMessage Encrypted, OnionDestination r) | 741 | -> IO (Either (DataToRoute,Rendezvous) (OnionMessage Encrypted, OnionDestination r)) |
742 | parseDataToRoute crypto (OnionToRouteResponse dta, od) | 742 | parseDataToRoute crypto (OnionToRouteResponse dta, od) = |
743 | = Left ( dta | 743 | return $ either (const $ Right (OnionToRouteResponse dta,od)) Left $ do |
744 | , Rendezvous (rendezvousAliasPublic crypto) $ onionNodeInfo od ) | 744 | -- XXX: Do something with decryption failure? |
745 | parseDataToRoute _ msg = Right msg | 745 | decrypted <- uncomposed |
746 | $ decryptMessage (rendezvousSecret crypto,rendezvousPublic crypto) | ||
747 | (asymmNonce dta) | ||
748 | (Right dta) | ||
749 | return ( runIdentity decrypted | ||
750 | , Rendezvous (rendezvousPublic crypto) $ onionNodeInfo od ) | ||
751 | parseDataToRoute _ msg = return $ Right msg | ||
746 | 752 | ||
747 | encodeDataToRoute :: TransportCrypto | 753 | encodeDataToRoute :: TransportCrypto |
748 | -> (Asymm (Encrypted DataToRoute),Rendezvous) | 754 | -> (DataToRoute,Rendezvous) |
749 | -> Maybe (OnionMessage Encrypted,OnionDestination r) | 755 | -> IO (Maybe (OnionMessage Encrypted,OnionDestination r)) |
750 | encodeDataToRoute crypto (dta, Rendezvous pub ni) | 756 | encodeDataToRoute crypto (plain, Rendezvous pub ni) = do |
751 | = Just ( OnionToRoute pub -- Public key of destination node | 757 | nonce <- atomically $ transportNewNonce crypto |
752 | dta | 758 | let dta = encryptMessage (onionAliasSecret crypto) pub nonce plain |
753 | , OnionDestination SearchingAlias ni Nothing ) | 759 | return $ Just ( OnionToRoute pub -- Public key of destination node |
760 | Asymm { senderKey = onionAliasPublic crypto | ||
761 | , asymmNonce = nonce | ||
762 | , asymmData = dta | ||
763 | } | ||
764 | , OnionDestination SearchingAlias ni Nothing ) | ||
diff --git a/src/Network/Tox/Transport.hs b/src/Network/Tox/Transport.hs index 59c0cf6f..2a4e7eee 100644 --- a/src/Network/Tox/Transport.hs +++ b/src/Network/Tox/Transport.hs | |||
@@ -24,14 +24,14 @@ toxTransport :: | |||
24 | -> UDPTransport | 24 | -> UDPTransport |
25 | -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) | 25 | -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) |
26 | , Transport String (OnionDestination RouteId) (OnionMessage Encrypted) | 26 | , Transport String (OnionDestination RouteId) (OnionMessage Encrypted) |
27 | , Transport String Rendezvous (Asymm (Encrypted DataToRoute)) | 27 | , Transport String Rendezvous DataToRoute |
28 | , Transport String SockAddr NetCrypto ) | 28 | , Transport String SockAddr NetCrypto ) |
29 | toxTransport crypto orouter closeLookup udp = do | 29 | toxTransport crypto orouter closeLookup udp = do |
30 | (dht,udp1) <- partitionTransport parseDHTAddr (Just . encodeDHTAddr) $ forwardOnions crypto udp | 30 | (dht,udp1) <- partitionTransport parseDHTAddr (Just . encodeDHTAddr) $ forwardOnions crypto udp |
31 | (onion1,udp2) <- partitionTransportM (parseOnionAddr $ lookupSender orouter) | 31 | (onion1,udp2) <- partitionTransportM (parseOnionAddr $ lookupSender orouter) |
32 | (encodeOnionAddr $ lookupRoute orouter) | 32 | (encodeOnionAddr $ lookupRoute orouter) |
33 | udp1 | 33 | udp1 |
34 | (dta,onion) <- partitionTransport (parseDataToRoute crypto) (encodeDataToRoute crypto) onion1 | 34 | (dta,onion) <- partitionTransportM (parseDataToRoute crypto) (encodeDataToRoute crypto) onion1 |
35 | let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 | 35 | let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 |
36 | return ( forwardDHTRequests crypto closeLookup dht | 36 | return ( forwardDHTRequests crypto closeLookup dht |
37 | , onion | 37 | , onion |