Skip to content

Commit

Permalink
fixed bug with updating torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Jun 12, 2018
1 parent 75c03cb commit 21fb686
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Tribler/community/popular/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def get_top_torrents(self, limit=DEFAULT_TORRENT_LIMIT):
def update_torrent_health(self, torrent_health_payload, peer_trust=0):
assert torrent_health_payload and isinstance(torrent_health_payload, TorrentHealthPayload)

def update_torrent(db_handler, health_payload):
db_handler.updateTorrent(infohash, notify=False, num_seeders=health_payload.num_seeders,
num_leechers=health_payload.num_leechers,
last_tracker_check=int(health_payload.timestamp),
status=u"good" if health_payload.num_seeders > 1 else u"unknown")

if not self.torrent_db:
self._logger.error("Torrent DB is None")
return
Expand All @@ -52,14 +58,13 @@ def update_torrent_health(self, torrent_health_payload, peer_trust=0):
if self.has_torrent(infohash):
db_torrent = self.get_torrent(infohash)
is_fresh = time.time() - db_torrent['last_tracker_check'] < DEFAULT_FRESHNESS_LIMIT
if is_fresh or peer_trust < 2:
self._logger.info("Database record is either fresh or peer trust score is too low. Ignoring response.")
if is_fresh and peer_trust < 2:
self._logger.info("Database record is already fresh and the sending peer trust "
"score is too low so we just ignore the response.")
return

# Update the torrent health anyway. A torrent info request should be sent separately to request additional info.
self.update_torrent_in_db(self, infohash, seeder=torrent_health_payload.num_seeders,
leecher=torrent_health_payload.num_leechers,
last_torrent_check=int(torrent_health_payload.timestamp))
update_torrent(self.torrent_db, torrent_health_payload)

def update_torrent_info(self, torrent_info_response):
infohash = torrent_info_response.infohash
Expand All @@ -70,7 +75,7 @@ def update_torrent_info(self, torrent_info_response):
return

# Update local database
self.update_torrent_in_db(self, infohash, name=torrent_info_response.name,
self.torrent_db.updateTorrent(infohash, notify=False, name=torrent_info_response.name,
length=torrent_info_response.length,
creation_date=torrent_info_response.creation_date,
num_files=torrent_info_response.num_files,
Expand All @@ -82,7 +87,4 @@ def get_torrent(self, infohash):
return self.torrent_db.getTorrent(infohash, keys=keys, include_mypref=False)

def has_torrent(self, infohash):
return self.torrent_db.hasTorrent(infohash)

def update_torrent_in_db(self, infohash, **kw):
self.torrent_db.updateTorrent(infohash, notify=False, **kw)
return self.get_torrent(infohash) is not None

0 comments on commit 21fb686

Please sign in to comment.