コード例 #1
0
async def test_no_alive_torrents():
    torrents = {(random_infohash(), 0, randint(1, 10), None)
                for _ in range(10)}

    popular, rand = PopularityCommunity.select_torrents_to_gossip(torrents)
    assert not popular
    assert not rand
コード例 #2
0
async def test_select_torrents_to_gossip_small_list():
    torrents = [
        # infohash, seeders, leechers, last_check
        (b'0' * 20, 0, 0, None),
        (b'1' * 20, 1, 0, None),
        (b'1' * 20, 2, 0, None),
    ]

    popular, rand = PopularityCommunity.select_torrents_to_gossip(
        set(torrents))
    assert torrents[1] in popular
    assert torrents[2] in popular
    assert not rand
コード例 #3
0
async def test_select_torrents_to_gossip_big_list():
    # torrent structure is (infohash, seeders, leechers, last_check)
    dead_torrents = {(random_infohash(), 0, randint(1, 10), None)
                     for _ in range(10)}

    alive_torrents = {(random_infohash(), randint(1, 10), randint(1, 10), None)
                      for _ in range(10)}

    top5_popular_torrents = {
        (random_infohash(), randint(11, 100), randint(1, 10), None)
        for _ in range(PopularityCommunity.GOSSIP_POPULAR_TORRENT_COUNT)
    }

    all_torrents = dead_torrents | alive_torrents | top5_popular_torrents

    popular, rand = PopularityCommunity.select_torrents_to_gossip(all_torrents)
    assert len(popular) <= PopularityCommunity.GOSSIP_POPULAR_TORRENT_COUNT
    assert popular == top5_popular_torrents

    assert len(rand) <= PopularityCommunity.GOSSIP_RANDOM_TORRENT_COUNT
    assert rand <= alive_torrents
コード例 #4
0
 def gossip_torrents_health(self):
     PopularityCommunity.gossip_torrents_health(self)
コード例 #5
0
    def load_ipv8_overlays(self):
        if self.config.get_testnet():
            peer = Peer(self.trustchain_testnet_keypair)
        else:
            peer = Peer(self.trustchain_keypair)
        discovery_community = DiscoveryCommunity(peer, self.ipv8.endpoint,
                                                 self.ipv8.network)
        discovery_community.resolve_dns_bootstrap_addresses()
        self.ipv8.overlays.append(discovery_community)
        self.ipv8.strategies.append((RandomChurn(discovery_community), -1))
        self.ipv8.strategies.append(
            (PeriodicSimilarity(discovery_community), -1))
        self.ipv8.strategies.append((RandomWalk(discovery_community), 20))

        # TrustChain Community
        if self.config.get_trustchain_enabled():
            from ipv8.attestation.trustchain.community import TrustChainCommunity, \
                TrustChainTestnetCommunity

            community_cls = TrustChainTestnetCommunity if self.config.get_testnet(
            ) else TrustChainCommunity
            self.trustchain_community = community_cls(
                peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                working_directory=self.config.get_state_dir())
            self.ipv8.overlays.append(self.trustchain_community)
            self.ipv8.strategies.append(
                (EdgeWalk(self.trustchain_community), 20))

            tc_wallet = TrustchainWallet(self.trustchain_community)
            self.wallets[tc_wallet.get_identifier()] = tc_wallet

        # DHT Community
        if self.config.get_dht_enabled():
            from ipv8.dht.discovery import DHTDiscoveryCommunity

            self.dht_community = DHTDiscoveryCommunity(peer,
                                                       self.ipv8.endpoint,
                                                       self.ipv8.network)
            self.ipv8.overlays.append(self.dht_community)
            self.ipv8.strategies.append((RandomWalk(self.dht_community), 20))
            self.ipv8.strategies.append((PingChurn(self.dht_community), -1))

        # Tunnel Community
        if self.config.get_tunnel_community_enabled():
            from tribler_core.modules.tunnel.community.triblertunnel_community import TriblerTunnelCommunity,\
                                                                               TriblerTunnelTestnetCommunity
            from tribler_core.modules.tunnel.community.discovery import GoldenRatioStrategy
            community_cls = TriblerTunnelTestnetCommunity if self.config.get_testnet() else \
                TriblerTunnelCommunity

            random_slots = self.config.get_tunnel_community_random_slots()
            competing_slots = self.config.get_tunnel_community_competing_slots(
            )

            dht_provider = DHTCommunityProvider(self.dht_community,
                                                self.config.get_ipv8_port())
            settings = TunnelSettings()
            settings.min_circuits = 3
            settings.max_circuits = 10
            self.tunnel_community = community_cls(
                peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                tribler_session=self,
                dht_provider=dht_provider,
                ipv8=self.ipv8,
                bandwidth_wallet=self.wallets["MB"],
                random_slots=random_slots,
                competing_slots=competing_slots,
                settings=settings)
            self.ipv8.overlays.append(self.tunnel_community)
            self.ipv8.strategies.append(
                (RandomWalk(self.tunnel_community), 20))
            self.ipv8.strategies.append(
                (GoldenRatioStrategy(self.tunnel_community), -1))

        # Market Community
        if self.config.get_market_community_enabled(
        ) and self.config.get_dht_enabled():
            from anydex.core.community import MarketCommunity, MarketTestnetCommunity

            community_cls = MarketTestnetCommunity if self.config.get_testnet(
            ) else MarketCommunity
            self.market_community = community_cls(
                peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                trustchain=self.trustchain_community,
                dht=self.dht_community,
                wallets=self.wallets,
                working_directory=self.config.get_state_dir(),
                record_transactions=self.config.get_record_transactions())

            self.ipv8.overlays.append(self.market_community)

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

        # Popular Community
        if self.config.get_popularity_community_enabled():
            from tribler_core.modules.popularity.popularity_community import PopularityCommunity

            self.popularity_community = PopularityCommunity(
                peer,
                self.ipv8.endpoint,
                self.ipv8.network,
                metadata_store=self.mds,
                torrent_checker=self.torrent_checker)

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

        # Gigachannel Community
        if self.config.get_chant_enabled():
            from tribler_core.modules.metadata_store.community.gigachannel_community import GigaChannelCommunity, GigaChannelTestnetCommunity
            from tribler_core.modules.metadata_store.community.sync_strategy import SyncChannels

            community_cls = GigaChannelTestnetCommunity if self.config.get_testnet(
            ) else GigaChannelCommunity
            self.gigachannel_community = community_cls(peer,
                                                       self.ipv8.endpoint,
                                                       self.ipv8.network,
                                                       self.mds,
                                                       notifier=self.notifier)

            self.ipv8.overlays.append(self.gigachannel_community)

            self.ipv8.strategies.append(
                (RandomWalk(self.gigachannel_community), 20))
            self.ipv8.strategies.append(
                (SyncChannels(self.gigachannel_community), 20))

            # Gigachannel RemoteQuery Community
            from tribler_core.modules.metadata_store.community.remote_query_community \
                import RemoteQueryCommunity, RemoteQueryTestnetCommunity

            community_cls = RemoteQueryTestnetCommunity if self.config.get_testnet(
            ) else RemoteQueryCommunity
            self.remote_query_community = community_cls(peer,
                                                        self.ipv8.endpoint,
                                                        self.ipv8.network,
                                                        self.mds,
                                                        notifier=self.notifier)

            self.ipv8.overlays.append(self.remote_query_community)
            self.ipv8.strategies.append(
                (RandomWalk(self.remote_query_community), 50))