summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Onion/Transport.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Onion/Transport.hs')
-rw-r--r--src/Network/Tox/Onion/Transport.hs33
1 files changed, 22 insertions, 11 deletions
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
738parseDataToRoute 738parseDataToRoute
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))
742parseDataToRoute crypto (OnionToRouteResponse dta, od) 742parseDataToRoute 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?
745parseDataToRoute _ 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 )
751parseDataToRoute _ msg = return $ Right msg
746 752
747encodeDataToRoute :: TransportCrypto 753encodeDataToRoute :: TransportCrypto
748 -> (Asymm (Encrypted DataToRoute),Rendezvous) 754 -> (DataToRoute,Rendezvous)
749 -> Maybe (OnionMessage Encrypted,OnionDestination r) 755 -> IO (Maybe (OnionMessage Encrypted,OnionDestination r))
750encodeDataToRoute crypto (dta, Rendezvous pub ni) 756encodeDataToRoute 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 )