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

Fix stack trimming. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 4 additions & 2 deletions proxy/flow_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FlowStack:
"""FlowStack class."""

stack = {}
cookies = []

def __init__(self, max_size: int = 1024) -> None:
"""Construct a new FlowStack."""
Expand All @@ -85,6 +86,7 @@ def set_flow(
flow = Flow(
cookie, direction_allowed, transport_allowed, application_allowed, direction
)
self.cookies.append(cookie)
else:
if direction_allowed is not None:
flow.direction_allowed = direction_allowed
Expand All @@ -107,6 +109,6 @@ def get_flow(self, cookie: bytes) -> Flow:
return None

def trim_stack(self) -> None:
"""Drop the oldest flows to resize the stack to max size."""
"""Drop the oldest flow to resize the stack to max size."""
if len(self.stack) > self.max_size:
self.stack = self.stack[-self.max_size:]
self.stack.pop(self.cookies.pop(0))