From 0f0ccf566b6df2a1b1ad08f2781f7fd29926dde6 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 15 Sep 2017 04:32:05 -0400 Subject: Moved ToxTransport to its hierarchical location. --- Tox.hs | 2 +- ToxTransport.hs | 71 -------------------------------------------- src/Network/Tox/Transport.hs | 71 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 ToxTransport.hs create mode 100644 src/Network/Tox/Transport.hs diff --git a/Tox.hs b/Tox.hs index 6dce9757..98c3811b 100644 --- a/Tox.hs +++ b/Tox.hs @@ -84,7 +84,7 @@ import Network.BitTorrent.DHT.Token as Token import GHC.TypeLits import Crypto.Tox hiding (Assym) -import ToxTransport +import Network.Tox.Transport import Network.Tox.Address import qualified Network.Tox.DHT.Transport as DHT import qualified Network.Tox.DHT.Handlers as DHT diff --git a/ToxTransport.hs b/ToxTransport.hs deleted file mode 100644 index 239000b0..00000000 --- a/ToxTransport.hs +++ /dev/null @@ -1,71 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE TypeOperators #-} -module ToxTransport (toxTransport) where - -import Network.QueryResponse -import Crypto.Tox -import Network.Tox.DHT.Transport -import Network.Tox.Onion.Transport -import Network.Tox.Crypto.Transport - -import Network.Socket - -toxTransport :: - TransportCrypto - -> (PublicKey -> IO (Maybe NodeInfo)) - -> UDPTransport - -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) - , Transport String OnionToOwner (OnionMessage Encrypted) - , Transport String SockAddr NetCrypto ) -toxTransport crypto closeLookup udp = do - (dht,udp1) <- partitionTransport parseDHTAddr encodeDHTAddr id $ forwardOnions crypto udp - (onion,udp2) <- partitionTransport parseOnionAddr encodeOnionAddr id udp1 - let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 - return ( forwardDHTRequests crypto closeLookup dht - , onion - , netcrypto - ) - - --- instance (Sized a, Sized b) => Sized (a,b) where size = _todo - - --- Byte value Packet Kind Return address --- :----------- :-------------------- --- `0x00` Ping Request DHTNode --- `0x01` Ping Response - --- `0x02` Nodes Request DHTNode --- `0x04` Nodes Response - --- `0x18` Cookie Request DHTNode, but without sending pubkey in response --- `0x19` Cookie Response - (no pubkey) --- --- `0x21` LAN Discovery DHTNode (No reply, port 33445, trigger Nodes Request/Response) --- --- `0x20` DHT Request DHTNode/-forward --- --- `0x1a` Crypto Handshake CookieAddress --- --- `0x1b` Crypto Data SessionAddress --- --- `0x83` Announce Request OnionToOwner --- `0x84` Announce Response - --- `0x85` Onion Data Request OnionToOwner --- `0x86` Onion Data Response - --- --- `0xf0` Bootstrap Info SockAddr? --- --- `0x80` Onion Request 0 -forward --- `0x81` Onion Request 1 -forward --- `0x82` Onion Request 2 -forward --- `0x8c` Onion Response 3 -return --- `0x8d` Onion Response 2 -return --- `0x8e` Onion Response 1 -return - - - diff --git a/src/Network/Tox/Transport.hs b/src/Network/Tox/Transport.hs new file mode 100644 index 00000000..24bd60b7 --- /dev/null +++ b/src/Network/Tox/Transport.hs @@ -0,0 +1,71 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE TypeOperators #-} +module Network.Tox.Transport (toxTransport) where + +import Network.QueryResponse +import Crypto.Tox +import Network.Tox.DHT.Transport +import Network.Tox.Onion.Transport +import Network.Tox.Crypto.Transport + +import Network.Socket + +toxTransport :: + TransportCrypto + -> (PublicKey -> IO (Maybe NodeInfo)) + -> UDPTransport + -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) + , Transport String OnionToOwner (OnionMessage Encrypted) + , Transport String SockAddr NetCrypto ) +toxTransport crypto closeLookup udp = do + (dht,udp1) <- partitionTransport parseDHTAddr encodeDHTAddr id $ forwardOnions crypto udp + (onion,udp2) <- partitionTransport parseOnionAddr encodeOnionAddr id udp1 + let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 + return ( forwardDHTRequests crypto closeLookup dht + , onion + , netcrypto + ) + + +-- instance (Sized a, Sized b) => Sized (a,b) where size = _todo + + +-- Byte value Packet Kind Return address +-- :----------- :-------------------- +-- `0x00` Ping Request DHTNode +-- `0x01` Ping Response - +-- `0x02` Nodes Request DHTNode +-- `0x04` Nodes Response - +-- `0x18` Cookie Request DHTNode, but without sending pubkey in response +-- `0x19` Cookie Response - (no pubkey) +-- +-- `0x21` LAN Discovery DHTNode (No reply, port 33445, trigger Nodes Request/Response) +-- +-- `0x20` DHT Request DHTNode/-forward +-- +-- `0x1a` Crypto Handshake CookieAddress +-- +-- `0x1b` Crypto Data SessionAddress +-- +-- `0x83` Announce Request OnionToOwner +-- `0x84` Announce Response - +-- `0x85` Onion Data Request OnionToOwner +-- `0x86` Onion Data Response - +-- +-- `0xf0` Bootstrap Info SockAddr? +-- +-- `0x80` Onion Request 0 -forward +-- `0x81` Onion Request 1 -forward +-- `0x82` Onion Request 2 -forward +-- `0x8c` Onion Response 3 -return +-- `0x8d` Onion Response 2 -return +-- `0x8e` Onion Response 1 -return + + + -- cgit v1.2.3