diff options
author | jim@bo <jim@bo> | 2018-06-21 05:55:32 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-21 05:55:32 -0400 |
commit | 43aced9d6c73135a21c877a79e7e5c920cebe5bb (patch) | |
tree | fb49808fc3ce7fe898683d696585f30e1033e833 /src/Network/Tox/Crypto | |
parent | 064aba3a5dcf255015dcd2d4da7d4811c22287c9 (diff) |
Packet request Thread, ready for testing
Diffstat (limited to 'src/Network/Tox/Crypto')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 8 | ||||
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 14 |
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_: | |||
93 | encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) | 94 | encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) |
94 | encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) | 95 | encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) |
95 | 96 | ||
97 | createRequestPacket :: Word32 -> [Word32] -> CryptoMessage | ||
98 | createRequestPacket 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 | ||
97 | data Handshake (f :: * -> *) = Handshake | 111 | data Handshake (f :: * -> *) = Handshake |
98 | { -- The cookie is a cookie obtained by | 112 | { -- The cookie is a cookie obtained by |