summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bittorrent.cabal1
-rw-r--r--examples/dhtd.hs7
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs5
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.
367executable mktorrent 368executable 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
24import Text.PrettyPrint.HughesPJClass 24import Text.PrettyPrint.HughesPJClass
25import Text.Printf 25import Text.Printf
26import Control.Monad.Reader.Class 26import Control.Monad.Reader.Class
27import System.Posix.Process (getProcessID)
27 28
28import Network.BitTorrent.Address 29import Network.BitTorrent.Address
29import Network.BitTorrent.DHT 30import 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
164main :: IO () 169main :: 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
395myNodeIdAccordingTo :: NodeAddr ip -> DHT ip NodeId 395myNodeIdAccordingTo :: NodeAddr ip -> DHT ip NodeId
396myNodeIdAccordingTo _ = do 396myNodeIdAccordingTo _ = 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.