summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-01-09 19:45:23 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-09 19:45:23 -0500
commit8ddaf16880b3dcc8cb30a36c46c7edd1f9fe4b3c (patch)
treeaa3af6bac404ac607ccc1f1ad1076b524ad70002
parente07ea02e9ff5a1ad53c9554977e2feea566d5523 (diff)
Improved debug prints.
-rw-r--r--dht/src/DebugTag.hs1
-rw-r--r--dht/src/Network/Tox/Onion/Handlers.hs15
-rw-r--r--dht/src/Network/Tox/Relay.hs32
3 files changed, 31 insertions, 17 deletions
diff --git a/dht/src/DebugTag.hs b/dht/src/DebugTag.hs
index efa6415f..83f9b1f8 100644
--- a/dht/src/DebugTag.hs
+++ b/dht/src/DebugTag.hs
@@ -5,6 +5,7 @@ import Data.Typeable
5-- | Debug Tags, add more as needed, but ensure XAnnounce is always first, XMisc last 5-- | Debug Tags, add more as needed, but ensure XAnnounce is always first, XMisc last
6data DebugTag 6data DebugTag
7 = XAnnounce 7 = XAnnounce
8 | XAnnounceResponse
8 | XBitTorrent 9 | XBitTorrent
9 | XDHT 10 | XDHT
10 | XLan 11 | XLan
diff --git a/dht/src/Network/Tox/Onion/Handlers.hs b/dht/src/Network/Tox/Onion/Handlers.hs
index 45795312..8db1c534 100644
--- a/dht/src/Network/Tox/Onion/Handlers.hs
+++ b/dht/src/Network/Tox/Onion/Handlers.hs
@@ -272,6 +272,15 @@ announceSerializer getTimeout = MethodSerializer
272-- aggressively reannounce itself and search for friends as if it was just 272-- aggressively reannounce itself and search for friends as if it was just
273-- started. 273-- started.
274 274
275showResponse :: Bool -> NodeInfo -> AnnounceRequest -> AnnounceResponse -> String
276showResponse is_async them req r = unlines $ map (mappend $ show them ++ " --> ") $
277 [ "AnnounceResponse" ++ if is_async then " -- async" else ""
278 , " { announceSeeking = " ++ show (announceSeeking req)
279 , " , is_stored = " ++ show (is_stored r)
280 , " , announceNodes = "
281 ] ++ case announceNodes r of
282 SendNodes ns -> map (mappend " " . show) ns
283 ++ [ " }" ]
275 284
276sendOnion :: (OnionDestination r -> STM (OnionDestination r, Int)) 285sendOnion :: (OnionDestination r -> STM (OnionDestination r, Int))
277 -> Client r 286 -> Client r
@@ -283,7 +292,8 @@ sendOnion getTimeout client req oaddr unwrap =
283 -- Four tries and then we tap out. 292 -- Four tries and then we tap out.
284 flip fix 4 $ \loop n -> do 293 flip fix 4 $ \loop n -> do
285 mb <- QR.sendQuery client (announceSerializer getTimeout) req oaddr 294 mb <- QR.sendQuery client (announceSerializer getTimeout) req oaddr
286 forM_ mb $ \r -> dput XAnnounce $ show (onionNodeInfo oaddr) ++ " sent response: " ++ show r 295 forM_ mb $ \mr -> forM_ mr $ \r ->
296 dput XAnnounceResponse $ showResponse False (onionNodeInfo oaddr) req r
287 let re = if n>0 then loop $! n - 1 else return Canceled 297 let re = if n>0 then loop $! n - 1 else return Canceled
288 case mb of 298 case mb of
289 Success x -> maybe re (return . Success . unwrap (onionNodeInfo oaddr)) x 299 Success x -> maybe re (return . Success . unwrap (onionNodeInfo oaddr)) x
@@ -300,7 +310,8 @@ asyncOnion :: (OnionDestination r -> STM (OnionDestination r, Int))
300asyncOnion getTimeout client req oaddr unwrap withResult = do 310asyncOnion getTimeout client req oaddr unwrap withResult = do
301 -- TODO: Restore "Four tries and then we tap out" behavior. 311 -- TODO: Restore "Four tries and then we tap out" behavior.
302 qid <- QR.asyncQuery client (announceSerializer getTimeout) req oaddr $ \k mb -> do 312 qid <- QR.asyncQuery client (announceSerializer getTimeout) req oaddr $ \k mb -> do
303 forM_ mb $ \r -> dput XAnnounce $ show (onionNodeInfo oaddr) ++ " async sent response: " ++ show r 313 forM_ mb $ \mr -> forM_ mr $ \r ->
314 dput XAnnounceResponse $ showResponse True (onionNodeInfo oaddr) req r
304 withResult k $ case mb of 315 withResult k $ case mb of
305 Success x -> maybe (TimedOut) 316 Success x -> maybe (TimedOut)
306 (Success . unwrap (onionNodeInfo oaddr)) 317 (Success . unwrap (onionNodeInfo oaddr))
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