From 5c2c19dfa55f0a319d78411e21fdd0cb5dcc4547 Mon Sep 17 00:00:00 2001 From: "jim@bo" Date: Sun, 24 Jun 2018 07:11:13 -0400 Subject: debug traces of packet request send/recieve --- src/Network/Tox/Crypto/Handlers.hs | 4 +++- src/Network/Tox/Crypto/Transport.hs | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/Network') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 82aa8f12..2e00d61b 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -1133,7 +1133,9 @@ sessionPacketH sessions addrRaw (CryptoPacket nonce16 encrypted) = do else do dput XNetCrypto $ "enqueue ncPacketQueue Lossless " ++ show cm when (msgID cm == PING) $ dput XNetCrypto $ "NetCrypto Recieved PING (session " ++ show ncSessionId ++")" - when (msgID cm == PacketRequest) . atomically $ do + when (msgID cm == PacketRequest) $ do + dput XNetCrypto $ "PACKETREquest: " ++ showCryptoMsg bufferEnd cm + atomically $ do num <- CB.getNextSequenceNum ncStoredRequests CB.enqueue ncStoredRequests num cd atomically $ PQ.enqueue ncPacketQueue bufferEnd cd diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 68e3d8e1..54d96c34 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs @@ -6,7 +6,8 @@ {-# LANGUAGE TupleSections #-} {-# LANGUAGE StandaloneDeriving #-} module Network.Tox.Crypto.Transport - ( parseCrypto + ( showCryptoMsg + , parseCrypto , encodeCrypto , unpadCryptoMsg , createRequestPacket @@ -77,7 +78,13 @@ import Data.Text as T import Data.Text.Encoding as T import Data.Serialize as S import Control.Arrow +import DPut +import Data.PacketQueue (toPNums) +import Data.List +showCryptoMsg :: Word32 -> CryptoMessage -> [Char] +showCryptoMsg seqno (UpToN PacketRequest bytes) = "UpToN PacketRequest --> " ++ show (toPNums seqno $ B.unpack bytes) +showCryptoMsg _ msg = show msg parseCrypto :: (ByteString, SockAddr) -> Either (CryptoPacket Encrypted, SockAddr) (ByteString, SockAddr) parseCrypto ((B.uncons -> Just (0x1b,pkt)),saddr) = either (\_ -> Right (pkt,saddr)) @@ -96,12 +103,14 @@ encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) createRequestPacket :: Word32 -> [Word32] -> CryptoMessage -createRequestPacket seqno xs = UpToN PacketRequest (B.pack ns) +createRequestPacket seqno xs = let r = UpToN PacketRequest (B.pack ns) + in dtrace XNetCrypto ("createRequestPacket " ++ show seqno ++ " " ++ show xs ++ " -----> " ++ show r) r where ys = Prelude.map (subtract (seqno - 1)) xs reduceToSums [] = [] reduceToSums (x:xs) = x:(reduceToSums $ Prelude.map (subtract x) xs) makeZeroes :: Word32 -> [Word32] + -- makeZeroes 0 = [] makeZeroes x = let (d,m)= x `divMod` 255 zeros= Prelude.replicate (fromIntegral d) 0 -- cgit v1.2.3