mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-11 17:44:23 +01:00
Adds new gatekeeper tests
This commit is contained in:
@@ -27,6 +27,7 @@ class UserInfo:
|
||||
self.available_slots = available_slots
|
||||
self.subscription_expiry = subscription_expiry
|
||||
|
||||
# FIXME: this list is currently never wiped
|
||||
if not appointments:
|
||||
self.appointments = []
|
||||
else:
|
||||
@@ -139,17 +140,17 @@ class Gatekeeper:
|
||||
"""
|
||||
Updates (add/removes) slots from a user subscription.
|
||||
|
||||
Slots are removed if a new subscription is given, or an update is given with a new subscription bigger than the
|
||||
Slots are removed if a new appointment is given, or an update is given with an appointment bigger than the
|
||||
old one.
|
||||
|
||||
Slots are added if an update is given but the new appointment is smaller than the old one.
|
||||
|
||||
Args:
|
||||
user_id(:obj:`str`): the public key that identifies the user (33-bytes hex str).
|
||||
new_appointment (:obj:`ExtendedAppointment <teos.extended_appointment.ExtendedAppointment>`): the new
|
||||
appointment the user is requesting to add.
|
||||
old_appointment (:obj:`ExtendedAppointment <teos.extended_appointment.ExtendedAppointment>`): the old
|
||||
appointment the user wants to replace. Optional.
|
||||
new_appointment (:obj:`dict`): the summary of new appointment the user is requesting
|
||||
to add.
|
||||
old_appointment (:obj:`dict`): the summary old appointment the user wants to replace.
|
||||
Optional.
|
||||
|
||||
Returns:
|
||||
:obj:`int`: the number of remaining appointment slots.
|
||||
@@ -180,7 +181,7 @@ class Gatekeeper:
|
||||
|
||||
def get_expired_appointments(self, block_height):
|
||||
"""
|
||||
Gets a list of appointments that are expiring at a given block height.
|
||||
Gets a list of appointments that expire at a given block height.
|
||||
|
||||
Args:
|
||||
block_height: the block height that wants to be checked.
|
||||
|
||||
@@ -23,7 +23,7 @@ class Watcher:
|
||||
"""
|
||||
The :class:`Watcher` is in charge of watching for channel breaches for the appointments accepted by the tower.
|
||||
|
||||
The :class:`Watcher` keeps track of the accepted appointments in ``appointments`` and, for new received block,
|
||||
The :class:`Watcher` keeps track of the accepted appointments in ``appointments`` and, for new received blocks,
|
||||
checks if any breach has happened by comparing the txids with the appointment locators. If a breach is seen, the
|
||||
``encrypted_blob`` of the corresponding appointment is decrypted and the data is passed to the
|
||||
:obj:`Responder <teos.responder.Responder>`.
|
||||
@@ -115,7 +115,7 @@ class Watcher:
|
||||
:obj:`AppointmentLimitReached`: If the tower cannot hold more appointments (cap reached).
|
||||
:obj:`AuthenticationFailure <teos.gatekeeper.AuthenticationFailure>`: If the user cannot be authenticated.
|
||||
:obj:`NotEnoughSlots <teos.gatekeeper.NotEnoughSlots>`: If the user does not have enough available slots,
|
||||
so the appointment is rejected
|
||||
so the appointment is rejected.
|
||||
"""
|
||||
|
||||
if len(self.appointments) >= self.max_appointments:
|
||||
@@ -129,6 +129,7 @@ class Watcher:
|
||||
# If an appointment is requested by the user the uuid can be recomputed and queried straightaway (no maps).
|
||||
uuid = hash_160("{}{}".format(appointment.locator, user_id))
|
||||
|
||||
# The third argument is the previous version of the same appointment (optional, returns None if missing)
|
||||
available_slots = self.gatekeeper.update_available_slots(
|
||||
user_id, appointment.get_summary(), self.appointments.get(uuid)
|
||||
)
|
||||
@@ -140,6 +141,7 @@ class Watcher:
|
||||
if uuid not in self.locator_uuid_map[appointment.locator]:
|
||||
self.locator_uuid_map[appointment.locator].append(uuid)
|
||||
else:
|
||||
# Otherwise two users have sent an appointment with the same locator, so we need to store both.
|
||||
self.locator_uuid_map[appointment.locator] = [uuid]
|
||||
|
||||
self.db_manager.store_watcher_appointment(uuid, appointment.to_dict())
|
||||
@@ -191,7 +193,7 @@ class Watcher:
|
||||
expired_appointments, self.appointments, self.locator_uuid_map, self.db_manager
|
||||
)
|
||||
|
||||
valid_breaches, invalid_breaches = self.filter_valid_breaches(self.get_breaches(txids))
|
||||
valid_breaches, invalid_breaches = self.filter_breaches(self.get_breaches(txids))
|
||||
|
||||
triggered_flags = []
|
||||
appointments_to_delete = []
|
||||
@@ -264,9 +266,9 @@ class Watcher:
|
||||
|
||||
return breaches
|
||||
|
||||
def filter_valid_breaches(self, breaches):
|
||||
def filter_breaches(self, breaches):
|
||||
"""
|
||||
Filters what of the found breaches contain valid transaction data.
|
||||
Filters the valid from the invalid channel breaches.
|
||||
|
||||
The :obj:`Watcher` cannot if a given ``encrypted_blob`` contains a valid transaction until a breach if seen.
|
||||
Blobs that contain arbitrary data are dropped and not sent to the :obj:`Responder <teos.responder.Responder>`.
|
||||
|
||||
Reference in New Issue
Block a user