diff options
author | joe <joe@jerkface.net> | 2018-06-09 15:59:22 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-09 15:59:22 -0400 |
commit | e4e4650d004cba42bfd8897d9658bfcaec82fb6d (patch) | |
tree | 3a4476002f04b099dd3e02072010efeed2579222 /src/Network/BitTorrent/MainlineDHT.hs | |
parent | e75cc83de37b628418c313b61db8864a04763562 (diff) |
bittorrent: Expire old peer announcements.
Diffstat (limited to 'src/Network/BitTorrent/MainlineDHT.hs')
-rw-r--r-- | src/Network/BitTorrent/MainlineDHT.hs | 20 |
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 | |||
47 | import Data.Ord | 47 | import Data.Ord |
48 | import qualified Data.Serialize as S | 48 | import qualified Data.Serialize as S |
49 | import Data.Set (Set) | 49 | import Data.Set (Set) |
50 | import Data.Time.Clock.POSIX (POSIXTime) | 50 | import Data.Time.Clock.POSIX (POSIXTime, getPOSIXTime) |
51 | import Data.Torrent | 51 | import Data.Torrent |
52 | import Data.Typeable | 52 | import Data.Typeable |
53 | import Data.Word | 53 | import 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. | ||
668 | forkAnnouncedInfohashesGC :: TVar PeerStore -> IO ThreadId | ||
669 | forkAnnouncedInfohashesGC 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 | -- |