-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
239 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/tribler-core/tribler_core/modules/community_di_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from dataclasses import dataclass | ||
|
||
from ipv8.peerdiscovery.discovery import RandomWalk | ||
|
||
DEFAULT_TARGET_PEERS = 20 | ||
INFINITE_TARGET_PEERS = -1 | ||
|
||
|
||
@dataclass | ||
class StrategyFactory: | ||
create_class: type = RandomWalk | ||
target_peers: int = 20 | ||
|
||
|
||
class CommunityDIMixin: | ||
"""Mixin for Dependency Injection | ||
""" | ||
|
||
def init_community_di_mixin(self, strategies=None): | ||
self.strategies = strategies | ||
|
||
def fill_mediator(self, mediator): | ||
... |
135 changes: 0 additions & 135 deletions
135
src/tribler-core/tribler_core/modules/community_loader.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from ipv8.dht.discovery import DHTDiscoveryCommunity | ||
from ipv8.peerdiscovery.churn import RandomChurn | ||
from ipv8.peerdiscovery.community import PeriodicSimilarity | ||
from ipv8.peerdiscovery.discovery import RandomWalk | ||
|
||
from tribler_core.modules.community_di_mixin import ( | ||
CommunityDIMixin, | ||
DEFAULT_TARGET_PEERS, | ||
INFINITE_TARGET_PEERS, | ||
StrategyFactory, | ||
) | ||
from tribler_core.session import Mediator | ||
|
||
|
||
class DHTDiscoveryStrategies(CommunityDIMixin, DHTDiscoveryCommunity): | ||
def __init__(self, *args, mediator=None, **kwargs): | ||
kwargs['max_peers'] = 60 | ||
super().__init__(*args, **kwargs) | ||
|
||
self.init_community_di_mixin(strategies=[ | ||
StrategyFactory(create_class=RandomChurn, target_peers=INFINITE_TARGET_PEERS), | ||
StrategyFactory(create_class=PeriodicSimilarity, target_peers=INFINITE_TARGET_PEERS), | ||
StrategyFactory(create_class=RandomWalk, target_peers=DEFAULT_TARGET_PEERS), | ||
]) | ||
|
||
def fill_mediator(self, mediator: Mediator): | ||
super().fill_mediator(mediator) | ||
|
||
mediator.dictionary['dht_community'] = self |
22 changes: 22 additions & 0 deletions
22
src/tribler-core/tribler_core/modules/discovery/community.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from ipv8.peerdiscovery.churn import RandomChurn | ||
from ipv8.peerdiscovery.community import DiscoveryCommunity, PeriodicSimilarity | ||
from ipv8.peerdiscovery.discovery import RandomWalk | ||
|
||
from tribler_core.modules.community_di_mixin import ( | ||
CommunityDIMixin, | ||
DEFAULT_TARGET_PEERS, | ||
INFINITE_TARGET_PEERS, | ||
StrategyFactory, | ||
) | ||
|
||
|
||
class TriblerDiscoveryStrategies(CommunityDIMixin, DiscoveryCommunity): | ||
def __init__(self, *args, mediator=None, **kwargs): | ||
kwargs['max_peers'] = 100 | ||
super().__init__(*args, **kwargs) | ||
|
||
self.init_community_di_mixin(strategies=[ | ||
StrategyFactory(create_class=RandomChurn, target_peers=INFINITE_TARGET_PEERS), | ||
StrategyFactory(create_class=PeriodicSimilarity, target_peers=INFINITE_TARGET_PEERS), | ||
StrategyFactory(create_class=RandomWalk, target_peers=DEFAULT_TARGET_PEERS), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.