From c4c381a5e9295e14382404e88a98af27690c5ec9 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Mon, 10 Dec 2018 09:47:57 -0500 Subject: TCP bug fix: length is 16 bits. --- src/Network/Tox/TCP.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/Network') diff --git a/src/Network/Tox/TCP.hs b/src/Network/Tox/TCP.hs index eede869f..5c6456f6 100644 --- a/src/Network/Tox/TCP.hs +++ b/src/Network/Tox/TCP.hs @@ -16,6 +16,7 @@ import Data.Functor.Identity import Data.Hashable import qualified Data.HashMap.Strict as HashMap import Data.IP +import Data.Monoid import Data.Serialize import Data.Word import qualified Data.Vector as Vector @@ -23,7 +24,7 @@ import Network.Socket (SockAddr(..)) import qualified Text.ParserCombinators.ReadP as RP import Crypto.Tox -import Data.ByteString (hPut,hGet,ByteString) +import Data.ByteString (hPut,hGet,ByteString,length) import Data.Tox.Relay import qualified Data.Word64Map import DebugTag @@ -124,7 +125,7 @@ tcpStream crypto = StreamHandshake decode <$> hGet h 2 >>= \case Left _ -> return Nothing Right len -> do - decode <$> hGet h len >>= \case + decode <$> hGet h (fromIntegral (len :: Word16)) >>= \case Left _ -> return Nothing Right x -> do n24 <- takeMVar nread @@ -133,7 +134,9 @@ tcpStream crypto = StreamHandshake return $ either (const Nothing) Just r , streamEncode = \y -> do n24 <- takeMVar nsend - hPut h $ encode $ encrypt (noncef' n24) $ encodePlain y + let bs = encode $ encrypt (noncef' n24) $ encodePlain y + hPut h $ encode (fromIntegral $ Data.ByteString.length bs :: Word16) + <> bs putMVar nsend (incrementNonce24 n24) } , streamAddr = nodeAddr -- cgit v1.2.3