diff options
Diffstat (limited to 'dht/src/Data')
-rw-r--r-- | dht/src/Data/Tox/DHT/Multi.hs | 17 | ||||
-rw-r--r-- | dht/src/Data/Tox/Onion.hs | 5 |
2 files changed, 17 insertions, 5 deletions
diff --git a/dht/src/Data/Tox/DHT/Multi.hs b/dht/src/Data/Tox/DHT/Multi.hs index 3f91387c..f769e384 100644 --- a/dht/src/Data/Tox/DHT/Multi.hs +++ b/dht/src/Data/Tox/DHT/Multi.hs | |||
@@ -7,13 +7,14 @@ | |||
7 | {-# LANGUAGE TypeFamilies #-} | 7 | {-# LANGUAGE TypeFamilies #-} |
8 | module Data.Tox.DHT.Multi where | 8 | module Data.Tox.DHT.Multi where |
9 | 9 | ||
10 | import Crypto.PubKey.Curve25519 (PublicKey) | ||
10 | import qualified Network.Tox.NodeId as UDP | 11 | import qualified Network.Tox.NodeId as UDP |
11 | ;import Network.Tox.NodeId (NodeId) | 12 | ;import Network.Tox.NodeId (NodeId) |
12 | import qualified Network.Tox.TCP.NodeId as TCP | 13 | import qualified Network.Tox.TCP.NodeId as TCP |
13 | import Data.Tox.Relay | 14 | import Data.Tox.Relay hiding (NodeInfo) |
14 | import Network.Address (either4or6) | 15 | import Network.Address (either4or6) |
15 | import Network.Tox.TCP as TCP (ViaRelay(..)) | 16 | import Network.Tox.TCP as TCP (ViaRelay(..), tcpConnectionRequest_) |
16 | import Network.QueryResponse (Tagged(..)) | 17 | import Network.QueryResponse as QR (Tagged(..), Client) |
17 | 18 | ||
18 | import Data.Dependent.Sum | 19 | import Data.Dependent.Sum |
19 | import Data.GADT.Compare | 20 | import Data.GADT.Compare |
@@ -124,3 +125,13 @@ relayNodeId (ViaRelay _ nid _) = nid | |||
124 | udpNode :: DSum T Identity -> Maybe UDP.NodeInfo | 125 | udpNode :: DSum T Identity -> Maybe UDP.NodeInfo |
125 | udpNode (UDP :=> Identity ni) = Just ni | 126 | udpNode (UDP :=> Identity ni) = Just ni |
126 | udpNode _ = Nothing | 127 | udpNode _ = Nothing |
128 | |||
129 | sessionAddr :: DSum T Identity -> DSum S Identity | ||
130 | sessionAddr (UDP :=> Identity ni) = SessionUDP ==> UDP.nodeAddr ni | ||
131 | sessionAddr (TCP :=> Identity vr) = SessionTCP ==> vr | ||
132 | |||
133 | tcpConnectionRequest :: QR.Client err PacketNumber tid TCP.NodeInfo (Bool, RelayPacket) | ||
134 | -> PublicKey -> TCP.NodeInfo -> IO (Maybe NodeInfo) | ||
135 | tcpConnectionRequest client pubkey ni = do | ||
136 | mcon <- tcpConnectionRequest_ client pubkey ni | ||
137 | return $ fmap (\conid -> TCP ==> ViaRelay (Just conid) (UDP.key2id pubkey) ni) mcon | ||
diff --git a/dht/src/Data/Tox/Onion.hs b/dht/src/Data/Tox/Onion.hs index e19f71b6..a9bc4e1d 100644 --- a/dht/src/Data/Tox/Onion.hs +++ b/dht/src/Data/Tox/Onion.hs | |||
@@ -125,12 +125,12 @@ data OnionDestination r | |||
125 | = OnionToOwner | 125 | = OnionToOwner |
126 | { onionNodeInfo :: NodeInfo | 126 | { onionNodeInfo :: NodeInfo |
127 | , onionReturnPath :: ReturnPath N3 -- ^ Somebody else's path to us. | 127 | , onionReturnPath :: ReturnPath N3 -- ^ Somebody else's path to us. |
128 | } | 128 | } -- ^ incoming queries and outgoing responses |
129 | | OnionDestination | 129 | | OnionDestination |
130 | { onionAliasSelector' :: AliasSelector | 130 | { onionAliasSelector' :: AliasSelector |
131 | , onionNodeInfo :: NodeInfo | 131 | , onionNodeInfo :: NodeInfo |
132 | , onionRouteSpec :: Maybe r -- ^ Our own onion-path. | 132 | , onionRouteSpec :: Maybe r -- ^ Our own onion-path. |
133 | } | 133 | } -- ^ outgoing queries and incoming responses |
134 | deriving Show | 134 | deriving Show |
135 | 135 | ||
136 | onionAliasSelector :: OnionDestination r -> AliasSelector | 136 | onionAliasSelector :: OnionDestination r -> AliasSelector |
@@ -213,6 +213,7 @@ putOnionMsg (OnionToRoute pubkey a) = putOnionAsymm 0x85 (putPublicKey | |||
213 | putOnionMsg (OnionAnnounceResponse n8 n24 x) = put (0x84 :: Word8) >> put n8 >> put n24 >> put x | 213 | putOnionMsg (OnionAnnounceResponse n8 n24 x) = put (0x84 :: Word8) >> put n8 >> put n24 >> put x |
214 | putOnionMsg (OnionToRouteResponse a) = putOnionAsymm 0x86 (return ()) a | 214 | putOnionMsg (OnionToRouteResponse a) = putOnionAsymm 0x86 (return ()) a |
215 | 215 | ||
216 | -- | /r/ parameter for 'OnionDestination' | ||
216 | newtype RouteId = RouteId Int | 217 | newtype RouteId = RouteId Int |
217 | deriving Show | 218 | deriving Show |
218 | 219 | ||