Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor structure of tribler communities #6175

Merged
merged 2 commits into from Jun 23, 2021

Conversation

drew2a
Copy link
Collaborator

@drew2a drew2a commented Jun 22, 2021

This PR contains refactoring of tribler's communities structure.

An attempt has been made to bring the structure to the following:

modulesmy_communitytests
  |test*.pycommunity.pysettings.py

The core idea is to make communities more unified (by bringing them to a uniform structure) and more autonomous (by combining implementation with its settings definition)

Implementation

For each Tribler community settings field has been added by inheriting them from:

class TriblerCommunity(Community):
    def __init__(self, *args, settings: TriblerConfigSection = None, **kwargs):
        super().__init__(*args, **kwargs)
        self.settings = settings

The settings set in ipv8_module_catalog.py for a normal Tribler's run:

class MyCommunityLauncher(IPv8CommunityLauncher):
    def get_kwargs(self, session):
        return {
            'settings': session.config.my_community,
        }

For tests it can be done by passing a settings object into community constructor:

mock_ipv8.overlay.my_community = MyCommunity(settings=BandwidthAccountingSettings())

Problems

I've encountered problems during refactoring the following entities:

  1. TunnelCommunity
  2. MetadataStore

TunnelCommunity

Tribler's TunnelCommunity highly intertwined with Ipv8's TunnelCommunity and looks like hi-level "hack" or "patch" (I guess this is the result of an epic Dispersy refactoring).
Therefore it is hard to control and modify, for example, Community settings.

This PR leaves TunnelSettings as is, adding only the following logic in TriblerTunnelCommunityLauncher:

class TriblerTunnelCommunityLauncher(IPv8CommunityLauncher):
    def get_kwargs(self, session):
        from ipv8.messaging.anonymization.community import TunnelSettings

        settings = TunnelSettings()
        settings.min_circuits = session.config.tunnel_community.min_circuits
        settings.max_circuits = session.config.tunnel_community.max_circuits

MetadataStore

MetadataStore is a very special place in Tribler which is unlike anything else. It uses a special structure and special inner logic.
This unit contains two communities, ORM bindings, and REST-API.

It contains also RemoteQueryCommunity which is the base class for PopularityCommunity and GigaChannelCommunity. These dependencies make it difficult to isolate atomic settings for each community.

This PR leaves MetadataStore almost as-is, leaving refactoring to the author, except for:

  1. RemoteQueryCommunity extracted from MetadataStore and placed to modulesalong with the rest communities.
  2. Has been added rqc_settings field to RemoteQueryCommunity class and all its successors.
class RemoteQueryCommunity(TriblerCommunity, EVAProtocolMixin):
    def __init__(self, my_peer, endpoint, network, metadata_store, rqc_settings: RemoteQueryCommunitySettings = None,
                 **kwargs):
        super().__init__(my_peer, endpoint, network=network, **kwargs)
        self.rqc_settings = rqc_settings or RemoteQueryCommunitySettings()

Launcher:

class PopularityCommunityLauncher(IPv8CommunityLauncher):
    def get_kwargs(self, session):
        return {
            'settings': session.config.popularity_community,
            'rqc_settings': session.config.remote_query_community,
        }

@drew2a drew2a force-pushed the refactoring/community_settings branch from 5b577f9 to 1244525 Compare June 22, 2021 13:32
@sonarcloud
Copy link

sonarcloud bot commented Jun 22, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@drew2a drew2a changed the title WIP Refactor tribler communities structure Refactor structure of tribler communities Jun 22, 2021
@drew2a drew2a marked this pull request as ready for review June 22, 2021 16:49
@synctext
Copy link
Member

Good initiative!
You are merging and unifying the coding practices of several Tribler communities (e.g. Lab members). That's never going to be easy 👏

@ichorid
Copy link
Contributor

ichorid commented Jun 23, 2021

This PR leaves MetadataStore almost as-is, leaving refactoring to the author ...

“The proof is left up to the student” (c) Richard Feynman 🤣

@drew2a drew2a merged commit e095beb into Tribler:main Jun 23, 2021
@drew2a drew2a deleted the refactoring/community_settings branch June 23, 2021 14:45
@egbertbouman
Copy link
Member

Looks like we just commited some test artifacts (0.db and 1.db) to our main branch...

@drew2a
Copy link
Collaborator Author

drew2a commented Jun 23, 2021

@egbertbouman yes, you are right. Will fix it soon.
Related to #6158

@drew2a drew2a mentioned this pull request Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants