diff options
author | Joe Crayne <joe@jerkface.net> | 2020-01-09 19:45:23 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-09 19:45:23 -0500 |
commit | 8ddaf16880b3dcc8cb30a36c46c7edd1f9fe4b3c (patch) | |
tree | aa3af6bac404ac607ccc1f1ad1076b524ad70002 /dht/src/Network/Tox/Onion | |
parent | e07ea02e9ff5a1ad53c9554977e2feea566d5523 (diff) |
Improved debug prints.
Diffstat (limited to 'dht/src/Network/Tox/Onion')
-rw-r--r-- | dht/src/Network/Tox/Onion/Handlers.hs | 15 |
1 files changed, 13 insertions, 2 deletions
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 | ||
275 | showResponse :: Bool -> NodeInfo -> AnnounceRequest -> AnnounceResponse -> String | ||
276 | showResponse 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 | ||
276 | sendOnion :: (OnionDestination r -> STM (OnionDestination r, Int)) | 285 | sendOnion :: (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)) | |||
300 | asyncOnion getTimeout client req oaddr unwrap withResult = do | 310 | asyncOnion 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)) |