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

Extract loaders from ipv8_module_catalog.py #6182

Merged
merged 5 commits into from
Jun 30, 2021

Conversation

drew2a
Copy link
Contributor

@drew2a drew2a commented Jun 24, 2021

One step closer to the atomic community: introduction of launcher.py

I've extracted IPv8CommunityLauncher for each Tribler's community from ipv8_module_catalog.py and put them into launcher.py next to corresponding communities.

image

Preconditions

Preconditions have been separated from Launcher definition to Loader implementation:

community_loader.py

def create_default_loader(config: TriblerConfig, tunnel_testnet: bool = False,
                          bandwidth_testnet: bool = False, chant_testnet: bool = False):
    loader = IPv8CommunityLoader()

    loader.set_launcher(IPv8DiscoveryCommunityLauncher())
    loader.set_launcher(DHTCommunityLauncher())

    if bandwidth_testnet:
        from tribler_core.modules.bandwidth_accounting.launcher import BandwidthTestnetCommunityLauncher
        loader.set_launcher(BandwidthTestnetCommunityLauncher())
    else:
        from tribler_core.modules.bandwidth_accounting.launcher import BandwidthCommunityLauncher
        loader.set_launcher(BandwidthCommunityLauncher())
   ...

This allowed the use of top imports inside each loader (which should lead to easier navigation and more convenient work inside IDE).

launcher.py

from ipv8.loader import overlay, set_in_session, walk_strategy
from ipv8.peerdiscovery.discovery import RandomWalk
from tribler_core.modules.community_loader import INFINITE, TriblerCommunityLauncher

from tribler_core.modules.metadata_store.community.sync_strategy import RemovePeers
from tribler_core.modules.popularity.community import PopularityCommunity


@set_in_session('popularity_community')
@overlay(PopularityCommunity)
@walk_strategy(RandomWalk, target_peers=30)
@walk_strategy(RemovePeers, target_peers=INFINITE)
class PopularityCommunityLauncher(TriblerCommunityLauncher):
    def get_kwargs(self, session):
        return {
            'settings': session.config.popularity_community,
            'rqc_settings': session.config.remote_query_community,

            'metadata_store': session.mds,
            'torrent_checker': session.torrent_checker,
        }

Community loader

Community loader can be passed to Session constructor now:

session.py

    def __init__(self, config: TriblerConfig, core_test_mode: bool = False,
                 community_loader: IPv8CommunityLoader = None):
        if not community_loader:
            community_loader = create_default_loader(config)

Therefore you don't need to cheat session to specify your own set of community launchers:

run_bandwith_crawler.py

async def start_crawler(tribler_config):
    # We use our own community loader
    loader = IPv8CommunityLoader()
    loader.set_launcher(BandwidthCommunityCrawlerLauncher())
    session = Session(tribler_config, community_loader=loader)

@drew2a drew2a force-pushed the refactoring/module_catalog branch from be593b8 to 50f1205 Compare June 25, 2021 14:54
@drew2a drew2a changed the title WIP Extract loaders from ipv8_module_catalog.py Extract loaders from ipv8_module_catalog.py Jun 25, 2021
@drew2a drew2a added this to the 7.11.0 July milestone Jun 25, 2021
@drew2a drew2a self-assigned this Jun 25, 2021
@drew2a drew2a force-pushed the refactoring/module_catalog branch from 100a7ec to ada438d Compare June 25, 2021 15:51
@drew2a drew2a marked this pull request as ready for review June 25, 2021 16:10
@drew2a drew2a requested a review from qstokkink June 25, 2021 16:36
Copy link
Contributor

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that moving module (/community) definitions to their own files is a good idea. However, I observe that this PR creates more problems than it solves.

I'd strongly suggest closing this PR and drafting a more formal design in an issue first.

src/tribler-core/tribler_core/modules/community_loader.py Outdated Show resolved Hide resolved
src/tribler-core/tribler_core/modules/community_loader.py Outdated Show resolved Hide resolved
src/tribler-core/tribler_core/session.py Outdated Show resolved Hide resolved
src/tribler-core/tribler_core/session.py Show resolved Hide resolved
@ichorid
Copy link
Contributor

ichorid commented Jun 26, 2021

@qstokkink , I hoped to first discuss it with @drew2a , but you guys discussing the problem of modularisation here...
Dependency Injector framework is just what you're looking for. I propose converting the IPv8 modules catalog to it first, then gradually convert all of the Tribler code to it, finishing with the Session itself.

@qstokkink
Copy link
Contributor

@ichorid I agree that this warrants more in-depth discussion and a formal design. This is why I called to move this PR to an issue first, instead of turning this PR into a long discussion.

I have not checked out the Dependency Injector framework. However, from my experience with Python plug-ins, we need to make doubly-sure that whatever we use (e.g., Dependency Injector) is compatible with a frozen environment (as created by PyInstaller). Ideally, we should have a list of all plug-in frameworks and weigh the pro's and con's. We'll be stuck with this for years probably, so this is not something we should decide on a whim.

Copy link
Contributor

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the shift in issue #1, dropping plugins, none of the points I raised matter anymore.

Copy link
Contributor

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I was too fast. This one still holds: https://github.com/Tribler/tribler/pull/6182/files#r659146652
I've set the comments that were related to plug-ins to "resolved".

@drew2a drew2a force-pushed the refactoring/module_catalog branch from 0930248 to 5e99b28 Compare June 30, 2021 11:05
qstokkink
qstokkink previously approved these changes Jun 30, 2021
Copy link
Contributor

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 Thanks for sticking with us through an entire lab vision revision.

Some future work notes:

@drew2a
Copy link
Contributor Author

drew2a commented Jun 30, 2021

@qstokkink 🙏

I may need to do another PR with Dependency Injection as a result of today's meeting, which will remove the use of launcher/loader from Tribler.

After that, the Gumby can be fixed.

@ichorid
Copy link
Contributor

ichorid commented Jun 30, 2021

Continuation of the DependencyInjector discussion: #4953

@sonarcloud
Copy link

sonarcloud bot commented Jun 30, 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
No Duplication information No Duplication information

@drew2a drew2a merged commit b6ad525 into Tribler:main Jun 30, 2021
@drew2a drew2a deleted the refactoring/module_catalog branch June 30, 2021 14:21
@drew2a drew2a restored the refactoring/module_catalog branch June 30, 2021 14:23
@drew2a drew2a deleted the refactoring/module_catalog branch June 30, 2021 14:23
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

3 participants