diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT/Session.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 18 |
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 | |||
86 | import Data.Time | 87 | import Data.Time |
87 | import Network (PortNumber) | 88 | import Network (PortNumber) |
88 | import System.Random (randomIO) | 89 | import System.Random (randomIO) |
90 | import Data.Time.Clock.POSIX | ||
91 | import Data.Text as Text | ||
92 | import Text.PrettyPrint.HughesPJClass hiding ((<>),($$)) | ||
93 | |||
89 | 94 | ||
90 | import Data.Torrent as Torrent | 95 | import Data.Torrent as Torrent |
91 | import Network.KRPC as KRPC hiding (Options, def) | 96 | import Network.KRPC as KRPC hiding (Options, def) |
@@ -435,7 +440,18 @@ lookupPeers :: Ord ip => InfoHash -> DHT ip [PeerAddr ip] | |||
435 | lookupPeers ih = do | 440 | lookupPeers 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 | |||
449 | getTimestamp :: DHT ip Timestamp | ||
450 | getTimestamp = 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 | -- |