diff options
author | jim@bo <jim@bo> | 2018-06-20 22:40:37 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-20 22:43:47 -0400 |
commit | 825962518c6ad00279fc23e8e1dec746980e483f (patch) | |
tree | 68c135bdffd879835c48cce3d397e8edf99b53f4 /src/Network/Tox | |
parent | 09aa079fbab069f177e08b5239bf684d312eb00a (diff) |
More DPut stuff
* verbose/quiet without args shows report
* verbose all - sets all tags verbose
* quiet all - sets all tags quiet
* XMisc defaults to verbose, everything else quiet
* new XMan tag for ToxManager related stuff
* s/hputStrLn stderr/dput XMisc/ in daemon code
Diffstat (limited to 'src/Network/Tox')
-rw-r--r-- | src/Network/Tox/ContactInfo.hs | 3 | ||||
-rw-r--r-- | src/Network/Tox/DHT/Handlers.hs | 14 | ||||
-rw-r--r-- | src/Network/Tox/Onion/Transport.hs | 12 |
3 files changed, 15 insertions, 14 deletions
diff --git a/src/Network/Tox/ContactInfo.hs b/src/Network/Tox/ContactInfo.hs index 64ea861b..5135813a 100644 --- a/src/Network/Tox/ContactInfo.hs +++ b/src/Network/Tox/ContactInfo.hs | |||
@@ -18,6 +18,7 @@ import Network.Tox.DHT.Transport as DHT | |||
18 | import Network.Tox.NodeId (id2key) | 18 | import Network.Tox.NodeId (id2key) |
19 | import Network.Tox.Onion.Transport as Onion | 19 | import Network.Tox.Onion.Transport as Onion |
20 | import System.IO | 20 | import System.IO |
21 | import DPut | ||
21 | 22 | ||
22 | newtype ContactInfo extra = ContactInfo | 23 | newtype ContactInfo extra = ContactInfo |
23 | -- | Map our toxid public key to an Account record. | 24 | -- | Map our toxid public key to an Account record. |
@@ -55,7 +56,7 @@ myKeyPairs (ContactInfo accounts) = do | |||
55 | 56 | ||
56 | updateContactInfo :: ContactInfo extra -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO () | 57 | updateContactInfo :: ContactInfo extra -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO () |
57 | updateContactInfo roster Onion.AnnouncedRendezvous{remoteUserKey} (localUserKey,omsg) = do | 58 | updateContactInfo roster Onion.AnnouncedRendezvous{remoteUserKey} (localUserKey,omsg) = do |
58 | hPutStrLn stderr "updateContactInfo!!!" | 59 | dput XMisc "updateContactInfo!!!" |
59 | now <- getPOSIXTime | 60 | now <- getPOSIXTime |
60 | atomically $ do | 61 | atomically $ do |
61 | as <- readTVar (accounts roster) | 62 | as <- readTVar (accounts roster) |
diff --git a/src/Network/Tox/DHT/Handlers.hs b/src/Network/Tox/DHT/Handlers.hs index 43169fa0..58a29c3e 100644 --- a/src/Network/Tox/DHT/Handlers.hs +++ b/src/Network/Tox/DHT/Handlers.hs | |||
@@ -404,9 +404,9 @@ unwrapNodes (SendNodes ns) = (ns,ns,Just ()) | |||
404 | 404 | ||
405 | getNodes :: Client -> TVar (HashMap NodeId [NodeInfoCallback]) -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],Maybe ())) | 405 | getNodes :: Client -> TVar (HashMap NodeId [NodeInfoCallback]) -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],Maybe ())) |
406 | getNodes client cbvar nid addr = do | 406 | getNodes client cbvar nid addr = do |
407 | -- hPutStrLn stderr $ show addr ++ " <-- getnodes " ++ show nid | 407 | -- dput XMisc $ show addr ++ " <-- getnodes " ++ show nid |
408 | reply <- QR.sendQuery client (serializer GetNodesType DHTGetNodes unsendNodes) (GetNodes nid) addr | 408 | reply <- QR.sendQuery client (serializer GetNodesType DHTGetNodes unsendNodes) (GetNodes nid) addr |
409 | -- hPutStrLn stderr $ show addr ++ " -sendnodes-> " ++ show reply | 409 | -- dput XMisc $ show addr ++ " -sendnodes-> " ++ show reply |
410 | forM_ (join reply) $ \(SendNodes ns) -> | 410 | forM_ (join reply) $ \(SendNodes ns) -> |
411 | forM_ ns $ \n -> do | 411 | forM_ ns $ \n -> do |
412 | now <- getPOSIXTime | 412 | now <- getPOSIXTime |
@@ -430,13 +430,13 @@ updateRouting client routing orouter naddr msg | |||
430 | case prefer4or6 naddr Nothing of | 430 | case prefer4or6 naddr Nothing of |
431 | Want_IP4 -> updateTable client naddr orouter (committee4 routing) (refresher4 routing) | 431 | Want_IP4 -> updateTable client naddr orouter (committee4 routing) (refresher4 routing) |
432 | Want_IP6 -> updateTable client naddr orouter (committee6 routing) (refresher6 routing) | 432 | Want_IP6 -> updateTable client naddr orouter (committee6 routing) (refresher6 routing) |
433 | Want_Both -> do hPutStrLn stderr "BUG:unreachable" | 433 | Want_Both -> do dput XMisc "BUG:unreachable" |
434 | error $ "BUG:unreachable at " ++ __FILE__ ++ ":" ++ show __LINE__ | 434 | error $ "BUG:unreachable at " ++ __FILE__ ++ ":" ++ show __LINE__ |
435 | 435 | ||
436 | updateTable :: Client -> NodeInfo -> OnionRouter -> TriadCommittee NodeId SockAddr -> BucketRefresher NodeId NodeInfo -> IO () | 436 | updateTable :: Client -> NodeInfo -> OnionRouter -> TriadCommittee NodeId SockAddr -> BucketRefresher NodeId NodeInfo -> IO () |
437 | updateTable client naddr orouter committee refresher = do | 437 | updateTable client naddr orouter committee refresher = do |
438 | self <- atomically $ R.thisNode <$> readTVar (refreshBuckets refresher) | 438 | self <- atomically $ R.thisNode <$> readTVar (refreshBuckets refresher) |
439 | -- hPutStrLn stderr $ "(tox)updateRouting: " ++ show (nodeIP self, nodeIP naddr) | 439 | -- dput XMisc $ "(tox)updateRouting: " ++ show (nodeIP self, nodeIP naddr) |
440 | when (self /= naddr) $ do | 440 | when (self /= naddr) $ do |
441 | -- TODO: IP address vote? | 441 | -- TODO: IP address vote? |
442 | insertNode (toxKademlia client committee orouter refresher) naddr | 442 | insertNode (toxKademlia client committee orouter refresher) naddr |
@@ -455,7 +455,7 @@ toxKademlia client committee orouter refresher | |||
455 | return $ do | 455 | return $ do |
456 | io1 >> io2 | 456 | io1 >> io2 |
457 | {- | 457 | {- |
458 | hPutStrLn stderr $ unwords | 458 | dput XMisc $ unwords |
459 | [ show (transitionedTo tr) | 459 | [ show (transitionedTo tr) |
460 | , show (transitioningNode tr) | 460 | , show (transitioningNode tr) |
461 | ] | 461 | ] |
@@ -467,7 +467,7 @@ transitionCommittee :: TriadCommittee NodeId SockAddr -> RoutingTransition NodeI | |||
467 | transitionCommittee committee (RoutingTransition ni Stranger) = do | 467 | transitionCommittee committee (RoutingTransition ni Stranger) = do |
468 | delVote committee (nodeId ni) | 468 | delVote committee (nodeId ni) |
469 | return $ do | 469 | return $ do |
470 | -- hPutStrLn stderr $ "delVote "++show (nodeId ni) | 470 | -- dput XMisc $ "delVote "++show (nodeId ni) |
471 | return () | 471 | return () |
472 | transitionCommittee committee _ = return $ return () | 472 | transitionCommittee committee _ = return $ return () |
473 | 473 | ||
@@ -500,7 +500,7 @@ isDHTRequest _ _ = Left "Bad dht relay request" | |||
500 | 500 | ||
501 | dhtRequestH :: NodeInfo -> DHTRequest -> IO () | 501 | dhtRequestH :: NodeInfo -> DHTRequest -> IO () |
502 | dhtRequestH ni req = do | 502 | dhtRequestH ni req = do |
503 | hPutStrLn stderr $ "Unhandled DHT Request: " ++ show req | 503 | dput XMisc $ "Unhandled DHT Request: " ++ show req |
504 | 504 | ||
505 | handlers :: TransportCrypto -> Routing -> PacketKind -> Maybe Handler | 505 | handlers :: TransportCrypto -> Routing -> PacketKind -> Maybe Handler |
506 | handlers _ routing PingType = Just $ MethodHandler (isPing snd) mkPong $ pingH | 506 | handlers _ routing PingType = Just $ MethodHandler (isPing snd) mkPong $ pingH |
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs index 8a66f2b2..70714465 100644 --- a/src/Network/Tox/Onion/Transport.hs +++ b/src/Network/Tox/Onion/Transport.hs | |||
@@ -246,7 +246,7 @@ encodeOnionAddr crypto _ (msg,OnionToOwner ni p) = | |||
246 | , nodeAddr ni ) | 246 | , nodeAddr ni ) |
247 | encodeOnionAddr crypto getRoute (msg,OnionDestination x ni Nothing) = do | 247 | encodeOnionAddr crypto getRoute (msg,OnionDestination x ni Nothing) = do |
248 | encodeOnionAddr crypto getRoute (msg,OnionDestination x ni (Just $ routeId $ nodeId ni) ) | 248 | encodeOnionAddr crypto getRoute (msg,OnionDestination x ni (Just $ routeId $ nodeId ni) ) |
249 | -- hPutStrLn stderr $ "ONION encode missing routeid" | 249 | -- dput XMisc $ "ONION encode missing routeid" |
250 | -- return Nothing | 250 | -- return Nothing |
251 | encodeOnionAddr crypto getRoute (msg,OnionDestination _ ni (Just rid)) = do | 251 | encodeOnionAddr crypto getRoute (msg,OnionDestination _ ni (Just rid)) = do |
252 | let go route = do | 252 | let go route = do |
@@ -255,8 +255,8 @@ encodeOnionAddr crypto getRoute (msg,OnionDestination _ ni (Just rid)) = do | |||
255 | , nodeAddr $ routeNodeA route) | 255 | , nodeAddr $ routeNodeA route) |
256 | mapM' f x = do | 256 | mapM' f x = do |
257 | let _ = x :: Maybe OnionRoute | 257 | let _ = x :: Maybe OnionRoute |
258 | -- hPutStrLn stderr $ "ONION encode sending to " ++ show ni | 258 | -- dput XMisc $ "ONION encode sending to " ++ show ni |
259 | -- hPutStrLn stderr $ "ONION encode getRoute -> " ++ show (fmap (\y -> map ($ y) [routeNodeA,routeNodeB,routeNodeC]) x) | 259 | -- dput XMisc $ "ONION encode getRoute -> " ++ show (fmap (\y -> map ($ y) [routeNodeA,routeNodeB,routeNodeC]) x) |
260 | mapM f x -- ONION encode getRoute -> Nothing | 260 | mapM f x -- ONION encode getRoute -> Nothing |
261 | getRoute ni rid >>= mapM' go | 261 | getRoute ni rid >>= mapM' go |
262 | 262 | ||
@@ -525,7 +525,7 @@ handleOnionResponse proxy crypto saddr udp kont (OnionResponse path msg) = do | |||
525 | Left e -> do | 525 | Left e -> do |
526 | -- todo report encryption error | 526 | -- todo report encryption error |
527 | let n = peanoVal path | 527 | let n = peanoVal path |
528 | hPutStrLn stderr $ unwords [ "peelSymmetric:", show n, either show show (either4or6 saddr), e] | 528 | dput XMisc $ unwords [ "peelSymmetric:", show n, either show show (either4or6 saddr), e] |
529 | kont | 529 | kont |
530 | Right (Addressed dst path') -> do | 530 | Right (Addressed dst path') -> do |
531 | sendMessage udp dst (runPut $ putResponse $ OnionResponse path' msg) | 531 | sendMessage udp dst (runPut $ putResponse $ OnionResponse path' msg) |
@@ -897,9 +897,9 @@ parseDataToRoute crypto (OnionToRouteResponse dta, od) = do | |||
897 | r = either (const $ Right (OnionToRouteResponse dta,od)) Left e | 897 | r = either (const $ Right (OnionToRouteResponse dta,od)) Left e |
898 | -- parseDataToRoute OnionToRouteResponse decipherAndAuth: auth fail | 898 | -- parseDataToRoute OnionToRouteResponse decipherAndAuth: auth fail |
899 | case e of | 899 | case e of |
900 | Left _ -> hPutStrLn stderr $ "Failed keys: " ++ show (map (key2id . snd) ks) | 900 | Left _ -> dput XMisc $ "Failed keys: " ++ show (map (key2id . snd) ks) |
901 | Right _ -> return () | 901 | Right _ -> return () |
902 | hPutStrLn stderr $ unlines | 902 | dput XMisc $ unlines |
903 | [ "parseDataToRoute " ++ either id (const "Right") e | 903 | [ "parseDataToRoute " ++ either id (const "Right") e |
904 | , " crypto inner.me = " ++ either id (\(pk,_,_) -> show $ key2id pk) eInner | 904 | , " crypto inner.me = " ++ either id (\(pk,_,_) -> show $ key2id pk) eInner |
905 | , " inner.them = " ++ either id (show . key2id . dataFromKey) eOuter | 905 | , " inner.them = " ++ either id (show . key2id . dataFromKey) eOuter |