summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-11-04 22:21:24 -0400
committerjoe <joe@jerkface.net>2017-11-04 22:21:24 -0400
commit8903c7e0b9eea11dbf229747e7f9729bfe5d2f7b (patch)
treea15d464c97bbad2a9f256f5fb52c8375b11ca9d3 /src/Network/Tox
parentf045f7e473b534cbe4dff70420e4cc0184465e54 (diff)
Quieter output and some bug fixes.
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/DHT/Handlers.hs10
-rw-r--r--src/Network/Tox/Onion/Transport.hs6
2 files changed, 12 insertions, 4 deletions
diff --git a/src/Network/Tox/DHT/Handlers.hs b/src/Network/Tox/DHT/Handlers.hs
index 89f3d442..fc28e2d2 100644
--- a/src/Network/Tox/DHT/Handlers.hs
+++ b/src/Network/Tox/DHT/Handlers.hs
@@ -383,12 +383,20 @@ isCookieRequest _ _ = Left "Bad cookie request"
383mkCookie :: TransactionId -> NodeInfo -> NodeInfo -> Cookie -> DHTMessage ((,) Nonce8) 383mkCookie :: TransactionId -> NodeInfo -> NodeInfo -> Cookie -> DHTMessage ((,) Nonce8)
384mkCookie (TransactionId n8 n24) src dst cookie = DHTCookie n24 (n8,cookie) 384mkCookie (TransactionId n8 n24) src dst cookie = DHTCookie n24 (n8,cookie)
385 385
386isDHTRequest :: (f DHTRequest -> DHTRequest) -> DHTMessage f -> Either String DHTRequest
387isDHTRequest unpack (DHTDHTRequest pubkey a) = Right $ unpack $ asymmData a
388isDHTRequest _ _ = Left "Bad dht relay request"
389
390dhtRequestH :: NodeInfo -> DHTRequest -> IO ()
391dhtRequestH ni req = do
392 hPutStrLn stderr $ "Unhandled DHT Request: " ++ show req
386 393
387handlers :: TransportCrypto -> Routing -> PacketKind -> Maybe Handler 394handlers :: TransportCrypto -> Routing -> PacketKind -> Maybe Handler
388handlers _ routing PingType = Just $ MethodHandler (isPing snd) mkPong $ pingH 395handlers _ routing PingType = Just $ MethodHandler (isPing snd) mkPong $ pingH
389handlers _ routing GetNodesType = Just $ MethodHandler (isGetNodes snd) mkSendNodes $ getNodesH routing 396handlers _ routing GetNodesType = Just $ MethodHandler (isGetNodes snd) mkSendNodes $ getNodesH routing
390handlers crypto _ CookieRequestType = Just $ MethodHandler (isCookieRequest snd) mkCookie $ cookieRequestH crypto 397handlers crypto _ CookieRequestType = Just $ MethodHandler (isCookieRequest snd) mkCookie $ cookieRequestH crypto
391handlers _ _ _ = error "TODO handlers" 398handlers _ _ DHTRequestType = Just $ NoReply (isDHTRequest snd) $ dhtRequestH
399handlers _ _ typ = error $ "TODO DHT handlers " ++ show typ
392 400
393nodeSearch :: Client -> Search NodeId (IP,PortNumber) () NodeInfo NodeInfo 401nodeSearch :: Client -> Search NodeId (IP,PortNumber) () NodeInfo NodeInfo
394nodeSearch client = Search 402nodeSearch client = Search
diff --git a/src/Network/Tox/Onion/Transport.hs b/src/Network/Tox/Onion/Transport.hs
index 39ea8c46..5b7aad0b 100644
--- a/src/Network/Tox/Onion/Transport.hs
+++ b/src/Network/Tox/Onion/Transport.hs
@@ -247,8 +247,8 @@ encodeOnionAddr getRoute (msg,OnionDestination _ ni (Just rid)) = do
247 , nodeAddr $ routeNodeA route) 247 , nodeAddr $ routeNodeA route)
248 mapM' f x = do 248 mapM' f x = do
249 let _ = x :: Maybe OnionRoute 249 let _ = x :: Maybe OnionRoute
250 hPutStrLn stderr $ "ONION encode sending to " ++ show ni 250 -- hPutStrLn stderr $ "ONION encode sending to " ++ show ni
251 hPutStrLn stderr $ "ONION encode getRoute -> " ++ show (fmap (\y -> map ($ y) [routeNodeA,routeNodeB,routeNodeC]) x) 251 -- hPutStrLn stderr $ "ONION encode getRoute -> " ++ show (fmap (\y -> map ($ y) [routeNodeA,routeNodeB,routeNodeC]) x)
252 mapM f x -- ONION encode getRoute -> Nothing 252 mapM f x -- ONION encode getRoute -> Nothing
253 getRoute ni rid >>= mapM' go 253 getRoute ni rid >>= mapM' go
254 254
@@ -846,7 +846,7 @@ parseDataToRoute crypto (OnionToRouteResponse dta, od) = do
846 (Left (dataFromKey dtr, dataToRoute dtr)) 846 (Left (dataFromKey dtr, dataToRoute dtr))
847 return (pk,dtr,omsg) 847 return (pk,dtr,omsg)
848 848
849 eInner = foldr1 (<|>) eInners 849 eInner = foldr (<|>) (Left "no user key") eInners
850 850
851 e = do 851 e = do
852 (pk,dtr,omsg) <- eInner 852 (pk,dtr,omsg) <- eInner