diff options
-rw-r--r-- | bittorrent.cabal | 1 | ||||
-rw-r--r-- | examples/dhtd.hs | 7 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 5 |
3 files changed, 10 insertions, 3 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal index 2dee30ee..b3165137 100644 --- a/bittorrent.cabal +++ b/bittorrent.cabal | |||
@@ -362,6 +362,7 @@ executable dhtd | |||
362 | , data-default | 362 | , data-default |
363 | , monad-logger | 363 | , monad-logger |
364 | , bittorrent | 364 | , bittorrent |
365 | , unix | ||
365 | 366 | ||
366 | -- Utility to work with torrent files. | 367 | -- Utility to work with torrent files. |
367 | executable mktorrent | 368 | executable mktorrent |
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 19b45acb..4afceb50 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -24,6 +24,7 @@ import System.IO.Error | |||
24 | import Text.PrettyPrint.HughesPJClass | 24 | import Text.PrettyPrint.HughesPJClass |
25 | import Text.Printf | 25 | import Text.Printf |
26 | import Control.Monad.Reader.Class | 26 | import Control.Monad.Reader.Class |
27 | import System.Posix.Process (getProcessID) | ||
27 | 28 | ||
28 | import Network.BitTorrent.Address | 29 | import Network.BitTorrent.Address |
29 | import Network.BitTorrent.DHT | 30 | import Network.BitTorrent.DHT |
@@ -153,12 +154,16 @@ clientSession st signalQuit sock n h = do | |||
153 | return $ do | 154 | return $ do |
154 | hPutClient h $ showReport r | 155 | hPutClient h $ showReport r |
155 | 156 | ||
156 | ("peers ", s) -> cmd $ do | 157 | ("peers", s) -> cmd $ do |
157 | let ih = fromString s | 158 | let ih = fromString s |
158 | ps <- allPeers ih | 159 | ps <- allPeers ih |
159 | return $ do | 160 | return $ do |
160 | hPutClient h $ showReport $ map (((,) "") . show . pPrint) ps | 161 | hPutClient h $ showReport $ map (((,) "") . show . pPrint) ps |
161 | 162 | ||
163 | ("pid", _) -> cmd $ return $ do | ||
164 | pid <- getProcessID | ||
165 | hPutClient h (show pid) | ||
166 | |||
162 | _ -> cmd0 $ hPutClient h "error." | 167 | _ -> cmd0 $ hPutClient h "error." |
163 | 168 | ||
164 | main :: IO () | 169 | main :: IO () |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index c08021c7..8dc3f7ac 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -395,8 +395,9 @@ routableAddress = do | |||
395 | myNodeIdAccordingTo :: NodeAddr ip -> DHT ip NodeId | 395 | myNodeIdAccordingTo :: NodeAddr ip -> DHT ip NodeId |
396 | myNodeIdAccordingTo _ = do | 396 | myNodeIdAccordingTo _ = do |
397 | info <- asks routingInfo >>= liftIO . atomically . readTVar | 397 | info <- asks routingInfo >>= liftIO . atomically . readTVar |
398 | fallback <- asks tentativeNodeId | 398 | maybe (asks tentativeNodeId) |
399 | return $ maybe fallback myNodeId info | 399 | (return . myNodeId) |
400 | info | ||
400 | 401 | ||
401 | -- | Get current routing table. Normally you don't need to use this | 402 | -- | Get current routing table. Normally you don't need to use this |
402 | -- function, but it can be usefull for debugging and profiling purposes. | 403 | -- function, but it can be usefull for debugging and profiling purposes. |