summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/Relay.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox/Relay.hs')
-rw-r--r--dht/src/Network/Tox/Relay.hs32
1 files changed, 17 insertions, 15 deletions
diff --git a/dht/src/Network/Tox/Relay.hs b/dht/src/Network/Tox/Relay.hs
index dd150917..96838688 100644
--- a/dht/src/Network/Tox/Relay.hs
+++ b/dht/src/Network/Tox/Relay.hs
@@ -80,12 +80,12 @@ relaySession :: TransportCrypto
80 -> Int 80 -> Int
81 -> Handle 81 -> Handle
82 -> IO () 82 -> IO ()
83relaySession crypto clients cons sendOnion _ conid h = do 83relaySession crypto clients cons sendOnion _ thistcp h = do
84 -- atomically $ modifyTVar' cons $ IntMap.insert conid h 84 -- atomically $ modifyTVar' cons $ IntMap.insert conid h
85 85
86 -- mhello <- fmap (>>= \h -> decryptPayload (computeSharedSecret me (helloFrom h) (helloNonce h)) h) $ hGetSized h 86 -- mhello <- fmap (>>= \h -> decryptPayload (computeSharedSecret me (helloFrom h) (helloNonce h)) h) $ hGetSized h
87 87
88 dput XRelay $ "Relay client session conid=" ++ show conid 88 dput XRelay $ "Relay client session tcp=" ++ show thistcp
89 (hGetSized h >>=) $ mapM_ $ \helloE -> do 89 (hGetSized h >>=) $ mapM_ $ \helloE -> do
90 90
91 let me = transportSecret crypto 91 let me = transportSecret crypto
@@ -103,13 +103,12 @@ relaySession crypto clients cons sendOnion _ conid h = do
103 w24 <- transportNewNonce crypto 103 w24 <- transportNewNonce crypto
104 return (skey, Welcome w24 $ pure dta) 104 return (skey, Welcome w24 $ pure dta)
105 105
106 {-
107 dput XRelay $ unlines [ "Relay to send welcome to client. conid=" ++ show conid
108 , show welcome
109 ]
110 -}
111 B.hPut h $ encode $ encryptPayload (noncef $ welcomeNonce welcome) welcome 106 B.hPut h $ encode $ encryptPayload (noncef $ welcomeNonce welcome) welcome
112 dput XRelay $ "Relay welcomes (conid=" ++ show conid ++ ") " ++ showKey256 them 107 dput XRelay $ unlines
108 [ "Relay welcomes (tcp=" ++ show thistcp ++ ") " ++ showKey256 them
109 -- , " hello=" ++ show hello
110 -- , " welcome=" ++ show welcome
111 ]
113 112
114 noncef' <- let them' = sessionPublicKey (runIdentity $ helloData hello) 113 noncef' <- let them' = sessionPublicKey (runIdentity $ helloData hello)
115 in lookupNonceFunction crypto me' them' 114 in lookupNonceFunction crypto me' them'
@@ -143,22 +142,25 @@ relaySession crypto clients cons sendOnion _ conid h = do
143 atomically $ modifyTVar' cons $ Map.insert (helloFrom hello) (sendPacket,session) 142 atomically $ modifyTVar' cons $ Map.insert (helloFrom hello) (sendPacket,session)
144 return (sendPacket,session) 143 return (sendPacket,session)
145 144
146 handlePacket cons conid (helloFrom hello) crypto sendOnion sendPacket session pkt0 145 handlePacket cons thistcp (helloFrom hello) crypto sendOnion sendPacket session pkt0
147 146
148 atomically $ modifyTVar' clients $ IntMap.insert conid $ 147 atomically $ modifyTVar' clients $ IntMap.insert thistcp $
149 \p -> do 148 \p -> do
150 dput XOnion $ "Sending onion reply to TCP client conid="++show conid 149 dput XOnion $ unlines
150 [ "Sending onion reply to TCP client tcp="++show thistcp
151 , " pkt0=" ++ show pkt0
152 ]
151 sendPacket p 153 sendPacket p
152 154
153 flip fix (incrementNonce24 base) $ \loop n24 -> do 155 flip fix (incrementNonce24 base) $ \loop n24 -> do
154 m <- readPacket n24 156 m <- readPacket n24
155 forM_ m $ \p -> do 157 forM_ m $ \p -> do
156 handlePacket cons conid (helloFrom hello) crypto sendOnion sendPacket session p 158 handlePacket cons thistcp (helloFrom hello) crypto sendOnion sendPacket session p
157 loop (incrementNonce24 n24) 159 loop (incrementNonce24 n24)
158 `finally` do 160 `finally` do
159 atomically $ modifyTVar' clients $ IntMap.delete conid 161 atomically $ modifyTVar' clients $ IntMap.delete thistcp
160 disconnect cons (helloFrom hello) 162 disconnect cons (helloFrom hello)
161 dput XRelay $ "Relay client session closed. conid=" ++ show conid 163 dput XRelay $ "Relay client session closed. tcp=" ++ show thistcp
162 164
163handlePacket :: TVar (Map PublicKey (RelayPacket -> IO (), TVar RelaySession)) -- ^ All sessions. 165handlePacket :: TVar (Map PublicKey (RelayPacket -> IO (), TVar RelaySession)) -- ^ All sessions.
164 -> Int -- ^ TCP client number. 166 -> Int -- ^ TCP client number.
@@ -211,7 +213,7 @@ handlePacket cons thistcp thisKey crypto sendOnion sendToClient session = \case
211 RelayPing x -> sendToClient $ RelayPong x -- TODO x==0 is invalid. Do we care? 213 RelayPing x -> sendToClient $ RelayPong x -- TODO x==0 is invalid. Do we care?
212 214
213 OOBSend them bs -> do 215 OOBSend them bs -> do
214 dput XRelay $ "OOB send to " ++ showKey256 them 216 dput XRelay $ "OOB send from " ++ showKey256 thisKey ++ " to " ++ showKey256 them
215 m <- atomically $ Map.lookup them <$> readTVar cons 217 m <- atomically $ Map.lookup them <$> readTVar cons
216 forM_ m $ \(sendToThem,_) -> sendToThem $ OOBRecv thisKey bs 218 forM_ m $ \(sendToThem,_) -> sendToThem $ OOBRecv thisKey bs
217 219