diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-21 02:48:58 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-21 02:48:58 +0400 |
commit | 76ef96ac3d5ad8d8ac3921fb0683a8e192e54090 (patch) | |
tree | 31061c252041942294a2cb2009355decc73b0872 | |
parent | a1b4c8f9ed0034fd383cfc3d5162135fc81f49c9 (diff) |
Rename startNode to newNode
-rw-r--r-- | src/Network/BitTorrent/Client.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT.hs | 6 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 12 | ||||
-rw-r--r-- | tests/Network/BitTorrent/DHT/QuerySpec.hs | 2 | ||||
-rw-r--r-- | tests/Network/BitTorrent/DHT/SessionSpec.hs | 4 |
5 files changed, 14 insertions, 14 deletions
diff --git a/src/Network/BitTorrent/Client.hs b/src/Network/BitTorrent/Client.hs index 905d3384..bd4993ba 100644 --- a/src/Network/BitTorrent/Client.hs +++ b/src/Network/BitTorrent/Client.hs | |||
@@ -98,8 +98,8 @@ initClient opts @ Options {..} logFun = do | |||
98 | let mkEx = Exchange.newManager (exchangeOptions pid opts) (connHandler tmap) | 98 | let mkEx = Exchange.newManager (exchangeOptions pid opts) (connHandler tmap) |
99 | (_, emgr) <- allocate mkEx Exchange.closeManager | 99 | (_, emgr) <- allocate mkEx Exchange.closeManager |
100 | 100 | ||
101 | let mkNode = startNode defaultHandlers def optNodeAddr logFun | 101 | let mkNode = DHT.newNode defaultHandlers def optNodeAddr logFun |
102 | (_, node) <- allocate mkNode stopNode | 102 | (_, node) <- allocate mkNode DHT.closeNode |
103 | 103 | ||
104 | resourceMap <- getInternalState | 104 | resourceMap <- getInternalState |
105 | return Client | 105 | return Client |
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs index ed42363f..44c55128 100644 --- a/src/Network/BitTorrent/DHT.hs +++ b/src/Network/BitTorrent/DHT.hs | |||
@@ -44,8 +44,8 @@ module Network.BitTorrent.DHT | |||
44 | , LogFun | 44 | , LogFun |
45 | , Node | 45 | , Node |
46 | , defaultHandlers | 46 | , defaultHandlers |
47 | , startNode | 47 | , newNode |
48 | , stopNode | 48 | , closeNode |
49 | 49 | ||
50 | -- ** Monad | 50 | -- ** Monad |
51 | , MonadDHT (..) | 51 | , MonadDHT (..) |
@@ -86,7 +86,7 @@ dht :: Address ip | |||
86 | -> IO a -- ^ result. | 86 | -> IO a -- ^ result. |
87 | dht opts addr action = do | 87 | dht opts addr action = do |
88 | runStderrLoggingT $ LoggingT $ \ logger -> do | 88 | runStderrLoggingT $ LoggingT $ \ logger -> do |
89 | bracket (startNode defaultHandlers opts addr logger) stopNode $ | 89 | bracket (newNode defaultHandlers opts addr logger) closeNode $ |
90 | \ node -> runDHT node action | 90 | \ node -> runDHT node action |
91 | {-# INLINE dht #-} | 91 | {-# INLINE dht #-} |
92 | 92 | ||
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index 69970918..43bd65e5 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -33,8 +33,8 @@ module Network.BitTorrent.DHT.Session | |||
33 | -- ** Initialization | 33 | -- ** Initialization |
34 | , LogFun | 34 | , LogFun |
35 | , NodeHandler | 35 | , NodeHandler |
36 | , startNode | 36 | , newNode |
37 | , stopNode | 37 | , closeNode |
38 | 38 | ||
39 | -- * DHT | 39 | -- * DHT |
40 | -- | Use @asks options@ to get options passed to 'startNode' | 40 | -- | Use @asks options@ to get options passed to 'startNode' |
@@ -294,13 +294,13 @@ type NodeHandler ip = Handler (DHT ip) | |||
294 | -- | Run DHT session. You /must/ properly close session using | 294 | -- | Run DHT session. You /must/ properly close session using |
295 | -- 'stopNode' function, otherwise socket or other scarce resources may | 295 | -- 'stopNode' function, otherwise socket or other scarce resources may |
296 | -- leak. | 296 | -- leak. |
297 | startNode :: Address ip | 297 | newNode :: Address ip |
298 | => [NodeHandler ip] -- ^ handlers to run on accepted queries; | 298 | => [NodeHandler ip] -- ^ handlers to run on accepted queries; |
299 | -> Options -- ^ various dht options; | 299 | -> Options -- ^ various dht options; |
300 | -> NodeAddr ip -- ^ node address to bind; | 300 | -> NodeAddr ip -- ^ node address to bind; |
301 | -> LogFun -- ^ | 301 | -> LogFun -- ^ |
302 | -> IO (Node ip) -- ^ a new DHT node running at given address. | 302 | -> IO (Node ip) -- ^ a new DHT node running at given address. |
303 | startNode hs opts naddr logger = do | 303 | newNode hs opts naddr logger = do |
304 | s <- createInternalState | 304 | s <- createInternalState |
305 | runInternalState initNode s | 305 | runInternalState initNode s |
306 | `onException` closeInternalState s | 306 | `onException` closeInternalState s |
@@ -323,8 +323,8 @@ startNode hs opts naddr logger = do | |||
323 | 323 | ||
324 | -- | Some resources like listener thread may live for | 324 | -- | Some resources like listener thread may live for |
325 | -- some short period of time right after this DHT session closed. | 325 | -- some short period of time right after this DHT session closed. |
326 | stopNode :: Node ip -> IO () | 326 | closeNode :: Node ip -> IO () |
327 | stopNode Node {..} = closeInternalState resources | 327 | closeNode Node {..} = closeInternalState resources |
328 | 328 | ||
329 | -- | Run DHT operation on the given session. | 329 | -- | Run DHT operation on the given session. |
330 | runDHT :: Node ip -> DHT ip a -> IO a | 330 | runDHT :: Node ip -> DHT ip a -> IO a |
diff --git a/tests/Network/BitTorrent/DHT/QuerySpec.hs b/tests/Network/BitTorrent/DHT/QuerySpec.hs index b89ce4ff..33114b40 100644 --- a/tests/Network/BitTorrent/DHT/QuerySpec.hs +++ b/tests/Network/BitTorrent/DHT/QuerySpec.hs | |||
@@ -28,7 +28,7 @@ nullLogger _ _ _ _ = return () | |||
28 | 28 | ||
29 | simpleDHT :: [NodeHandler IPv4] -> DHT IPv4 a -> IO a | 29 | simpleDHT :: [NodeHandler IPv4] -> DHT IPv4 a -> IO a |
30 | simpleDHT hs m = | 30 | simpleDHT hs m = |
31 | bracket (startNode hs def myAddr nullLogger) stopNode $ \ node -> | 31 | bracket (newNode hs def myAddr nullLogger) closeNode $ \ node -> |
32 | runDHT node m | 32 | runDHT node m |
33 | 33 | ||
34 | getBootInfo :: IO (NodeInfo IPv4) | 34 | getBootInfo :: IO (NodeInfo IPv4) |
diff --git a/tests/Network/BitTorrent/DHT/SessionSpec.hs b/tests/Network/BitTorrent/DHT/SessionSpec.hs index 41852763..b3b9a9fc 100644 --- a/tests/Network/BitTorrent/DHT/SessionSpec.hs +++ b/tests/Network/BitTorrent/DHT/SessionSpec.hs | |||
@@ -39,10 +39,10 @@ spec :: Spec | |||
39 | spec = do | 39 | spec = do |
40 | describe "session" $ do | 40 | describe "session" $ do |
41 | it "is active until stopNode called" $ do | 41 | it "is active until stopNode called" $ do |
42 | node <- startNode [] def myAddr nullLogger | 42 | node <- newNode [] def myAddr nullLogger |
43 | runDHT node monadActive `shouldReturn` True | 43 | runDHT node monadActive `shouldReturn` True |
44 | runDHT node monadActive `shouldReturn` True | 44 | runDHT node monadActive `shouldReturn` True |
45 | stopNode node | 45 | closeNode node |
46 | runDHT node monadActive `shouldReturn` False | 46 | runDHT node monadActive `shouldReturn` False |
47 | 47 | ||
48 | describe "tokens" $ do | 48 | describe "tokens" $ do |