summaryrefslogtreecommitdiff
path: root/dht/src
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-17 13:22:28 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:26:50 -0500
commit2425c1a5df23d7051461d8f9fd32b5d5aa03e104 (patch)
treefad9dc999a824ed7fd951241768682fdeffda04a /dht/src
parent0c9cf41d9cf8c0b908f38a3ccf66452d56c578e8 (diff)
Schedule TCP chat-link session attempts.
Diffstat (limited to 'dht/src')
-rw-r--r--dht/src/Data/Tox/DHT/Multi.hs17
-rw-r--r--dht/src/Data/Tox/Onion.hs5
-rw-r--r--dht/src/Network/Tox/TCP.hs4
3 files changed, 19 insertions, 7 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 #-}
8module Data.Tox.DHT.Multi where 8module Data.Tox.DHT.Multi where
9 9
10import Crypto.PubKey.Curve25519 (PublicKey)
10import qualified Network.Tox.NodeId as UDP 11import qualified Network.Tox.NodeId as UDP
11 ;import Network.Tox.NodeId (NodeId) 12 ;import Network.Tox.NodeId (NodeId)
12import qualified Network.Tox.TCP.NodeId as TCP 13import qualified Network.Tox.TCP.NodeId as TCP
13import Data.Tox.Relay 14import Data.Tox.Relay hiding (NodeInfo)
14import Network.Address (either4or6) 15import Network.Address (either4or6)
15import Network.Tox.TCP as TCP (ViaRelay(..)) 16import Network.Tox.TCP as TCP (ViaRelay(..), tcpConnectionRequest_)
16import Network.QueryResponse (Tagged(..)) 17import Network.QueryResponse as QR (Tagged(..), Client)
17 18
18import Data.Dependent.Sum 19import Data.Dependent.Sum
19import Data.GADT.Compare 20import Data.GADT.Compare
@@ -124,3 +125,13 @@ relayNodeId (ViaRelay _ nid _) = nid
124udpNode :: DSum T Identity -> Maybe UDP.NodeInfo 125udpNode :: DSum T Identity -> Maybe UDP.NodeInfo
125udpNode (UDP :=> Identity ni) = Just ni 126udpNode (UDP :=> Identity ni) = Just ni
126udpNode _ = Nothing 127udpNode _ = Nothing
128
129sessionAddr :: DSum T Identity -> DSum S Identity
130sessionAddr (UDP :=> Identity ni) = SessionUDP ==> UDP.nodeAddr ni
131sessionAddr (TCP :=> Identity vr) = SessionTCP ==> vr
132
133tcpConnectionRequest :: QR.Client err PacketNumber tid TCP.NodeInfo (Bool, RelayPacket)
134 -> PublicKey -> TCP.NodeInfo -> IO (Maybe NodeInfo)
135tcpConnectionRequest 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
136onionAliasSelector :: OnionDestination r -> AliasSelector 136onionAliasSelector :: OnionDestination r -> AliasSelector
@@ -213,6 +213,7 @@ putOnionMsg (OnionToRoute pubkey a) = putOnionAsymm 0x85 (putPublicKey
213putOnionMsg (OnionAnnounceResponse n8 n24 x) = put (0x84 :: Word8) >> put n8 >> put n24 >> put x 213putOnionMsg (OnionAnnounceResponse n8 n24 x) = put (0x84 :: Word8) >> put n8 >> put n24 >> put x
214putOnionMsg (OnionToRouteResponse a) = putOnionAsymm 0x86 (return ()) a 214putOnionMsg (OnionToRouteResponse a) = putOnionAsymm 0x86 (return ()) a
215 215
216-- | /r/ parameter for 'OnionDestination'
216newtype RouteId = RouteId Int 217newtype RouteId = RouteId Int
217 deriving Show 218 deriving Show
218 219
diff --git a/dht/src/Network/Tox/TCP.hs b/dht/src/Network/Tox/TCP.hs
index dc4c9967..c4727a20 100644
--- a/dht/src/Network/Tox/TCP.hs
+++ b/dht/src/Network/Tox/TCP.hs
@@ -292,9 +292,9 @@ tcpPing client dst = do
292 , method = PingPacket 292 , method = PingPacket
293 } 293 }
294 294
295tcpConnectionRequest :: Client err PacketNumber tid addr (Bool, RelayPacket) 295tcpConnectionRequest_ :: Client err PacketNumber tid addr (Bool, RelayPacket)
296 -> PublicKey -> addr -> IO (Maybe ConId) 296 -> PublicKey -> addr -> IO (Maybe ConId)
297tcpConnectionRequest client pubkey ni = do 297tcpConnectionRequest_ client pubkey ni = do
298 sendQuery client meth pubkey ni 298 sendQuery client meth pubkey ni
299 where 299 where
300 meth = MethodSerializer 300 meth = MethodSerializer