summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 3336052b..5192e180 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -768,9 +768,21 @@ runUponHandshake netCryptoSession0 addr pktoq = do
768 sendSessionPacket sessions addr pkt 768 sendSessionPacket sessions addr pkt
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 thread 771 -- launch ping Machine thread
772 fuzz <- randomRIO (0,2000) 772 fuzz <- randomRIO (0,2000)
773 pingMachine <- forkPingMachine ("NetCrypto." ++ show (key2id remotePublicKey)) (15000 + fuzz) 2000 773 pingMachine <- forkPingMachine ("NetCrypto." ++ show (key2id remotePublicKey)) (15000 + fuzz) 2000
774 pingThreadId <- forkIO $ do
775 tid <- myThreadId
776 event <- atomically $ pingWait pingMachine
777 labelThread tid ("NetCryptoPingSender." ++ show (key2id remotePublicKey) ++ "." ++ show (ncSessionId netCryptoSession0))
778 case event of
779 PingIdle -> do
780 dput XNetCrypto $ "pingThread (session: " ++ show (ncSessionId netCryptoSession0) ++ ") PingIdle"
781 lr <- sendPing crypto netCryptoSession0
782 case lr of
783 Left s -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") " ++ s
784 Right _ -> return ()
785 PingTimeOut -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") PingTimeOut TODO"
774 -- update session with thread ids 786 -- update session with thread ids
775 let netCryptoSession = netCryptoSession0 {ncDequeueThread=Just threadid, ncPingMachine=Just pingMachine} 787 let netCryptoSession = netCryptoSession0 {ncDequeueThread=Just threadid, ncPingMachine=Just pingMachine}
776 -- add this session to the lookup maps 788 -- add this session to the lookup maps
@@ -1173,6 +1185,12 @@ sendCrypto crypto session updateLocal cm = do
1173 PQ.OGFull -> return (Left "Outgoing packet buffer is full") 1185 PQ.OGFull -> return (Left "Outgoing packet buffer is full")
1174 PQ.OGEncodeFail -> return (Left "Failed to encode outgoing packet") 1186 PQ.OGEncodeFail -> return (Left "Failed to encode outgoing packet")
1175 1187
1188sendPing :: TransportCrypto -> NetCryptoSession -> IO (Either String ())
1189sendPing crypto session = do
1190 let cm=OneByte PING
1191 addMsgToLastN False (cm ^. messageType) session (Out cm)
1192 sendCrypto crypto session (return ()) (OneByte PING)
1193
1176sendOnline :: TransportCrypto -> NetCryptoSession -> IO (Either String ()) 1194sendOnline :: TransportCrypto -> NetCryptoSession -> IO (Either String ())
1177sendOnline crypto session = do 1195sendOnline crypto session = do
1178 let cm=OneByte ONLINE 1196 let cm=OneByte ONLINE