summaryrefslogtreecommitdiff
path: root/src/Network/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r--src/Network/Tox.hs29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index 6df239b5..8b966266 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -97,7 +97,7 @@ import Crypto.Tox
97import Data.Word64Map (fitsInInt) 97import Data.Word64Map (fitsInInt)
98import qualified Data.Word64Map (empty) 98import qualified Data.Word64Map (empty)
99import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) 99import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap)
100import Network.Tox.Crypto.Transport (NetCrypto(..), CryptoMessage, HandshakeData(..), Handshake(..)) 100import Network.Tox.Crypto.Transport (NetCrypto(..), CryptoMessage, HandshakeData(..), Handshake(..),CryptoPacket)
101import Network.Tox.Crypto.Handlers 101import Network.Tox.Crypto.Handlers
102import qualified Network.Tox.DHT.Handlers as DHT 102import qualified Network.Tox.DHT.Handlers as DHT
103import qualified Network.Tox.DHT.Transport as DHT 103import qualified Network.Tox.DHT.Transport as DHT
@@ -239,8 +239,8 @@ data Tox = Tox
239 { toxDHT :: DHT.Client 239 { toxDHT :: DHT.Client
240 , toxOnion :: Onion.Client RouteId 240 , toxOnion :: Onion.Client RouteId
241 , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) 241 , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData)
242 , toxCrypto :: Transport String SockAddr NetCrypto 242 , toxCrypto :: Transport String SockAddr (CryptoPacket Encrypted)
243 , toxHandshakes :: Transport String SockAddr NetCrypto 243 , toxHandshakes :: Transport String SockAddr (Handshake Encrypted)
244 , toxCryptoSessions :: NetCryptoSessions 244 , toxCryptoSessions :: NetCryptoSessions
245 , toxCryptoKeys :: TransportCrypto 245 , toxCryptoKeys :: TransportCrypto
246 , toxRouting :: DHT.Routing 246 , toxRouting :: DHT.Routing
@@ -441,22 +441,17 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
441 let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. 441 let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building.
442 orouter <- newOnionRouter ignoreErrors 442 orouter <- newOnionRouter ignoreErrors
443 (cryptonet,dhtcrypt,onioncrypt,dtacrypt,handshakes) <- toxTransport crypto orouter lookupClose udp 443 (cryptonet,dhtcrypt,onioncrypt,dtacrypt,handshakes) <- toxTransport crypto orouter lookupClose udp
444 444 let sessionsState = sessionsState0 { sessionTransport = nc_combo
445 -- TODO: Avoid adapting these transports here. 445 , transportCrypto = crypto }
446 let nc_cryptonet = layerTransport (\x addr -> Right (NetCrypto x,addr)) 446 where
447 (\(NetCrypto x) addr -> (x,addr)) 447 -- TODO: This send-only transport is obviated by it's two components.
448 cryptonet 448 nc_combo = Transport
449 nc_handshakes = layerTransport (\x addr -> Right (NetHandshake x,addr))
450 (\(NetHandshake x) addr -> (x,addr))
451 handshakes
452 nc_combo = nc_handshakes
453 { sendMessage = \addr -> \case 449 { sendMessage = \addr -> \case
454 NetCrypto x -> sendMessage cryptonet addr x 450 NetCrypto x -> sendMessage cryptonet addr x
455 NetHandshake x -> sendMessage handshakes addr x 451 NetHandshake x -> sendMessage handshakes addr x
452 , awaitMessage = \_ -> throwIO (userError "oops: awaitMessage nc_combo")
453 , closeTransport = hPutStrLn stderr "oops: closeTransport nc_combo"
456 } 454 }
457
458 let sessionsState = sessionsState0 { sessionTransport = nc_combo
459 , transportCrypto = crypto }
460 let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt 455 let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt
461 tbl4 = DHT.routing4 $ mkrouting (error "missing client") 456 tbl4 = DHT.routing4 $ mkrouting (error "missing client")
462 tbl6 = DHT.routing6 $ mkrouting (error "missing client") 457 tbl6 = DHT.routing6 $ mkrouting (error "missing client")
@@ -480,8 +475,8 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
480 { toxDHT = dhtclient 475 { toxDHT = dhtclient
481 , toxOnion = onionclient 476 , toxOnion = onionclient
482 , toxToRoute = onInbound (updateContactInfo roster) dtacrypt 477 , toxToRoute = onInbound (updateContactInfo roster) dtacrypt
483 , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) nc_cryptonet 478 , toxCrypto = addHandler (hPutStrLn stderr) (sessionPacketH sessionsState) cryptonet
484 , toxHandshakes = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) nc_handshakes 479 , toxHandshakes = addHandler (hPutStrLn stderr) (handshakeH sessionsState) handshakes
485 , toxCryptoSessions = sessionsState 480 , toxCryptoSessions = sessionsState
486 , toxCryptoKeys = crypto 481 , toxCryptoKeys = crypto
487 , toxRouting = mkrouting dhtclient 482 , toxRouting = mkrouting dhtclient