diff --git a/capport-example.yaml b/capport-example.yaml index b68c715..1f50aa6 100644 --- a/capport-example.yaml +++ b/capport-example.yaml @@ -11,3 +11,4 @@ server-names: - ... api-port: 8000 controller-port: 5000 +database-file: capport.state diff --git a/src/capport/comm/hub.py b/src/capport/comm/hub.py index 9a5cbc5..902beda 100644 --- a/src/capport/comm/hub.py +++ b/src/capport/comm/hub.py @@ -299,11 +299,11 @@ class Hub: self._hostname = socket.getfqdn() self._app = app self._is_controller = is_controller - state_filename: typing.Optional[str] + state_filename: str if is_controller: - state_filename = 'capport.state' + state_filename = config.database_file else: - state_filename = None + state_filename = '' self.database = capport.database.Database(state_filename=state_filename) self._anon_context = ssl.SSLContext() # python ssl doesn't support setting tls1.3 ciphers yet, so make sure we stay on 1.2 for now to enable anon diff --git a/src/capport/config.py b/src/capport/config.py index 03e2730..c0b4de2 100644 --- a/src/capport/config.py +++ b/src/capport/config.py @@ -23,6 +23,7 @@ class Config: session_timeout: int # in seconds api_port: int controller_port: int + database_file: str # empty str: disable database debug: bool @staticmethod @@ -58,6 +59,7 @@ class Config: session_timeout=data.pop('session-timeout', 3600), api_port=data.pop('api-port', 8000), controller_port=data.pop('controller-port', 5000), + database_file=str(data.pop('database-file', 'capport.state')), debug=data.pop('debug', False) ) if data: diff --git a/src/capport/database.py b/src/capport/database.py index 3907dbd..be65105 100644 --- a/src/capport/database.py +++ b/src/capport/database.py @@ -139,7 +139,7 @@ class NotReadyYet(Exception): class Database: - def __init__(self, state_filename: typing.Optional[str] = None): + def __init__(self, state_filename: str = ""): self._macs: dict[cptypes.MacAddress, MacEntry] = {} self._state_filename = state_filename self._changed_since_last_cleanup = False