mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 06:34:19 +01:00
Moves slots added on register from gatekeeper to config
This commit is contained in:
@@ -2,8 +2,6 @@ import re
|
|||||||
|
|
||||||
from common.cryptographer import Cryptographer
|
from common.cryptographer import Cryptographer
|
||||||
|
|
||||||
SUBSCRIPTION_SLOTS = 1
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: UNITTEST
|
# TODO: UNITTEST
|
||||||
class NotEnoughSlots(ValueError):
|
class NotEnoughSlots(ValueError):
|
||||||
@@ -32,7 +30,8 @@ class Gatekeeper:
|
|||||||
registered_users (:obj:`dict`): a map of user_pk:appointment_slots.
|
registered_users (:obj:`dict`): a map of user_pk:appointment_slots.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, default_slots):
|
||||||
|
self.default_slots = default_slots
|
||||||
self.registered_users = {}
|
self.registered_users = {}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -57,16 +56,16 @@ class Gatekeeper:
|
|||||||
user_pk(:obj:`str`): the public key that identifies the user (33-bytes hex str).
|
user_pk(:obj:`str`): the public key that identifies the user (33-bytes hex str).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`int`: the number of avaiable slots in the user subscription.
|
:obj:`int`: the number of available slots in the user subscription.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.check_user_pk(user_pk):
|
if not self.check_user_pk(user_pk):
|
||||||
raise ValueError("provided public key does not match expected format (33-byte hex string)")
|
raise ValueError("provided public key does not match expected format (33-byte hex string)")
|
||||||
|
|
||||||
if user_pk not in self.registered_users:
|
if user_pk not in self.registered_users:
|
||||||
self.registered_users[user_pk] = SUBSCRIPTION_SLOTS
|
self.registered_users[user_pk] = self.default_slots
|
||||||
else:
|
else:
|
||||||
self.registered_users[user_pk] += SUBSCRIPTION_SLOTS
|
self.registered_users[user_pk] += self.default_slots
|
||||||
|
|
||||||
return self.registered_users[user_pk]
|
return self.registered_users[user_pk]
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,8 @@ def main(command_line_conf):
|
|||||||
# Fire the API and the ChainMonitor
|
# Fire the API and the ChainMonitor
|
||||||
# FIXME: 92-block-data-during-bootstrap-db
|
# FIXME: 92-block-data-during-bootstrap-db
|
||||||
chain_monitor.monitor_chain()
|
chain_monitor.monitor_chain()
|
||||||
API(Inspector(block_processor, config.get("MIN_TO_SELF_DELAY")), watcher, Gatekeeper()).start()
|
gatekeeper = Gatekeeper(config.get("DEFAULT_SLOTS"))
|
||||||
|
API(Inspector(block_processor, config.get("MIN_TO_SELF_DELAY")), watcher, gatekeeper).start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("An error occurred: {}. Shutting down".format(e))
|
logger.error("An error occurred: {}. Shutting down".format(e))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user