diff options
author | joe <joe@jerkface.net> | 2017-06-22 01:37:04 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-06-22 01:37:04 -0400 |
commit | e0ada56c116255a2feddcf7b09cec808f79afefc (patch) | |
tree | cf68a3015821039f707591684a237f8d7cf1c7cb /src/Network/BitTorrent | |
parent | 012d138b1061d967ef3a05dfb7dc819d199b3902 (diff) |
Propagated MonadKRPC deletion to Network.BitTorrent.DHT.
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/DHT.hs | 11 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 9 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs index 51d92127..d9328cea 100644 --- a/src/Network/BitTorrent/DHT.hs +++ b/src/Network/BitTorrent/DHT.hs | |||
@@ -70,8 +70,11 @@ import Network.BitTorrent.DHT.Query | |||
70 | import Network.BitTorrent.DHT.Session | 70 | import Network.BitTorrent.DHT.Session |
71 | import Network.DHT.Routing as T hiding (null) | 71 | import Network.DHT.Routing as T hiding (null) |
72 | import qualified Data.Text as Text | 72 | import qualified Data.Text as Text |
73 | import Data.Typeable | ||
73 | import Data.Monoid | 74 | import Data.Monoid |
74 | import Network.DatagramServer.Mainline (KMessageOf) | 75 | import Network.DatagramServer.Mainline (KMessageOf) |
76 | import qualified Network.DatagramServer as KRPC (listen, Protocol(..)) | ||
77 | |||
75 | 78 | ||
76 | 79 | ||
77 | {----------------------------------------------------------------------- | 80 | {----------------------------------------------------------------------- |
@@ -97,8 +100,12 @@ dht :: (Ord ip, Address ip) | |||
97 | -> IO a -- ^ result. | 100 | -> IO a -- ^ result. |
98 | dht opts addr logfilter action = do | 101 | dht opts addr logfilter action = do |
99 | runStderrLoggingT $ filterLogger logfilter $ LoggingT $ \ logger -> do | 102 | runStderrLoggingT $ filterLogger logfilter $ LoggingT $ \ logger -> do |
100 | bracket (newNode defaultHandlers opts addr logger Nothing) closeNode $ | 103 | bracket (newNode opts addr logger Nothing) closeNode $ |
101 | \ node -> runDHT node action | 104 | \ node -> runDHT node $ do |
105 | hs <- defaultHandlers logger | ||
106 | m <- asks manager | ||
107 | liftIO $ KRPC.listen m hs (KRPC.Protocol Proxy Proxy) | ||
108 | action | ||
102 | {-# INLINE dht #-} | 109 | {-# INLINE dht #-} |
103 | 110 | ||
104 | {----------------------------------------------------------------------- | 111 | {----------------------------------------------------------------------- |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index d8665773..d4794038 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -377,8 +377,8 @@ locFromCS cs = case getCallStack cs of | |||
377 | -- 'closeNode' function, otherwise socket or other scarce resources may | 377 | -- 'closeNode' function, otherwise socket or other scarce resources may |
378 | -- leak. | 378 | -- leak. |
379 | newNode :: Address ip | 379 | newNode :: Address ip |
380 | => [NodeHandler] -- ^ handlers to run on accepted queries; | 380 | => -- [NodeHandler] -- ^ handlers to run on accepted queries; |
381 | -> Options -- ^ various dht options; | 381 | Options -- ^ various dht options; |
382 | -> NodeAddr ip -- ^ node address to bind; | 382 | -> NodeAddr ip -- ^ node address to bind; |
383 | -> LogFun -- ^ invoked on log messages; | 383 | -> LogFun -- ^ invoked on log messages; |
384 | #ifdef VERSION_bencoding | 384 | #ifdef VERSION_bencoding |
@@ -387,7 +387,7 @@ newNode :: Address ip | |||
387 | -> Maybe (NodeId Tox.Message) -- ^ use this NodeId, if not given a new one is generated. | 387 | -> Maybe (NodeId Tox.Message) -- ^ use this NodeId, if not given a new one is generated. |
388 | #endif | 388 | #endif |
389 | -> IO (Node ip) -- ^ a new DHT node running at given address. | 389 | -> IO (Node ip) -- ^ a new DHT node running at given address. |
390 | newNode hs opts naddr logger mbid = do | 390 | newNode opts naddr logger mbid = do |
391 | s <- createInternalState | 391 | s <- createInternalState |
392 | runInternalState initNode s | 392 | runInternalState initNode s |
393 | `onException` closeInternalState s | 393 | `onException` closeInternalState s |
@@ -396,7 +396,7 @@ newNode hs opts naddr logger mbid = do | |||
396 | nodeAddr = toSockAddr naddr | 396 | nodeAddr = toSockAddr naddr |
397 | initNode = do | 397 | initNode = do |
398 | s <- getInternalState | 398 | s <- getInternalState |
399 | (_, m) <- allocate (newManager rpcOpts (logt logger) nodeAddr hs) closeManager | 399 | (_, m) <- allocate (newManager rpcOpts (logt logger) nodeAddr []) closeManager |
400 | liftIO $ do | 400 | liftIO $ do |
401 | myId <- maybe genNodeId return mbid | 401 | myId <- maybe genNodeId return mbid |
402 | node <- Node opts myId s m | 402 | node <- Node opts myId s m |
@@ -405,7 +405,6 @@ newNode hs opts naddr logger mbid = do | |||
405 | <*> newTVarIO S.empty | 405 | <*> newTVarIO S.empty |
406 | <*> (newTVarIO =<< nullSessionTokens) | 406 | <*> (newTVarIO =<< nullSessionTokens) |
407 | <*> pure logger | 407 | <*> pure logger |
408 | KRPC.listen m (KRPC.Protocol Proxy Proxy) | ||
409 | return node | 408 | return node |
410 | 409 | ||
411 | -- | Some resources like listener thread may live for | 410 | -- | Some resources like listener thread may live for |