summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/MainlineDHT.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-09 15:59:22 -0400
committerjoe <joe@jerkface.net>2018-06-09 15:59:22 -0400
commite4e4650d004cba42bfd8897d9658bfcaec82fb6d (patch)
tree3a4476002f04b099dd3e02072010efeed2579222 /src/Network/BitTorrent/MainlineDHT.hs
parente75cc83de37b628418c313b61db8864a04763562 (diff)
bittorrent: Expire old peer announcements.
Diffstat (limited to 'src/Network/BitTorrent/MainlineDHT.hs')
-rw-r--r--src/Network/BitTorrent/MainlineDHT.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/MainlineDHT.hs b/src/Network/BitTorrent/MainlineDHT.hs
index f43b070c..63e67ad3 100644
--- a/src/Network/BitTorrent/MainlineDHT.hs
+++ b/src/Network/BitTorrent/MainlineDHT.hs
@@ -47,7 +47,7 @@ import Data.Monoid
47import Data.Ord 47import Data.Ord
48import qualified Data.Serialize as S 48import qualified Data.Serialize as S
49import Data.Set (Set) 49import Data.Set (Set)
50import Data.Time.Clock.POSIX (POSIXTime) 50import Data.Time.Clock.POSIX (POSIXTime, getPOSIXTime)
51import Data.Torrent 51import Data.Torrent
52import Data.Typeable 52import Data.Typeable
53import Data.Word 53import Data.Word
@@ -631,7 +631,7 @@ newClient swarms addr = do
631 , clientResponseId = return 631 , clientResponseId = return
632 } 632 }
633 633
634 -- TODO: Provide some means of shutting down these four auxillary threads: 634 -- TODO: Provide some means of shutting down these five auxillary threads:
635 635
636 fork $ fix $ \again -> do 636 fork $ fix $ \again -> do
637 myThreadId >>= flip labelThread "addr4" 637 myThreadId >>= flip labelThread "addr4"
@@ -656,8 +656,24 @@ newClient swarms addr = do
656 refresh_thread4 <- forkPollForRefresh $ refresher4 routing 656 refresh_thread4 <- forkPollForRefresh $ refresher4 routing
657 refresh_thread6 <- forkPollForRefresh $ refresher6 routing 657 refresh_thread6 <- forkPollForRefresh $ refresher6 routing
658 658
659 forkAnnouncedInfohashesGC (contactInfo swarms)
660
659 return (client, routing, bootstrap (refresher4 routing), bootstrap (refresher6 routing)) 661 return (client, routing, bootstrap (refresher4 routing), bootstrap (refresher6 routing))
660 662
663-- Note that you should call .put() every hour for content that you want to
664-- keep alive, since nodes may discard data nodes older than 2 hours. (source:
665-- https://www.npmjs.com/package/bittorrent-dht)
666--
667-- This function will discard records between 3 and 6 hours old.
668forkAnnouncedInfohashesGC :: TVar PeerStore -> IO ThreadId
669forkAnnouncedInfohashesGC vpeers = fork $ do
670 myThreadId >>= flip labelThread "gc:bt-peers"
671 fix $ \loop -> do
672 cutoff <- getPOSIXTime
673 threadDelay 10800000000 -- 3 hours
674 atomically $ modifyTVar' vpeers $ deleteOlderThan cutoff
675 loop
676
661-- | Modifies a purely random 'NodeId' to one that is related to a given 677-- | Modifies a purely random 'NodeId' to one that is related to a given
662-- routable address in accordance with BEP 42. 678-- routable address in accordance with BEP 42.
663-- 679--