summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-12-10 09:47:57 -0500
committerJoe Crayne <joe@jerkface.net>2018-12-16 14:08:26 -0500
commitc4c381a5e9295e14382404e88a98af27690c5ec9 (patch)
treea5c20b8e33dbfbc458def7066db24937468bcfa2 /src/Network
parent739c62c21fad363483c5ec70f1050393bd14964c (diff)
TCP bug fix: length is 16 bits.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox/TCP.hs9
1 files changed, 6 insertions, 3 deletions
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
16import Data.Hashable 16import Data.Hashable
17import qualified Data.HashMap.Strict as HashMap 17import qualified Data.HashMap.Strict as HashMap
18import Data.IP 18import Data.IP
19import Data.Monoid
19import Data.Serialize 20import Data.Serialize
20import Data.Word 21import Data.Word
21import qualified Data.Vector as Vector 22import qualified Data.Vector as Vector
@@ -23,7 +24,7 @@ import Network.Socket (SockAddr(..))
23import qualified Text.ParserCombinators.ReadP as RP 24import qualified Text.ParserCombinators.ReadP as RP
24 25
25import Crypto.Tox 26import Crypto.Tox
26import Data.ByteString (hPut,hGet,ByteString) 27import Data.ByteString (hPut,hGet,ByteString,length)
27import Data.Tox.Relay 28import Data.Tox.Relay
28import qualified Data.Word64Map 29import qualified Data.Word64Map
29import DebugTag 30import DebugTag
@@ -124,7 +125,7 @@ tcpStream crypto = StreamHandshake
124 decode <$> hGet h 2 >>= \case 125 decode <$> hGet h 2 >>= \case
125 Left _ -> return Nothing 126 Left _ -> return Nothing
126 Right len -> do 127 Right len -> do
127 decode <$> hGet h len >>= \case 128 decode <$> hGet h (fromIntegral (len :: Word16)) >>= \case
128 Left _ -> return Nothing 129 Left _ -> return Nothing
129 Right x -> do 130 Right x -> do
130 n24 <- takeMVar nread 131 n24 <- takeMVar nread
@@ -133,7 +134,9 @@ tcpStream crypto = StreamHandshake
133 return $ either (const Nothing) Just r 134 return $ either (const Nothing) Just r
134 , streamEncode = \y -> do 135 , streamEncode = \y -> do
135 n24 <- takeMVar nsend 136 n24 <- takeMVar nsend
136 hPut h $ encode $ encrypt (noncef' n24) $ encodePlain y 137 let bs = encode $ encrypt (noncef' n24) $ encodePlain y
138 hPut h $ encode (fromIntegral $ Data.ByteString.length bs :: Word16)
139 <> bs
137 putMVar nsend (incrementNonce24 n24) 140 putMVar nsend (incrementNonce24 n24)
138 } 141 }
139 , streamAddr = nodeAddr 142 , streamAddr = nodeAddr