summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto
diff options
context:
space:
mode:
authorjim@bo <jim@bo>2018-06-21 05:55:32 -0400
committerjim@bo <jim@bo>2018-06-21 05:55:32 -0400
commit43aced9d6c73135a21c877a79e7e5c920cebe5bb (patch)
treefb49808fc3ce7fe898683d696585f30e1033e833 /src/Network/Tox/Crypto
parent064aba3a5dcf255015dcd2d4da7d4811c22287c9 (diff)
Packet request Thread, ready for testing
Diffstat (limited to 'src/Network/Tox/Crypto')
-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