summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-11-23 03:03:51 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-11-23 03:04:33 +0000
commitc2937cc29fed0b09fbbdb7fe58fe49adc46b5d37 (patch)
tree30bcba9c6e928c7cf1f6ae318bfd375af5d70ab1 /src/Network/Tox
parentde34b6ec46a7136c249c95d97de3a569cd60b835 (diff)
dequeueOutgoing thread
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 50dd8c67..ef7afe98 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -3,6 +3,7 @@
3{-# LANGUAGE TypeOperators #-} 3{-# LANGUAGE TypeOperators #-}
4module Network.Tox.Crypto.Handlers where 4module Network.Tox.Crypto.Handlers where
5 5
6import Network.QueryResponse
6import Network.Tox.NodeId 7import Network.Tox.NodeId
7import Network.Tox.Crypto.Transport 8import Network.Tox.Crypto.Transport
8import Network.Tox.DHT.Transport (Cookie(..),CookieData(..), CookieRequest(..), NoSpam(..)) 9import Network.Tox.DHT.Transport (Cookie(..),CookieData(..), CookieRequest(..), NoSpam(..))
@@ -127,6 +128,7 @@ data NetCryptoSessions = NCSessions
127 , outboundQueueCapacity :: Word32 128 , outboundQueueCapacity :: Word32
128 , nextSessionId :: TVar SessionID 129 , nextSessionId :: TVar SessionID
129 , announceNewSessionHooks :: TVar [IOHook (Maybe NoSpam) NetCryptoSession] 130 , announceNewSessionHooks :: TVar [IOHook (Maybe NoSpam) NetCryptoSession]
131 , sessionTransport :: Transport String SockAddr NetCrypto
130 } 132 }
131 133
132type NewSessionHook = IOHook (Maybe NoSpam) NetCryptoSession 134type NewSessionHook = IOHook (Maybe NoSpam) NetCryptoSession
@@ -190,6 +192,7 @@ newSessionsState crypto unrechook hooks = do
190 , outboundQueueCapacity = 400 192 , outboundQueueCapacity = 400
191 , nextSessionId = nextSessionId0 193 , nextSessionId = nextSessionId0
192 , announceNewSessionHooks = announceNewSessionHooks0 194 , announceNewSessionHooks = announceNewSessionHooks0
195 , sessionTransport = error "Need to set sessionTransport field of NetCryptoSessions!"
193 } 196 }
194 197
195data HandshakeParams 198data HandshakeParams
@@ -376,6 +379,14 @@ freshCryptoSession sessions
376 cd <- atomically $ PQ.dequeue pktq 379 cd <- atomically $ PQ.dequeue pktq
377 _ <- runCryptoHook (netCryptoSession0 {ncDequeueThread=Just tid}) cd 380 _ <- runCryptoHook (netCryptoSession0 {ncDequeueThread=Just tid}) cd
378 loop 381 loop
382 -- launch dequeueOutgoing thread
383 threadidOutgoing <- forkIO $ do
384 tid <- myThreadId
385 labelThread tid ("NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey))
386 fix $ \loop -> do
387 (_,pkt) <- atomically $ PQ.dequeueOutgoing pktoq
388 sendMessage (sessionTransport sessions) addr (NetCrypto pkt)
389 loop
379 -- launch ping thread 390 -- launch ping thread
380 fuzz <- randomRIO (0,2000) 391 fuzz <- randomRIO (0,2000)
381 pingMachine <- forkPingMachine ("NetCrypto." ++ show (key2id remotePublicKey)) (15000 + fuzz) 2000 392 pingMachine <- forkPingMachine ("NetCrypto." ++ show (key2id remotePublicKey)) (15000 + fuzz) 2000