summaryrefslogtreecommitdiff
path: root/src/Network/Tox/DHT
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/DHT
parentf045f7e473b534cbe4dff70420e4cc0184465e54 (diff)
Quieter output and some bug fixes.
Diffstat (limited to 'src/Network/Tox/DHT')
-rw-r--r--src/Network/Tox/DHT/Handlers.hs10
1 files changed, 9 insertions, 1 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