summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-17 23:23:04 -0400
committerjoe <joe@jerkface.net>2018-06-17 23:23:04 -0400
commit1784d1ff2e6c4197bf18824688691ebf7aa7ab3d (patch)
tree1c1c83e5bc627c720a6a783e71cfad6e3e6368d1 /src/Network/Tox/Crypto/Handlers.hs
parentbbc451970f54f675bd5f8b7ed2fe9bbed97a1d23 (diff)
Adjusted ping behavior for toxcore compatibility.
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 5192e180..2632c936 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -769,8 +769,9 @@ runUponHandshake netCryptoSession0 addr pktoq = do
769 loop 769 loop
770 dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey) 770 dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey)
771 -- launch ping Machine thread 771 -- launch ping Machine thread
772 fuzz <- randomRIO (0,2000) 772 fuzz <- return 0 -- randomRIO (0,2000) -- Fuzz to prevent simultaneous ping/pong exchanges.
773 pingMachine <- forkPingMachine ("NetCrypto." ++ show (key2id remotePublicKey)) (15000 + fuzz) 2000 773 -- Disabled because tox has no pong event.
774 pingMachine <- forkPingMachine ("NetCrypto." ++ show (key2id remotePublicKey)) (8000 + fuzz) 4000
774 pingThreadId <- forkIO $ do 775 pingThreadId <- forkIO $ do
775 tid <- myThreadId 776 tid <- myThreadId
776 event <- atomically $ pingWait pingMachine 777 event <- atomically $ pingWait pingMachine
@@ -778,6 +779,12 @@ runUponHandshake netCryptoSession0 addr pktoq = do
778 case event of 779 case event of
779 PingIdle -> do 780 PingIdle -> do
780 dput XNetCrypto $ "pingThread (session: " ++ show (ncSessionId netCryptoSession0) ++ ") PingIdle" 781 dput XNetCrypto $ "pingThread (session: " ++ show (ncSessionId netCryptoSession0) ++ ") PingIdle"
782 -- Normally, we would not bump the PingMachine until we receive
783 -- an inbound packet. We are doing this here because tox has
784 -- no pong response packet and so we need to mark the
785 -- connection non-idle here. Doing this prevents a PingTimeOut
786 -- from ever occurring. (TODO: handle timed-out sessions somehow.)
787 pingBump pingMachine
781 lr <- sendPing crypto netCryptoSession0 788 lr <- sendPing crypto netCryptoSession0
782 case lr of 789 case lr of
783 Left s -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") " ++ s 790 Left s -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") " ++ s
@@ -1043,7 +1050,13 @@ sessionPacketH sessions addrRaw (CryptoPacket nonce16 encrypted) = do
1043 atomically $ writeTVar ncState {-Confirmed-}Established 1050 atomically $ writeTVar ncState {-Confirmed-}Established
1044 -- bump ping machine 1051 -- bump ping machine
1045 case ncPingMachine of 1052 case ncPingMachine of
1046 Just pingMachine -> pingBump pingMachine 1053 Just pingMachine -> -- Normally, we would bump the PingMachine to mark the connection
1054 -- as non-idle so that we don't need to send a ping message.
1055 -- Because tox has no pong message, we need to send a ping every
1056 -- eight seconds regardless, so we will let the PingIdle event be
1057 -- signaled even when we receive packets.
1058 -- pingBump pingMachine
1059 return ()
1047 Nothing -> return () 1060 Nothing -> return ()
1048 msgTypes <- atomically $ readTVar ncIncomingTypeArray 1061 msgTypes <- atomically $ readTVar ncIncomingTypeArray
1049 let msgTyp = cd ^. messageType 1062 let msgTyp = cd ^. messageType