summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox.hs3
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs11
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index dfa0ea9e..aa95df81 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -310,7 +310,7 @@ newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rende
310 -> IO Tox 310 -> IO Tox
311newTox keydb addr mbSessionsState suppliedDHTKey = do 311newTox keydb addr mbSessionsState suppliedDHTKey = do
312 udp <- {- addVerbosity <$> -} udpTransport addr 312 udp <- {- addVerbosity <$> -} udpTransport addr
313 (crypto0,sessionsState) <- case mbSessionsState of 313 (crypto0,sessionsState0) <- case mbSessionsState of
314 Nothing -> do 314 Nothing -> do
315 crypto <- newCrypto 315 crypto <- newCrypto
316 sessionsState <- newSessionsState crypto defaultUnRecHook defaultCryptoDataHooks 316 sessionsState <- newSessionsState crypto defaultUnRecHook defaultCryptoDataHooks
@@ -335,6 +335,7 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
335 let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. 335 let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building.
336 orouter <- newOnionRouter ignoreErrors 336 orouter <- newOnionRouter ignoreErrors
337 (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp 337 (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp
338 let sessionsState = sessionsState0 { sessionTransport = cryptonet }
338 let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt 339 let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt
339 tbl4 = DHT.routing4 $ mkrouting (error "missing client") 340 tbl4 = DHT.routing4 $ mkrouting (error "missing client")
340 tbl6 = DHT.routing6 $ mkrouting (error "missing client") 341 tbl6 = DHT.routing6 $ mkrouting (error "missing client")
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