Skip to content

Commit

Permalink
Merge pull request #1269 from egbertbouman/leave_swarm
Browse files Browse the repository at this point in the history
Updated hidden services to stop removing data circuits
  • Loading branch information
egbertbouman committed Jan 29, 2024
2 parents 1e68c0a + 3aaa876 commit 44c12fc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
5 changes: 2 additions & 3 deletions ipv8/messaging/anonymization/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def do_circuits(self) -> None:
self.logger.info("Want %d data circuits of length %d", num_to_build, circuit_length)
for _ in range(num_to_build):
if not self.create_circuit(circuit_length):
self.logger.info("circuit creation of %d circuits failed, no need to continue", num_to_build)
self.logger.info("Circuit creation of %d circuits failed, no need to continue", num_to_build)
break
self.do_remove()

Expand All @@ -271,8 +271,7 @@ def build_tunnels(self, hops: int) -> None:
The number of circuits created for this hop count is dictated by the ``max_circuits`` setting.
"""
if hops > 0:
self.circuits_needed[hops] = max(self.settings.max_circuits,
min(self.settings.max_circuits, self.circuits_needed.get(hops, 0) + 1))
self.circuits_needed[hops] = self.settings.max_circuits
self.do_circuits()

def tunnels_ready(self, hops: int) -> float:
Expand Down
6 changes: 1 addition & 5 deletions ipv8/messaging/anonymization/hidden_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,8 @@ def leave_swarm(self, info_hash: bytes) -> None:
CIRCUIT_TYPE_RP_DOWNLOADER]:
_ = self.remove_circuit(circuit.circuit_id, 'leaving hidden swarm', destroy=DESTROY_REASON_UNNEEDED)
# Remove swarm and callback
swarm = self.swarms.pop(info_hash, None)
self.swarms.pop(info_hash, None)
self.e2e_callbacks.pop(info_hash, None)
# If there are no other swarms with the same hop count, remove the data circuits
if swarm and not [s for s in self.swarms.values() if s != swarm and s.hops == swarm.hops]:
for circuit in self.find_circuits(hops=swarm.hops, state=None):
_ = self.remove_circuit(circuit.circuit_id, 'not needed', destroy=DESTROY_REASON_UNNEEDED)

async def estimate_swarm_size(self, info_hash: bytes, hops: int = 1, max_requests: int = 10) -> int:
"""
Expand Down
2 changes: 0 additions & 2 deletions ipv8/test/messaging/anonymization/test_hiddenservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ....messaging.anonymization.hidden_services import HiddenTunnelCommunity, HiddenTunnelSettings
from ....messaging.anonymization.payload import TestRequestPayload
from ....messaging.anonymization.tunnel import (
CIRCUIT_TYPE_DATA,
CIRCUIT_TYPE_IP_SEEDER,
PEER_FLAG_EXIT_BT,
PEER_FLAG_RELAY,
Expand Down Expand Up @@ -218,7 +217,6 @@ async def test_dht_lookup_with_counterparty(self) -> None:
await sleep(.1)
self.assertFalse(self.overlay(0).find_circuits(ctype=CIRCUIT_TYPE_IP_SEEDER))
self.assertFalse(self.overlay(0).find_circuits(ctype=CIRCUIT_TYPE_RP_DOWNLOADER))
self.assertFalse(self.overlay(0).find_circuits(ctype=CIRCUIT_TYPE_DATA))

async def test_dht_lookup_no_counterparty(self) -> None:
"""
Expand Down

0 comments on commit 44c12fc

Please sign in to comment.