Skip to content

Commit

Permalink
- Basic content popular community
Browse files Browse the repository at this point in the history
- Peers selected based on trust score
- New torrent check results are shared to subscribers
- Added unload popular community on shutdown and fixed tests
- Periodically subscribe to more peers if necessary
- Added the master key for the community
  • Loading branch information
xoriole committed Jun 8, 2018
1 parent f304394 commit 4e56d0a
Show file tree
Hide file tree
Showing 16 changed files with 1,212 additions and 6 deletions.
19 changes: 19 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.torrent_checker = None
self.tunnel_community = None
self.triblerchain_community = None
self.popular_community = None

self.startup_deferred = Deferred()

Expand Down Expand Up @@ -304,6 +305,21 @@ def load_ipv8_overlays(self):

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

# Popular Community
if self.session.config.get_popular_community_enabled():
from Tribler.community.popular.community import PopularCommunity

local_peer = Peer(self.session.trustchain_keypair)

self.popular_community = PopularCommunity(local_peer, self.ipv8.endpoint, self.ipv8.network,
torrent_db=self.session.lm.torrent_db)

self.ipv8.overlays.append(self.popular_community)

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

self.popular_community.start()

@blocking_call_on_reactor_thread
def load_dispersy_communities(self):
self._logger.info("tribler: Preparing Dispersy communities...")
Expand Down Expand Up @@ -873,6 +889,9 @@ def early_shutdown(self):
yield self.ipv8.unload_overlay(self.tunnel_community)
yield self.ipv8.unload_overlay(self.triblerchain_community)

if self.popular_community:
yield self.ipv8.unload_overlay(self.popular_community)

if self.dispersy:
self._logger.info("lmc: Shutting down Dispersy...")
now = timemod.time()
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 @@ -114,3 +114,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)

[popular_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 @@ -531,6 +531,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_popular_community_enabled(self):
return self.config['popular_community']['enabled']

def set_popular_community_enabled(self, value):
self.config['popular_community']['enabled'] = value

# Torrent store

def get_torrent_store_enabled(self):
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.popular.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 popular 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.popular_community:
self.tribler_session.lm.popular_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 4e56d0a

Please sign in to comment.