Skip to content

Commit

Permalink
Renamed popular community to popularity community
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Jun 28, 2018
1 parent 63a1847 commit bc19910
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 79 deletions.
4 changes: 2 additions & 2 deletions Tribler/Core/APIImplementation/LaunchManyCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ 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 PopularityCommunity
if self.session.config.get_popularity_community_enabled():
from Tribler.community.popularity.community import PopularityCommunity

local_peer = Peer(self.session.trustchain_keypair)

Expand Down
2 changes: 1 addition & 1 deletion Tribler/Core/Config/config.spec
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ enabled = boolean(default=True)
sources = string_list(default=list())
max_disk_space = integer(min=0, default=53687091200)

[popular_community]
[popularity_community]
enabled = boolean(default=True)
cache_dir = string(default=health_cache)
8 changes: 4 additions & 4 deletions Tribler/Core/Config/tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ def get_dummy_wallets_enabled(self):

# Popular Community

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

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

# Torrent store

Expand Down
2 changes: 1 addition & 1 deletion Tribler/Core/Modules/search_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def search_for_torrents(self, keywords):
break

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

Expand Down
8 changes: 4 additions & 4 deletions Tribler/Core/TorrentChecker/torrent_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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.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 @@ -199,7 +199,7 @@ 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
# Add this result to popularity community to publish to subscribers
self.publish_torrent_result(torrent_update_dict)

return final_response
Expand Down Expand Up @@ -336,7 +336,7 @@ def publish_torrent_result(self, response):
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)
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")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
import string

from Tribler.Test.Core.base_test import MockObject
from Tribler.community.popular import constants
from Tribler.community.popular.community import PopularityCommunity, MSG_TORRENT_HEALTH_RESPONSE, \
from Tribler.community.popularity import constants
from Tribler.community.popularity.community import PopularityCommunity, MSG_TORRENT_HEALTH_RESPONSE, \
MSG_CHANNEL_HEALTH_RESPONSE, ERROR_UNKNOWN_PEER, ERROR_NO_CONTENT, \
ERROR_UNKNOWN_RESPONSE
from Tribler.community.popular.constants import SEARCH_TORRENT_REQUEST, MSG_TORRENT_INFO_RESPONSE, MSG_SUBSCRIPTION
from Tribler.community.popular.payload import SearchResponseItemPayload, TorrentInfoResponsePayload, \
from Tribler.community.popularity.constants import SEARCH_TORRENT_REQUEST, MSG_TORRENT_INFO_RESPONSE, MSG_SUBSCRIPTION
from Tribler.community.popularity.payload import SearchResponseItemPayload, TorrentInfoResponsePayload, \
TorrentHealthPayload, ContentSubscription
from Tribler.community.popular.repository import TYPE_TORRENT_HEALTH
from Tribler.community.popularity.repository import TYPE_TORRENT_HEALTH
from Tribler.pyipv8.ipv8.test.base import TestBase
from Tribler.pyipv8.ipv8.test.mocking.ipv8 import MockIPv8
from Tribler.pyipv8.ipv8.test.util import twisted_wrapper


class TestPopularCommunityBase(TestBase):
class TestPopularityCommunityBase(TestBase):
NUM_NODES = 2

def setUp(self):
super(TestPopularCommunityBase, self).setUp()
super(TestPopularityCommunityBase, self).setUp()
self.initialize(PopularityCommunity, self.NUM_NODES)

def create_node(self, *args, **kwargs):
Expand Down Expand Up @@ -101,7 +101,7 @@ def update_from_torrent_search_results(self, search_results):
pass


class TestPopularCommunity(TestPopularCommunityBase):
class TestPopularityCommunity(TestPopularityCommunityBase):
__testing__ = False
NUM_NODES = 2

Expand Down Expand Up @@ -277,7 +277,7 @@ def test_publish_no_content(self):
@twisted_wrapper
def test_send_subscription(self):
"""
Tests sending popular content subscription response.
Tests sending popularity content subscription response.
"""
original_logger = self.nodes[0].overlay.logger
self.nodes[0].overlay.logger.error = lambda *args, **kw: self.fake_logger_error(self.nodes[0], *args)
Expand Down Expand Up @@ -611,12 +611,18 @@ def test_on_subscription_status_with_unsubscribe(self):

self.assertEqual(len(self.nodes[0].overlay.publishers), 0)

@twisted_wrapper(5)
@twisted_wrapper
def test_search_request_response(self):
self.nodes[0].overlay.content_repository = MockRepository()
self.nodes[1].overlay.content_repository = MockRepository()
self.nodes[1].overlay.publish_latest_torrents = lambda *args, **kwargs: None

def fake_process_torrent_search_response(peer):
peer.called_process_torrent_search_response = True

self.nodes[0].overlay.process_torrent_search_response = lambda query, payload: \
fake_process_torrent_search_response(self.nodes[0])

yield self.introduce_nodes()
self.nodes[0].overlay.subscribe_peers()
yield self.deliver_messages()
Expand All @@ -627,6 +633,9 @@ def test_search_request_response(self):

yield self.deliver_messages()

self.assertTrue(self.nodes[0].called_process_torrent_search_response)


@twisted_wrapper
def test_send_content_info_request(self):
self.nodes[0].overlay.content_repository = MockRepository()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import string
from unittest import TestCase

from Tribler.community.popular.payload import SearchResponsePayload, SearchResponseItemPayload, ContentInfoRequest, \
from Tribler.community.popularity.payload import SearchResponsePayload, SearchResponseItemPayload, ContentInfoRequest, \
Pagination, ContentInfoResponse, ContentSubscription, TorrentHealthPayload, ChannelHealthPayload
from Tribler.pyipv8.ipv8.messaging.serialization import Serializer

Expand Down Expand Up @@ -169,9 +169,9 @@ def test_content_info_response(self):
serialized_response = self.serializer.pack_multiple(in_response.to_pack_list())

# Deserialize request and test it
(deserialized_ressponse, _) = self.serializer.unpack_multiple(ContentInfoResponse.format_list,
(deserialized_response, _) = self.serializer.unpack_multiple(ContentInfoResponse.format_list,
serialized_response)
out_request = ContentInfoResponse.from_unpack_list(*deserialized_ressponse)
out_request = ContentInfoResponse.from_unpack_list(*deserialized_response)
self.assertEqual(in_response.identifier, out_request.identifier)
self.assertEqual(in_response.response, out_request.response)
self.assertEqual(in_response.content_type, out_request.content_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import unittest

from Tribler.Test.Core.base_test import MockObject
from Tribler.community.popular.payload import TorrentHealthPayload
from Tribler.community.popular.repository import ContentRepository, DEFAULT_FRESHNESS_LIMIT
from Tribler.community.popularity.payload import TorrentHealthPayload
from Tribler.community.popularity.repository import ContentRepository, DEFAULT_FRESHNESS_LIMIT


class TestContentRepository(unittest.TestCase):
Expand Down Expand Up @@ -129,14 +129,15 @@ def test_update_torrent_info(self):
def fake_update_torrent(ref):
ref.called_update_torrent = True

self.content_repository.torrent_db.updateTorrent = lambda infohash, **kw: fake_update_torrent(self.content_repository)
self.content_repository.torrent_db.updateTorrent = lambda infohash, **kw: \
fake_update_torrent(self.content_repository)
self.content_repository.has_torrent = lambda infohash: False
torrent_info_response = MockObject()
torrent_info_response.infohash = 'a' * 20

torrent_info_response.name = 'ubuntu',
torrent_info_response.name = 'ubuntu'
torrent_info_response.length = 123
torrent_info_response.creation_date =123123123
torrent_info_response.creation_date = 123123123
torrent_info_response.num_files = 2
torrent_info_response.comment = 'Ubuntu ISO'

Expand Down Expand Up @@ -217,23 +218,21 @@ def test_search_channel(self):
def random_string(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))

def random_infohash():
return ''.join(random.choice('0123456789abcdef') for _ in range(20))

sample_channels = []
for index in range(10):
dbid = index
cid = random_string(size=20)
name = random_string()
description = random_string(20)
nr_torrents = random.randint(1, 10)
nr_favorite = random.randint(1,10)
nr_favorite = random.randint(1, 10)
nr_spam = random.randint(1, 10)
my_vote = 1
modified = random.randint(1, 10000000)
relevance_score = 0.0

sample_channels.append([dbid, cid, name, description, nr_torrents, nr_favorite, nr_spam, my_vote, modified, relevance_score])
sample_channels.append([dbid, cid, name, description, nr_torrents, nr_favorite, nr_spam, my_vote,
modified, relevance_score])

def fake_torrentdb_search_channels(_):
return sample_channels
Expand Down Expand Up @@ -289,8 +288,7 @@ def get_torrent(torrent_as_list):
'creation_date': torrent_as_list[5],
'seeders': torrent_as_list[6],
'leechers': torrent_as_list[7],
'cid': torrent_as_list[8],
}
'cid': torrent_as_list[8]}

def fake_update_torrent(ref):
ref.called_update_torrent = True
Expand Down
8 changes: 4 additions & 4 deletions Tribler/Test/Core/Config/test_tribler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ def test_get_set_methods_preview_channel_community(self):
self.tribler_config.set_preview_channel_community_enabled(True)
self.assertEqual(self.tribler_config.get_preview_channel_community_enabled(), True)

def test_get_set_methods_popular_community(self):
def test_get_set_methods_popularity_community(self):
"""
Check whether popular community get and set methods are working as expected.
Check whether popularity community get and set methods are working as expected.
"""
self.tribler_config.set_popular_community_enabled(True)
self.assertEqual(self.tribler_config.get_popular_community_enabled(), True)
self.tribler_config.set_popularity_community_enabled(True)
self.assertEqual(self.tribler_config.get_popularity_community_enabled(), True)

def test_get_set_methods_watch_folder(self):
"""
Expand Down
32 changes: 16 additions & 16 deletions Tribler/Test/Core/TorrentChecker/test_torrentchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from Tribler.Core.simpledefs import NTFY_TORRENTS
from Tribler.Test.Core.base_test import TriblerCoreTest, MockObject
from Tribler.Test.twisted_thread import deferred
from Tribler.community.popular.repository import TYPE_TORRENT_HEALTH
from Tribler.community.popularity.repository import TYPE_TORRENT_HEALTH
from Tribler.pyipv8.ipv8.util import blocking_call_on_reactor_thread


Expand All @@ -33,7 +33,7 @@ def setUp(self, annotate=True):
self.session.lm.torrent_db = TorrentDBHandler(self.session)
self.session.lm.torrent_checker = TorrentChecker(self.session)
self.session.lm.tracker_manager = TrackerManager(self.session)
self.session.lm.popular_community = MockObject()
self.session.lm.popularity_community = MockObject()

self.torrent_checker = self.session.lm.torrent_checker
self.torrent_checker._torrent_db = self.session.open_dbhandler(NTFY_TORRENTS)
Expand Down Expand Up @@ -190,23 +190,23 @@ def remove_tracker(tracker_url):

def test_publish_torrent_result(self):
MSG_ZERO_SEED_TORRENT = "Not publishing zero seeded torrents"
MSG_NO_POPULAR_COMMUNITY = "Popular community not available to publish torrent checker result"
MSG_NO_popularity_community = "Popular community not available to publish torrent checker result"

def _fake_logger_info(torrent_checker, msg):
if msg == MSG_ZERO_SEED_TORRENT:
torrent_checker.zero_seed_torrent = True
if msg == MSG_NO_POPULAR_COMMUNITY:
torrent_checker.popular_community_not_found = True
if msg == MSG_NO_popularity_community:
torrent_checker.popularity_community_not_found = True

original_logger_info = self.torrent_checker._logger.info
self.torrent_checker._logger.info = lambda msg: _fake_logger_info(self.torrent_checker, msg)

def popular_community_queue_content(torrent_checker, _type, _):
torrent_checker.popular_community_queue_content_called = True
torrent_checker.popular_community_queue_content_called_type = _type
def popularity_community_queue_content(torrent_checker, _type, _):
torrent_checker.popularity_community_queue_content_called = True
torrent_checker.popularity_community_queue_content_called_type = _type

self.torrent_checker.tribler_session.lm.popular_community.queue_content = lambda _type, _content: \
popular_community_queue_content(self.torrent_checker, _type, _content)
self.torrent_checker.tribler_session.lm.popularity_community.queue_content = lambda _type, _content: \
popularity_community_queue_content(self.torrent_checker, _type, _content)

# Case1: Fake torrent checker response, seeders:0
fake_response = {'infohash': 'a'*20, 'seeders': 0, 'leechers': 0, 'last_check': time.time()}
Expand All @@ -215,17 +215,17 @@ def popular_community_queue_content(torrent_checker, _type, _):

# Case2: Positive seeders
fake_response['seeders'] = 5
self.torrent_checker.popular_community_queue_content_called = False
self.torrent_checker.popular_community_queue_content_called_type = None
self.torrent_checker.popularity_community_queue_content_called = False
self.torrent_checker.popularity_community_queue_content_called_type = None

self.torrent_checker.publish_torrent_result(fake_response)
self.assertTrue(self.torrent_checker.popular_community_queue_content_called)
self.assertEqual(self.torrent_checker.popular_community_queue_content_called_type, TYPE_TORRENT_HEALTH)
self.assertTrue(self.torrent_checker.popularity_community_queue_content_called)
self.assertEqual(self.torrent_checker.popularity_community_queue_content_called_type, TYPE_TORRENT_HEALTH)

# Case3: Popular community is None
self.torrent_checker.tribler_session.lm.popular_community = None
self.torrent_checker.tribler_session.lm.popularity_community = None
self.torrent_checker.publish_torrent_result(fake_response)
self.assertTrue(self.torrent_checker.popular_community_not_found)
self.assertTrue(self.torrent_checker.popularity_community_not_found)

self.torrent_checker._logger.info = original_logger_info

Expand Down
2 changes: 1 addition & 1 deletion Tribler/Test/test_as_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def setUpPreSession(self):
self.config.set_tunnel_community_enabled(False)
self.config.set_credit_mining_enabled(False)
self.config.set_market_community_enabled(False)
self.config.set_popular_community_enabled(False)
self.config.set_popularity_community_enabled(False)

@blocking_call_on_reactor_thread
@inlineCallbacks
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from twisted.internet.defer import inlineCallbacks

from Tribler.Core.simpledefs import SIGNAL_SEARCH_COMMUNITY, SIGNAL_ON_SEARCH_RESULTS
from Tribler.community.popular.constants import MSG_TORRENT_HEALTH_RESPONSE, MSG_CHANNEL_HEALTH_RESPONSE, \
from Tribler.community.popularity.constants import MSG_TORRENT_HEALTH_RESPONSE, MSG_CHANNEL_HEALTH_RESPONSE, \
MSG_TORRENT_INFO_REQUEST, MSG_TORRENT_INFO_RESPONSE, \
ERROR_UNKNOWN_RESPONSE, MAX_PACKET_PAYLOAD_SIZE, ERROR_UNKNOWN_PEER, ERROR_NO_CONTENT, \
MSG_CONTENT_INFO_REQUEST, \
SEARCH_TORRENT_REQUEST, MSG_CONTENT_INFO_RESPONSE, SEARCH_TORRENT_RESPONSE
from Tribler.community.popular.payload import TorrentHealthPayload, ContentSubscription, TorrentInfoRequestPayload, \
from Tribler.community.popularity.payload import TorrentHealthPayload, ContentSubscription, TorrentInfoRequestPayload, \
TorrentInfoResponsePayload, SearchResponseItemPayload, \
ContentInfoRequest, Pagination, ContentInfoResponse, decode_values
from Tribler.community.popular.pubsub import PubSubCommunity
from Tribler.community.popular.repository import ContentRepository, TYPE_TORRENT_HEALTH
from Tribler.community.popular.request import SearchRequest
from Tribler.community.popularity.pubsub import PubSubCommunity
from Tribler.community.popularity.repository import ContentRepository, TYPE_TORRENT_HEALTH
from Tribler.community.popularity.request import SearchRequest
from Tribler.pyipv8.ipv8.peer import Peer


class PopularityCommunity(PubSubCommunity):
"""
Community for disseminating the content across the network. Follows publish-subscribe model.
"""
MASTER_PUBLIC_KEY = "3081a7301006072a8648ce3d020106052b810400270381920004073beff7002b6a9fc2824a3b1bbb1c4fc32546261" \
"e3ef7537874560346c5fdc0c17fe654f67d23b08cbb44141879f79a7a4c8deddf9beb4fbc7a0f02ee1586ccebedb6" \
"23eeef51710108d702f9250361c071482e83c0a4a86c8f45a0b13a19ef83eacb6267b4bfccf220ae5f6d1db7125ea1" \
"d10da3744b65679828f23376e28b76ab33132b7fa984a77f159dba7351a7"
MASTER_PUBLIC_KEY = "3081a7301006072a8648ce3d020106052b810400270381920004073beff7002b6a9fc2824a3b1bbb1c4fc32546" \
"261e3ef7537874560346c5fdc0c17fe654f67d23b08cbb44141879f79a7a4c8deddf9beb4fbc7a0f02ee1586cc" \
"ebedb623eeef51710108d702f9250361c071482e83c0a4a86c8f45a0b13a19ef83eacb6267b4bfccf220ae5f6d" \
"1db7125ea1d10da3744b65679828f23376e28b76ab33132b7fa984a77f159dba7351a7"

master_peer = Peer(MASTER_PUBLIC_KEY.decode('hex'))

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def timestamp(self):

class ChannelHealthPayload(Payload):
"""
Payload for a channel popularity message in the popular community.
Payload for a channel popularity message in the popularity community.
"""

format_list = ['varlenI', 'I', 'I', 'I', 'I']
Expand Down
Loading

0 comments on commit bc19910

Please sign in to comment.