From e0ada56c116255a2feddcf7b09cec808f79afefc Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 22 Jun 2017 01:37:04 -0400 Subject: Propagated MonadKRPC deletion to Network.BitTorrent.DHT. --- src/Network/DatagramServer.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Network/DatagramServer.hs') diff --git a/src/Network/DatagramServer.hs b/src/Network/DatagramServer.hs index f212ffdf..2140e2cd 100644 --- a/src/Network/DatagramServer.hs +++ b/src/Network/DatagramServer.hs @@ -196,7 +196,7 @@ data Manager h raw msg = Manager , listenerThread :: !(MVar ThreadId) , transactionCounter :: {-# UNPACK #-} !TransactionCounter , pendingCalls :: {-# UNPACK #-} !(PendingCalls msg raw) - , handlers :: [Handler h msg raw] + , handlers :: [Handler h msg raw] -- TODO delete this, it's not used , logMsg :: Char -> String -> T.Text -> IO () } @@ -462,8 +462,8 @@ dispatchHandler :: ( Eq (QueryMethod msg) , Show (QueryMethod msg) , Serialize (TransactionID msg) , Envelope msg - ) => Manager IO raw msg -> QueryMethod msg -> msg raw -> SockAddr -> IO (KResult msg raw) -dispatchHandler mgr@Manager{..} meth q addr = do + ) => Manager IO raw msg -> [Handler IO msg raw] -> QueryMethod msg -> msg raw -> SockAddr -> IO (KResult msg raw) +dispatchHandler mgr handlers meth q addr = do case L.lookup meth handlers of Nothing -> return $ Left $ KError MethodUnknown ("Unknown method " <> BC.pack (show meth)) (envelopeTransaction q) Just h -> runHandler mgr meth h addr q @@ -483,10 +483,10 @@ handleQuery :: ( WireFormat raw msg , Eq (QueryMethod msg) , Show (QueryMethod msg) , Serialize (TransactionID msg) - ) => Manager IO raw msg -> QueryMethod msg -> raw -> msg raw -> SockAddr -> IO () -handleQuery mgr@Manager{..} meth raw q addr = void $ fork $ do + ) => Manager IO raw msg -> [Handler IO msg raw] -> QueryMethod msg -> raw -> msg raw -> SockAddr -> IO () +handleQuery mgr@Manager{..} hs meth raw q addr = void $ fork $ do myThreadId >>= liftIO . flip labelThread "KRPC.handleQuery" - res <- dispatchHandler mgr meth q addr + res <- dispatchHandler mgr hs meth q addr let res' = either buildError Just res ctx = error "TODO TOX ToxCipherContext 2 or () for Mainline" resbs = fmap (encodeHeaders ctx) res' :: Maybe BS.ByteString @@ -520,8 +520,8 @@ listener :: forall raw msg. , Eq (QueryMethod msg) , Show (QueryMethod msg) , Serialize (TransactionID msg) - ) => Manager IO raw msg -> Protocol raw msg -> IO () -listener mgr@Manager{..} p = do + ) => Manager IO raw msg -> [Handler IO msg raw] -> Protocol raw msg -> IO () +listener mgr@Manager{..} hs p = do fix $ \again -> do let ctx = error "TODO TOX ToxCipherContext or () for Mainline" (bs, addr) <- liftIO $ do @@ -532,7 +532,7 @@ listener mgr@Manager{..} p = do return () -- Without transaction id, error message isn't very useful. Right (raw,m) -> case envelopeClass m of - Query meth -> handleQuery mgr meth (raw::raw) m addr + Query meth -> handleQuery mgr hs meth (raw::raw) m addr Response _ -> handleResponse mgr raw (Right m) addr Error e -> handleResponse mgr raw (Left e) addr @@ -551,10 +551,10 @@ listen :: ( WireFormat raw msg , Eq (QueryMethod msg) , Show (QueryMethod msg) , Serialize (TransactionID msg) - ) => Manager IO raw msg -> Protocol raw msg -> IO () -listen mgr@Manager{..} p = do + ) => Manager IO raw msg -> [Handler IO msg raw] -> Protocol raw msg -> IO () +listen mgr@Manager{..} hs p = do tid <- fork $ do myThreadId >>= liftIO . flip labelThread "KRPC.listen" - listener mgr p `Lifted.finally` + listener mgr hs p `Lifted.finally` liftIO (takeMVar listenerThread) liftIO $ putMVar listenerThread tid -- cgit v1.2.3