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

Fixed cache leaks in Network #1221

Merged
merged 1 commit into from
Oct 13, 2023
Merged
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
6 changes: 6 additions & 0 deletions ipv8/peerdiscovery/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def discover_address(self,
intro_cache.append(address)
else:
self.reverse_intro_lookup[peer] = [address]
if len(self.reverse_intro_lookup) > self.reverse_intro_cache_size:
self.reverse_intro_lookup.popitem(False) # Pop the oldest cache entry

self.add_verified_peer(peer)

Expand All @@ -163,6 +165,8 @@ def discover_services(self, peer: Peer, services: Iterable) -> None:
service_cache.remove(peer)
service_cache.append(self.verified_by_public_key_bin.get(key_material, peer))
self.reverse_service_lookup[service] = service_cache
if len(self.reverse_service_lookup) > self.reverse_service_cache_size:
self.reverse_service_lookup.popitem(False) # Pop the oldest cache entry

def add_verified_peer(self, peer: Peer) -> None:
"""
Expand Down Expand Up @@ -287,6 +291,8 @@ def get_verified_by_address(self, address: Address) -> Peer | None:
else:
# Refresh the peer in the cache (by popping first, it is now on top of the stack again)
self.reverse_ip_lookup[address] = peer
if len(self.reverse_ip_lookup) > self.reverse_ip_cache_size:
self.reverse_ip_lookup.popitem(False) # Pop the oldest cache entry
return peer

def get_verified_by_public_key_bin(self, public_key_bin: PublicKeyMat) -> Peer | None:
Expand Down