summaryrefslogtreecommitdiff
path: root/src/Network/Tox.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-01 21:49:53 -0400
committerjoe <joe@jerkface.net>2018-06-01 22:34:04 -0400
commit11dae7ee45996dd76dff47e20dd51d7da49f0a43 (patch)
tree4a9603f4366a7a3d6491b6c6fd027a799590b4a1 /src/Network/Tox.hs
parent45e96346d7ce952f65b44b4e1e3c98287cf4b2da (diff)
tox: Separate transports for handshakes and crypto-packets.
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r--src/Network/Tox.hs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index ce9939a9..6df239b5 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -240,6 +240,7 @@ data Tox = Tox
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 NetCrypto
243 , toxHandshakes :: Transport String SockAddr NetCrypto
243 , toxCryptoSessions :: NetCryptoSessions 244 , toxCryptoSessions :: NetCryptoSessions
244 , toxCryptoKeys :: TransportCrypto 245 , toxCryptoKeys :: TransportCrypto
245 , toxRouting :: DHT.Routing 246 , toxRouting :: DHT.Routing
@@ -439,8 +440,22 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
439 mkrouting <- DHT.newRouting addr crypto updateIP updateIP 440 mkrouting <- DHT.newRouting addr crypto updateIP updateIP
440 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.
441 orouter <- newOnionRouter ignoreErrors 442 orouter <- newOnionRouter ignoreErrors
442 (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp 443 (cryptonet,dhtcrypt,onioncrypt,dtacrypt,handshakes) <- toxTransport crypto orouter lookupClose udp
443 let sessionsState = sessionsState0 { sessionTransport = cryptonet 444
445 -- TODO: Avoid adapting these transports here.
446 let nc_cryptonet = layerTransport (\x addr -> Right (NetCrypto x,addr))
447 (\(NetCrypto x) addr -> (x,addr))
448 cryptonet
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
454 NetCrypto x -> sendMessage cryptonet addr x
455 NetHandshake x -> sendMessage handshakes addr x
456 }
457
458 let sessionsState = sessionsState0 { sessionTransport = nc_combo
444 , transportCrypto = crypto } 459 , transportCrypto = crypto }
445 let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt 460 let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt
446 tbl4 = DHT.routing4 $ mkrouting (error "missing client") 461 tbl4 = DHT.routing4 $ mkrouting (error "missing client")
@@ -465,7 +480,8 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
465 { toxDHT = dhtclient 480 { toxDHT = dhtclient
466 , toxOnion = onionclient 481 , toxOnion = onionclient
467 , toxToRoute = onInbound (updateContactInfo roster) dtacrypt 482 , toxToRoute = onInbound (updateContactInfo roster) dtacrypt
468 , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) cryptonet 483 , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) nc_cryptonet
484 , toxHandshakes = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) nc_handshakes
469 , toxCryptoSessions = sessionsState 485 , toxCryptoSessions = sessionsState
470 , toxCryptoKeys = crypto 486 , toxCryptoKeys = crypto
471 , toxRouting = mkrouting dhtclient 487 , toxRouting = mkrouting dhtclient
@@ -481,10 +497,11 @@ onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTim
481 497
482forkTox :: Tox -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ()) 498forkTox :: Tox -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ())
483forkTox tox = do 499forkTox tox = do
484 _ <- forkListener "toxCrypto" (toxCrypto tox) 500 _ <- forkListener "toxHandshakes" (toxHandshakes tox)
485 _ <- forkListener "toxToRoute" (toxToRoute tox) 501 _ <- forkListener "toxToRoute" (toxToRoute tox)
486 _ <- forkListener "toxOnion" (clientNet $ toxOnion tox) 502 _ <- forkListener "toxOnion" (clientNet $ toxOnion tox)
487 quit <- forkListener "toxDHT" (clientNet $ toxDHT tox) 503 _ <- forkListener "toxDHT" (clientNet $ toxDHT tox)
504 quit <- forkListener "toxCrypto" (toxCrypto tox)
488 forkPollForRefresh (DHT.refresher4 $ toxRouting tox) 505 forkPollForRefresh (DHT.refresher4 $ toxRouting tox)
489 forkPollForRefresh (DHT.refresher6 $ toxRouting tox) 506 forkPollForRefresh (DHT.refresher6 $ toxRouting tox)
490 return ( quit 507 return ( quit