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

Fixes #6250, fixes #6251: each community should use a separate bootstrapper #6252

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ async def run(self):
database=database)
ipv8.strategies.append((RandomWalk(community), 20))

if ipv8_component.bootstrapper:
community.bootstrappers.append(ipv8_component.bootstrapper)
community.bootstrappers.append(ipv8_component.make_bootstrapper())

ipv8.overlays.append(community)
self.community = community
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ async def run(self):
ipv8.strategies.append((RandomWalk(community), 30))
ipv8.strategies.append((RemovePeers(community), INFINITE))

if ipv8_component.bootstrapper:
community.bootstrappers.append(ipv8_component.bootstrapper)
community.bootstrappers.append(ipv8_component.make_bootstrapper())

ipv8.overlays.append(community)

Expand Down
11 changes: 5 additions & 6 deletions src/tribler-core/tribler_core/components/implementation/ipv8.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ async def run(self):

rest_manager.get_endpoint('statistics').ipv8 = ipv8

self.bootstrapper = self.peer_discovery_community = self.dht_discovery_community = None
self.peer_discovery_community = self.dht_discovery_community = None
self.init_dht_discovery_community()
if not self.session.config.gui_test_mode:
self.init_bootstrapper()
self.init_peer_discovery_community()
else:
self.dht_discovery_community.routing_tables[UDPv4Address] = RoutingTable('\x00' * 20)
Expand All @@ -93,12 +92,12 @@ async def run(self):
if path in endpoints_to_init:
endpoint.initialize(ipv8)

def init_bootstrapper(self):
def make_bootstrapper(self) -> DispersyBootstrapper:
args = DISPERSY_BOOTSTRAPPER['init']
if bootstrap_override := self.session.config.ipv8.bootstrap_override:
address, port = bootstrap_override.split(':')
args = {'ip_addresses': [(address, int(port))], 'dns_addresses': []}
self.bootstrapper = DispersyBootstrapper(**args)
return DispersyBootstrapper(**args)

def init_peer_discovery_community(self):
ipv8 = self.ipv8
Expand All @@ -107,7 +106,7 @@ def init_peer_discovery_community(self):
ipv8.strategies.append((PeriodicSimilarity(community), INFINITE))
ipv8.strategies.append((RandomWalk(community), 20))
ipv8.overlays.append(community)
community.bootstrappers.append(self.bootstrapper)
community.bootstrappers.append(self.make_bootstrapper())
self.peer_discovery_community = community

def init_dht_discovery_community(self):
Expand All @@ -116,7 +115,7 @@ def init_dht_discovery_community(self):
ipv8.strategies.append((PingChurn(community), INFINITE))
ipv8.strategies.append((RandomWalk(community), 20))
ipv8.overlays.append(community)
community.bootstrappers.append(self.bootstrapper)
community.bootstrappers.append(self.make_bootstrapper())
self.dht_discovery_community = community

async def shutdown(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ async def run(self):
ipv8.strategies.append((RandomWalk(community), 30))
ipv8.strategies.append((RemovePeers(community), INFINITE))

if ipv8_component.bootstrapper:
community.bootstrappers.append(ipv8_component.bootstrapper)
community.bootstrappers.append(ipv8_component.make_bootstrapper())

ipv8.overlays.append(community)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ async def run(self):
ipv8.strategies.append((RemovePeers(community), INFINITE))
ipv8.overlays.append(community)

if ipv8_component.bootstrapper:
community.bootstrappers.append(ipv8_component.bootstrapper)
community.bootstrappers.append(ipv8_component.make_bootstrapper())

self.community = community

Expand Down
10 changes: 8 additions & 2 deletions src/tribler-core/tribler_core/components/interfaces/ipv8.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import abstractmethod
from typing import Optional
from unittest.mock import Mock

Expand All @@ -17,7 +18,6 @@ class Ipv8Component(Component):

ipv8: IPv8
peer: Peer
bootstrapper: Optional[DispersyBootstrapper]
peer_discovery_community: Optional[DiscoveryCommunity]
dht_discovery_community: Optional[DHTDiscoveryCommunity]

Expand All @@ -32,11 +32,17 @@ def make_implementation(cls, config: TriblerConfig, enable: bool):
return Ipv8ComponentImp(cls)
return Ipv8ComponentMock(cls)

@abstractmethod
def make_bootstrapper(self) -> DispersyBootstrapper:
pass


@testcomponent
class Ipv8ComponentMock(Ipv8Component):
ipv8 = Mock()
peer = Mock()
bootstrapper = Mock()
peer_discovery_community = Mock()
dht_discovery_community = Mock()

def make_bootstrapper(self):
return Mock()