diff options
Diffstat (limited to 'src/Network/Tox')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 4 | ||||
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 13 |
2 files changed, 14 insertions, 3 deletions
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 | |||
1133 | else do dput XNetCrypto $ "enqueue ncPacketQueue Lossless " ++ show cm | 1133 | else do dput XNetCrypto $ "enqueue ncPacketQueue Lossless " ++ show cm |
1134 | when (msgID cm == PING) $ | 1134 | when (msgID cm == PING) $ |
1135 | dput XNetCrypto $ "NetCrypto Recieved PING (session " ++ show ncSessionId ++")" | 1135 | dput XNetCrypto $ "NetCrypto Recieved PING (session " ++ show ncSessionId ++")" |
1136 | when (msgID cm == PacketRequest) . atomically $ do | 1136 | when (msgID cm == PacketRequest) $ do |
1137 | dput XNetCrypto $ "PACKETREquest: " ++ showCryptoMsg bufferEnd cm | ||
1138 | atomically $ do | ||
1137 | num <- CB.getNextSequenceNum ncStoredRequests | 1139 | num <- CB.getNextSequenceNum ncStoredRequests |
1138 | CB.enqueue ncStoredRequests num cd | 1140 | CB.enqueue ncStoredRequests num cd |
1139 | atomically $ PQ.enqueue ncPacketQueue bufferEnd cd | 1141 | 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 @@ | |||
6 | {-# LANGUAGE TupleSections #-} | 6 | {-# LANGUAGE TupleSections #-} |
7 | {-# LANGUAGE StandaloneDeriving #-} | 7 | {-# LANGUAGE StandaloneDeriving #-} |
8 | module Network.Tox.Crypto.Transport | 8 | module Network.Tox.Crypto.Transport |
9 | ( parseCrypto | 9 | ( showCryptoMsg |
10 | , parseCrypto | ||
10 | , encodeCrypto | 11 | , encodeCrypto |
11 | , unpadCryptoMsg | 12 | , unpadCryptoMsg |
12 | , createRequestPacket | 13 | , createRequestPacket |
@@ -77,7 +78,13 @@ import Data.Text as T | |||
77 | import Data.Text.Encoding as T | 78 | import Data.Text.Encoding as T |
78 | import Data.Serialize as S | 79 | import Data.Serialize as S |
79 | import Control.Arrow | 80 | import Control.Arrow |
81 | import DPut | ||
82 | import Data.PacketQueue (toPNums) | ||
83 | import Data.List | ||
80 | 84 | ||
85 | showCryptoMsg :: Word32 -> CryptoMessage -> [Char] | ||
86 | showCryptoMsg seqno (UpToN PacketRequest bytes) = "UpToN PacketRequest --> " ++ show (toPNums seqno $ B.unpack bytes) | ||
87 | showCryptoMsg _ msg = show msg | ||
81 | 88 | ||
82 | parseCrypto :: (ByteString, SockAddr) -> Either (CryptoPacket Encrypted, SockAddr) (ByteString, SockAddr) | 89 | parseCrypto :: (ByteString, SockAddr) -> Either (CryptoPacket Encrypted, SockAddr) (ByteString, SockAddr) |
83 | parseCrypto ((B.uncons -> Just (0x1b,pkt)),saddr) = either (\_ -> Right (pkt,saddr)) | 90 | parseCrypto ((B.uncons -> Just (0x1b,pkt)),saddr) = either (\_ -> Right (pkt,saddr)) |
@@ -96,12 +103,14 @@ encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) | |||
96 | encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) | 103 | encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) |
97 | 104 | ||
98 | createRequestPacket :: Word32 -> [Word32] -> CryptoMessage | 105 | createRequestPacket :: Word32 -> [Word32] -> CryptoMessage |
99 | createRequestPacket seqno xs = UpToN PacketRequest (B.pack ns) | 106 | createRequestPacket seqno xs = let r = UpToN PacketRequest (B.pack ns) |
107 | in dtrace XNetCrypto ("createRequestPacket " ++ show seqno ++ " " ++ show xs ++ " -----> " ++ show r) r | ||
100 | where | 108 | where |
101 | ys = Prelude.map (subtract (seqno - 1)) xs | 109 | ys = Prelude.map (subtract (seqno - 1)) xs |
102 | reduceToSums [] = [] | 110 | reduceToSums [] = [] |
103 | reduceToSums (x:xs) = x:(reduceToSums $ Prelude.map (subtract x) xs) | 111 | reduceToSums (x:xs) = x:(reduceToSums $ Prelude.map (subtract x) xs) |
104 | makeZeroes :: Word32 -> [Word32] | 112 | makeZeroes :: Word32 -> [Word32] |
113 | -- makeZeroes 0 = [] | ||
105 | makeZeroes x | 114 | makeZeroes x |
106 | = let (d,m)= x `divMod` 255 | 115 | = let (d,m)= x `divMod` 255 |
107 | zeros= Prelude.replicate (fromIntegral d) 0 | 116 | zeros= Prelude.replicate (fromIntegral d) 0 |