diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/DHT.hs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs index 3867d182..7ca8fc8b 100644 --- a/src/Network/BitTorrent/DHT.hs +++ b/src/Network/BitTorrent/DHT.hs | |||
@@ -21,6 +21,7 @@ module Network.BitTorrent.DHT | |||
21 | ( -- * Distributed Hash Table | 21 | ( -- * Distributed Hash Table |
22 | DHT | 22 | DHT |
23 | , Options (..) | 23 | , Options (..) |
24 | , fullLogging | ||
24 | , dht | 25 | , dht |
25 | 26 | ||
26 | -- * Bootstrapping | 27 | -- * Bootstrapping |
@@ -82,14 +83,19 @@ class MonadDHT m where | |||
82 | instance MonadDHT (DHT IPv4) where | 83 | instance MonadDHT (DHT IPv4) where |
83 | liftDHT = id | 84 | liftDHT = id |
84 | 85 | ||
86 | -- | Convenience method. Pass this to 'dht' to enable full logging. | ||
87 | fullLogging :: LogSource -> LogLevel -> Bool | ||
88 | fullLogging _ _ = True | ||
89 | |||
85 | -- | Run DHT on specified port. <add note about resources> | 90 | -- | Run DHT on specified port. <add note about resources> |
86 | dht :: Address ip | 91 | dht :: Address ip |
87 | => Options -- ^ normally you need to use 'Data.Default.def'; | 92 | => Options -- ^ normally you need to use 'Data.Default.def'; |
88 | -> NodeAddr ip -- ^ address to bind this node; | 93 | -> NodeAddr ip -- ^ address to bind this node; |
94 | -> (LogSource -> LogLevel -> Bool) -- ^ use 'fullLogging' as a noisy default | ||
89 | -> DHT ip a -- ^ actions to run: 'bootstrap', 'lookup', etc; | 95 | -> DHT ip a -- ^ actions to run: 'bootstrap', 'lookup', etc; |
90 | -> IO a -- ^ result. | 96 | -> IO a -- ^ result. |
91 | dht opts addr action = do | 97 | dht opts addr logfilter action = do |
92 | runStderrLoggingT $ LoggingT $ \ logger -> do | 98 | runStderrLoggingT $ filterLogger logfilter $ LoggingT $ \ logger -> do |
93 | bracket (newNode defaultHandlers opts addr logger Nothing) closeNode $ | 99 | bracket (newNode defaultHandlers opts addr logger Nothing) closeNode $ |
94 | \ node -> runDHT node action | 100 | \ node -> runDHT node action |
95 | {-# INLINE dht #-} | 101 | {-# INLINE dht #-} |