diff options
author | Joe Crayne <joe@jerkface.net> | 2018-12-10 09:47:57 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-12-16 14:08:26 -0500 |
commit | c4c381a5e9295e14382404e88a98af27690c5ec9 (patch) | |
tree | a5c20b8e33dbfbc458def7066db24937468bcfa2 /src/Network | |
parent | 739c62c21fad363483c5ec70f1050393bd14964c (diff) |
TCP bug fix: length is 16 bits.
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Tox/TCP.hs | 9 |
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 | |||
16 | import Data.Hashable | 16 | import Data.Hashable |
17 | import qualified Data.HashMap.Strict as HashMap | 17 | import qualified Data.HashMap.Strict as HashMap |
18 | import Data.IP | 18 | import Data.IP |
19 | import Data.Monoid | ||
19 | import Data.Serialize | 20 | import Data.Serialize |
20 | import Data.Word | 21 | import Data.Word |
21 | import qualified Data.Vector as Vector | 22 | import qualified Data.Vector as Vector |
@@ -23,7 +24,7 @@ import Network.Socket (SockAddr(..)) | |||
23 | import qualified Text.ParserCombinators.ReadP as RP | 24 | import qualified Text.ParserCombinators.ReadP as RP |
24 | 25 | ||
25 | import Crypto.Tox | 26 | import Crypto.Tox |
26 | import Data.ByteString (hPut,hGet,ByteString) | 27 | import Data.ByteString (hPut,hGet,ByteString,length) |
27 | import Data.Tox.Relay | 28 | import Data.Tox.Relay |
28 | import qualified Data.Word64Map | 29 | import qualified Data.Word64Map |
29 | import DebugTag | 30 | import 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 |