Skip to content

Commit

Permalink
Merge pull request #7504 from kozlovsky/fix/get_circuit_slots
Browse files Browse the repository at this point in the history
The `get_circuit_slots` method of `DebugEndpoint` should handle the case when `tunnel_community` is `None`
  • Loading branch information
kozlovsky authored Jun 26, 2023
2 parents b554579 + 16f8f32 commit 4a4b04d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/tribler/core/components/restapi/rest/debug_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
import logging
import sys
from io import StringIO
from typing import Optional

import psutil
from aiohttp import web
from aiohttp.abc import BaseRequest
from aiohttp_apispec import docs
from ipv8.REST.schema import schema
from ipv8.messaging.anonymization.community import TunnelCommunity
from marshmallow.fields import Boolean, Float, Integer, String

from tribler.core.components.reporter.exception_handler import CoreExceptionHandler
from tribler.core.components.resource_monitor.implementation.base import ResourceMonitor
from tribler.core.components.restapi.rest.rest_endpoint import RESTEndpoint, RESTResponse
from tribler.core.components.tunnel.community.tunnel_community import TriblerTunnelCommunity
from tribler.core.exceptions import TriblerCoreTestException
from tribler.core.utilities.instrumentation import WatchDog
from tribler.core.utilities.osutils import get_root_state_directory
Expand Down Expand Up @@ -46,9 +47,9 @@ class DebugEndpoint(RESTEndpoint):
def __init__(self,
state_dir: Path,
log_dir: Path,
tunnel_community: TunnelCommunity = None,
resource_monitor: ResourceMonitor = None,
core_exception_handler: CoreExceptionHandler = None):
tunnel_community: Optional[TriblerTunnelCommunity] = None,
resource_monitor: Optional[ResourceMonitor] = None,
core_exception_handler: Optional[CoreExceptionHandler] = None):
super().__init__()
self.logger = logging.getLogger(self.__class__.__name__)
self.state_dir = state_dir
Expand Down Expand Up @@ -88,10 +89,12 @@ def setup_routes(self):
}
)
async def get_circuit_slots(self, request):
random_slots = self.tunnel_community.random_slots if self.tunnel_community else []
competing_slots = self.tunnel_community.competing_slots if self.tunnel_community else []
return RESTResponse({
"slots": {
"random": self.tunnel_community.random_slots,
"competing": self.tunnel_community.competing_slots
"random": random_slots,
"competing": competing_slots
}
})

Expand Down

0 comments on commit 4a4b04d

Please sign in to comment.