summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
authorjim@bo <jim@bo>2018-06-20 22:40:37 -0400
committerjim@bo <jim@bo>2018-06-20 22:43:47 -0400
commit825962518c6ad00279fc23e8e1dec746980e483f (patch)
tree68c135bdffd879835c48cce3d397e8edf99b53f4 /src/Network/Tox
parent09aa079fbab069f177e08b5239bf684d312eb00a (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.hs3
-rw-r--r--src/Network/Tox/DHT/Handlers.hs14
-rw-r--r--src/Network/Tox/Onion/Transport.hs12
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
18import Network.Tox.NodeId (id2key) 18import Network.Tox.NodeId (id2key)
19import Network.Tox.Onion.Transport as Onion 19import Network.Tox.Onion.Transport as Onion
20import System.IO 20import System.IO
21import DPut
21 22
22newtype ContactInfo extra = ContactInfo 23newtype 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
56updateContactInfo :: ContactInfo extra -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO () 57updateContactInfo :: ContactInfo extra -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO ()
57updateContactInfo roster Onion.AnnouncedRendezvous{remoteUserKey} (localUserKey,omsg) = do 58updateContactInfo 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
405getNodes :: Client -> TVar (HashMap NodeId [NodeInfoCallback]) -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],Maybe ())) 405getNodes :: Client -> TVar (HashMap NodeId [NodeInfoCallback]) -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],Maybe ()))
406getNodes client cbvar nid addr = do 406getNodes 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
436updateTable :: Client -> NodeInfo -> OnionRouter -> TriadCommittee NodeId SockAddr -> BucketRefresher NodeId NodeInfo -> IO () 436updateTable :: Client -> NodeInfo -> OnionRouter -> TriadCommittee NodeId SockAddr -> BucketRefresher NodeId NodeInfo -> IO ()
437updateTable client naddr orouter committee refresher = do 437updateTable 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
467transitionCommittee committee (RoutingTransition ni Stranger) = do 467transitionCommittee 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 ()
472transitionCommittee committee _ = return $ return () 472transitionCommittee committee _ = return $ return ()
473 473
@@ -500,7 +500,7 @@ isDHTRequest _ _ = Left "Bad dht relay request"
500 500
501dhtRequestH :: NodeInfo -> DHTRequest -> IO () 501dhtRequestH :: NodeInfo -> DHTRequest -> IO ()
502dhtRequestH ni req = do 502dhtRequestH ni req = do
503 hPutStrLn stderr $ "Unhandled DHT Request: " ++ show req 503 dput XMisc $ "Unhandled DHT Request: " ++ show req
504 504
505handlers :: TransportCrypto -> Routing -> PacketKind -> Maybe Handler 505handlers :: TransportCrypto -> Routing -> PacketKind -> Maybe Handler
506handlers _ routing PingType = Just $ MethodHandler (isPing snd) mkPong $ pingH 506handlers _ 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 )
247encodeOnionAddr crypto getRoute (msg,OnionDestination x ni Nothing) = do 247encodeOnionAddr 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
251encodeOnionAddr crypto getRoute (msg,OnionDestination _ ni (Just rid)) = do 251encodeOnionAddr 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