summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs8
-rw-r--r--src/Network/Tox/Crypto/Transport.hs14
2 files changed, 21 insertions, 1 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 356ddf24..1cb9c48e 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -755,7 +755,13 @@ runUponHandshake netCryptoSession0 addr pktoq = do
755 atomically (readTVar (ncRequestInterval netCryptoSession0)) >>= threadDelay 755 atomically (readTVar (ncRequestInterval netCryptoSession0)) >>= threadDelay
756 nums <- atomically $ PQ.getMissing pktq 756 nums <- atomically $ PQ.getMissing pktq
757 dput XNetCrypto $ "(Request Thread) Missing Packets detected:" ++ show nums 757 dput XNetCrypto $ "(Request Thread) Missing Packets detected:" ++ show nums
758 dput XNetCrypto $ "TODO: compose PacketRequest message and send it." 758 getOutGoingParam <- PQ.readyOutGoing pktoq
759 atomically $ do
760 seqno <- PQ.getLastDequeuedPlus1 pktq
761 ogresult <- PQ.tryAppendQueueOutgoing getOutGoingParam pktoq (createRequestPacket seqno nums)
762 case ogresult of
763 PQ.OGSuccess -> return ()
764 _ -> retry
759 loop 765 loop
760 dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr 766 dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr
761 -- launch dequeueOutgoing thread 767 -- launch dequeueOutgoing thread
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs
index fab0f3e2..67950854 100644
--- a/src/Network/Tox/Crypto/Transport.hs
+++ b/src/Network/Tox/Crypto/Transport.hs
@@ -8,6 +8,7 @@ module Network.Tox.Crypto.Transport
8 ( parseCrypto 8 ( parseCrypto
9 , encodeCrypto 9 , encodeCrypto
10 , unpadCryptoMsg 10 , unpadCryptoMsg
11 , createRequestPacket
11 , parseHandshakes 12 , parseHandshakes
12 , encodeHandshakes 13 , encodeHandshakes
13 , CryptoData(..) 14 , CryptoData(..)
@@ -93,6 +94,19 @@ parseHandshakes bs _ = Left $ "parseHandshakes_:
93encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) 94encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr)
94encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) 95encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr)
95 96
97createRequestPacket :: Word32 -> [Word32] -> CryptoMessage
98createRequestPacket seqno xs = UpToN PacketRequest (B.pack ns)
99 where
100 ys = Prelude.map (subtract seqno) xs
101 reduceToSums [] = []
102 reduceToSums (x:xs) = x:(reduceToSums $ Prelude.map (subtract x) xs)
103 makeZeroes :: Word32 -> [Word32]
104 makeZeroes x
105 = let (d,m)= x `divMod` 255
106 zeros= Prelude.replicate (fromIntegral d) 0
107 in zeros ++ [m]
108 ns :: [Word8]
109 ns = Prelude.map fromIntegral (reduceToSums ys >>= makeZeroes)
96 110
97data Handshake (f :: * -> *) = Handshake 111data Handshake (f :: * -> *) = Handshake
98 { -- The cookie is a cookie obtained by 112 { -- The cookie is a cookie obtained by