summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/Session.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT/Session.hs')
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 339b18eb..4f861a1e 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -33,6 +33,7 @@ module Network.BitTorrent.DHT.Session
33 , myNodeIdAccordingTo 33 , myNodeIdAccordingTo
34 , routingInfo 34 , routingInfo
35 , routableAddress 35 , routableAddress
36 , getTimestamp
36 37
37 -- ** Initialization 38 -- ** Initialization
38 , LogFun 39 , LogFun
@@ -86,6 +87,10 @@ import Data.Set as S
86import Data.Time 87import Data.Time
87import Network (PortNumber) 88import Network (PortNumber)
88import System.Random (randomIO) 89import System.Random (randomIO)
90import Data.Time.Clock.POSIX
91import Data.Text as Text
92import Text.PrettyPrint.HughesPJClass hiding ((<>),($$))
93
89 94
90import Data.Torrent as Torrent 95import Data.Torrent as Torrent
91import Network.KRPC as KRPC hiding (Options, def) 96import Network.KRPC as KRPC hiding (Options, def)
@@ -435,7 +440,18 @@ lookupPeers :: Ord ip => InfoHash -> DHT ip [PeerAddr ip]
435lookupPeers ih = do 440lookupPeers ih = do
436 refreshContacts 441 refreshContacts
437 var <- asks contactInfo 442 var <- asks contactInfo
438 liftIO $ P.lookup ih <$> readTVarIO var 443 tm <- getTimestamp
444 liftIO $ atomically $ do
445 (ps,store') <- P.freshPeers ih tm <$> readTVar var
446 writeTVar var store'
447 return ps
448
449getTimestamp :: DHT ip Timestamp
450getTimestamp = do
451 utcTime <- liftIO $ getCurrentTime
452 $(logDebugS) "routing.make_timestamp" (Text.pack (render (pPrint utcTime)))
453 return $ utcTimeToPOSIXSeconds utcTime
454
439 455
440-- | Prepare result for 'get_peers' query. 456-- | Prepare result for 'get_peers' query.
441-- 457--