Skip to content

Commit

Permalink
Merge pull request #3660 from xoriole/popular_channel
Browse files Browse the repository at this point in the history
Content popularity
  • Loading branch information
qstokkink authored Jun 29, 2018
2 parents 5ab2c54 + 85c6b2a commit 727b40d
Show file tree
Hide file tree
Showing 23 changed files with 2,419 additions and 7 deletions.
16 changes: 16 additions & 0 deletions Tribler/Core/APIImplementation/LaunchManyCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self):
self.tunnel_community = None
self.trustchain_community = None
self.wallets = {}
self.popularity_community = None

self.startup_deferred = Deferred()

Expand Down Expand Up @@ -287,6 +288,21 @@ def load_ipv8_overlays(self):

self.ipv8.strategies.append((RandomWalk(self.market_community), 20))

# Popular Community
if self.session.config.get_popularity_community_enabled():
from Tribler.community.popularity.community import PopularityCommunity

local_peer = Peer(self.session.trustchain_keypair)

self.popularity_community = PopularityCommunity(local_peer, self.ipv8.endpoint, self.ipv8.network,
torrent_db=self.session.lm.torrent_db, session=self.session)

self.ipv8.overlays.append(self.popularity_community)

self.ipv8.strategies.append((RandomWalk(self.popularity_community), 20))

self.popularity_community.start()

@blocking_call_on_reactor_thread
def load_dispersy_communities(self):
self._logger.info("tribler: Preparing Dispersy communities...")
Expand Down
10 changes: 10 additions & 0 deletions Tribler/Core/CacheDB/SqliteCacheDBHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,16 @@ def getRecentlyCollectedTorrents(self, limit):
results = self._db.fetchall(sql, (limit,))
return [[str2bin(result[0]), result[1], result[2], result[3] or 0, result[4]] for result in results]

def getRecentlyCheckedTorrents(self, limit):
sql = u"""
SELECT T.infohash, T.num_seeders, T.num_leechers, T.last_tracker_check
FROM Torrent T
WHERE T.is_collected = 0 AND T.num_seeders > 1
AND T.secret is not 1 ORDER BY T.last_tracker_check, T.num_seeders DESC LIMIT ?
"""
results = self._db.fetchall(sql, (limit,))
return [[str2bin(result[0]), result[1], result[2], result[3] or 0] for result in results]

def getRandomlyCollectedTorrents(self, insert_time, limit):
sql = u"""
SELECT CT.infohash, CT.num_seeders, CT.num_leechers, T.last_tracker_check
Expand Down
4 changes: 4 additions & 0 deletions Tribler/Core/Config/config.spec
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ history_size = integer(min=1, default=20)
enabled = boolean(default=True)
sources = string_list(default=list())
max_disk_space = integer(min=0, default=53687091200)

[popularity_community]
enabled = boolean(default=True)
cache_dir = string(default=health_cache)
8 changes: 8 additions & 0 deletions Tribler/Core/Config/tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ def set_dummy_wallets_enabled(self, value):
def get_dummy_wallets_enabled(self):
return self.config['wallets']['dummy_wallets_enabled']

# Popular Community

def get_popularity_community_enabled(self):
return self.config['popularity_community']['enabled']

def set_popularity_community_enabled(self, value):
self.config['popularity_community']['enabled'] = value

# Torrent store

def get_torrent_store_enabled(self):
Expand Down
5 changes: 5 additions & 0 deletions Tribler/Core/Modules/search_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def search_for_torrents(self, keywords):
self._logger.warn("Could not send search in SearchCommunity, no verified candidates found")
break

self._current_keywords = keywords
# If popularity community is enabled, send the search request there as well
if self.session.lm.popularity_community:
self.session.lm.popularity_community.send_torrent_search_request(keywords)

return nr_requests_made

@call_on_reactor_thread
Expand Down
14 changes: 14 additions & 0 deletions Tribler/Core/TorrentChecker/torrent_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from Tribler.Core.TorrentChecker.session import create_tracker_session, FakeDHTSession, UdpSocketManager
from Tribler.Core.Utilities.tracker_utils import MalformedTrackerURLException
from Tribler.Core.simpledefs import NTFY_TORRENTS
from Tribler.community.popularity.repository import TYPE_TORRENT_HEALTH
from Tribler.dispersy.util import blocking_call_on_reactor_thread, call_on_reactor_thread
from Tribler.pyipv8.ipv8.taskmanager import TaskManager

Expand Down Expand Up @@ -198,6 +199,9 @@ def on_gui_request_completed(self, infohash, result):

self._update_torrent_result(torrent_update_dict)

# Add this result to popularity community to publish to subscribers
self.publish_torrent_result(torrent_update_dict)

return final_response

@call_on_reactor_thread
Expand Down Expand Up @@ -326,3 +330,13 @@ def _update_torrent_result(self, response):
self._torrent_db.updateTorrentCheckResult(torrent_id,
infohash, seeders, leechers, last_check, next_check,
status, retries)

def publish_torrent_result(self, response):
if response['seeders'] == 0:
self._logger.info("Not publishing zero seeded torrents")
return
content = (response['infohash'], response['seeders'], response['leechers'], response['last_check'])
if self.tribler_session.lm.popularity_community:
self.tribler_session.lm.popularity_community.queue_content(TYPE_TORRENT_HEALTH, content)
else:
self._logger.info("Popular community not available to publish torrent checker result")
Empty file.
Loading

0 comments on commit 727b40d

Please sign in to comment.