-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated IPv8 while keeping Community kwargs (#7645)
- Loading branch information
Showing
20 changed files
with
147 additions
and
119 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
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
4 changes: 2 additions & 2 deletions
4
src/tribler/core/components/database/db/tests/test_tribler_database.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
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
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,35 @@ | ||
import inspect | ||
|
||
from ipv8.test.base import TestBase | ||
from ipv8.test.mocking.ipv8 import MockIPv8 | ||
|
||
|
||
def backport_to_settings_class(overlay_class, kwargs): | ||
signature = inspect.signature(overlay_class.__init__) | ||
defaults = {k: v.default for k, v in signature.parameters.items() | ||
if v.default is not inspect.Parameter.empty} | ||
defaults.update(kwargs) | ||
return overlay_class.settings_class(**defaults) | ||
|
||
|
||
class TriblerMockIPv8(MockIPv8): | ||
|
||
def __init__(self, crypto_curve_or_peer, overlay_class, create_dht = False, enable_statistics = False, | ||
**kwargs): | ||
community_settings = backport_to_settings_class(overlay_class, kwargs) | ||
|
||
class ProxyOverlay(overlay_class): | ||
|
||
def __init__(self, settings): | ||
super().__init__(**settings.__dict__) | ||
|
||
super().__init__(crypto_curve_or_peer, ProxyOverlay, community_settings, create_dht, enable_statistics) | ||
|
||
|
||
class TriblerTestBase(TestBase): | ||
|
||
def create_node(self, *args, **kwargs): | ||
create_dht = args[1] if len(args) > 1 else False | ||
enable_statistics = args[2] if len(args) > 2 else False | ||
return TriblerMockIPv8("low", self.overlay_class, create_dht=create_dht, | ||
enable_statistics=enable_statistics, **kwargs) |
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
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
from ipv8.community import Community | ||
from ipv8.community import Community, DEFAULT_MAX_PEERS | ||
|
||
from tribler.core.config.tribler_config_section import TriblerConfigSection | ||
|
||
def args_kwargs_to_community_settings(settings_class, args, kwargs): | ||
return settings_class(my_peer=args[0] if len(args) > 0 else kwargs.pop("my_peer"), | ||
endpoint=args[1] if len(args) > 1 else kwargs.pop("endpoint"), | ||
network=args[2] if len(args) > 2 else kwargs.pop("network"), | ||
max_peers=args[4] if len(args) > 3 else kwargs.pop("max_peers", DEFAULT_MAX_PEERS), | ||
anonymize=args[5] if len(args) > 4 else kwargs.pop("anonymize", True), | ||
**kwargs) | ||
|
||
|
||
class TriblerCommunity(Community): | ||
"""Base class for Tribler communities. | ||
""" | ||
|
||
def __init__(self, *args, settings: TriblerConfigSection = None, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
community_settings = args_kwargs_to_community_settings(self.settings_class, args, kwargs) | ||
super().__init__(community_settings) | ||
self.settings = settings | ||
self.logger.info(f'Init. Settings: {settings}.') |
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
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
Oops, something went wrong.