diff options
author | joe <joe@jerkface.net> | 2018-06-01 23:54:26 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-01 23:54:26 -0400 |
commit | fb14227aa2b843e372d57d267e6a9e8921c82877 (patch) | |
tree | db78516a0745bfb2fcefd7d135fd5db9f363f029 | |
parent | 05e750fef5cdf54ffa9e28f2a40286efcaa988a0 (diff) |
More informative types on toxCrypto/toxHandshakes.
-rw-r--r-- | src/Network/Tox.hs | 29 |
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 | |||
97 | import Data.Word64Map (fitsInInt) | 97 | import Data.Word64Map (fitsInInt) |
98 | import qualified Data.Word64Map (empty) | 98 | import qualified Data.Word64Map (empty) |
99 | import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) | 99 | import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) |
100 | import Network.Tox.Crypto.Transport (NetCrypto(..), CryptoMessage, HandshakeData(..), Handshake(..)) | 100 | import Network.Tox.Crypto.Transport (NetCrypto(..), CryptoMessage, HandshakeData(..), Handshake(..),CryptoPacket) |
101 | import Network.Tox.Crypto.Handlers | 101 | import Network.Tox.Crypto.Handlers |
102 | import qualified Network.Tox.DHT.Handlers as DHT | 102 | import qualified Network.Tox.DHT.Handlers as DHT |
103 | import qualified Network.Tox.DHT.Transport as DHT | 103 | import 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 |