mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 06:34:19 +01:00
plugin - Some fixes and renaming
This commit is contained in:
@@ -62,15 +62,15 @@ def send_appointment(tower_id, tower, appointment_dict, signature):
|
|||||||
add_appointment_endpoint = f"{tower.get('netaddr')}/add_appointment"
|
add_appointment_endpoint = f"{tower.get('netaddr')}/add_appointment"
|
||||||
response = process_post_response(post_request(data, add_appointment_endpoint, tower_id))
|
response = process_post_response(post_request(data, add_appointment_endpoint, tower_id))
|
||||||
|
|
||||||
signature = response.get("signature")
|
tower_signature = response.get("signature")
|
||||||
# Check that the server signed the appointment as it should.
|
# Check that the server signed the appointment as it should.
|
||||||
if not signature:
|
if not tower_signature:
|
||||||
raise SignatureError("The response does not contain the signature of the appointment", signature=None)
|
raise SignatureError("The response does not contain the signature of the appointment", signature=None)
|
||||||
|
|
||||||
rpk = Cryptographer.recover_pk(Appointment.from_dict(appointment_dict).serialize(), signature)
|
rpk = Cryptographer.recover_pk(Appointment.from_dict(appointment_dict).serialize(), tower_signature)
|
||||||
if tower_id != Cryptographer.get_compressed_pk(rpk):
|
if tower_id != Cryptographer.get_compressed_pk(rpk):
|
||||||
raise SignatureError(
|
raise SignatureError(
|
||||||
"The returned appointment's signature is invalid", tower_id=tower_id, rpk=rpk, signature=signature
|
"The returned appointment's signature is invalid", tower_id=tower_id, rpk=rpk, signature=tower_signature
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class TowerInfo:
|
|||||||
pending_appointments=None,
|
pending_appointments=None,
|
||||||
invalid_appointments=None,
|
invalid_appointments=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
self.netaddr = netaddr
|
self.netaddr = netaddr
|
||||||
self.available_slots = available_slots
|
self.available_slots = available_slots
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class WTClient:
|
|||||||
else:
|
else:
|
||||||
tower_info.pending_appointments.remove(list(data))
|
tower_info.pending_appointments.remove(list(data))
|
||||||
if "invalid_appointment" in tower_update:
|
if "invalid_appointment" in tower_update:
|
||||||
tower_info.pending_appointments.append(list(tower_update.get("invalid_appointment")))
|
tower_info.invalid_appointments.append(list(tower_update.get("invalid_appointment")))
|
||||||
|
|
||||||
self.towers[tower_id] = tower_info.get_summary()
|
self.towers[tower_id] = tower_info.get_summary()
|
||||||
self.db_manager.store_tower_record(tower_id, tower_info)
|
self.db_manager.store_tower_record(tower_id, tower_info)
|
||||||
@@ -219,20 +219,25 @@ def get_tower_info(plugin, tower_id):
|
|||||||
|
|
||||||
@plugin.method("retrytower", desc="Retry to send pending appointment to an unreachable tower.")
|
@plugin.method("retrytower", desc="Retry to send pending appointment to an unreachable tower.")
|
||||||
def retry_tower(plugin, tower_id):
|
def retry_tower(plugin, tower_id):
|
||||||
|
response = None
|
||||||
|
plugin.wt_client.lock.acquire()
|
||||||
tower = plugin.wt_client.towers.get(tower_id)
|
tower = plugin.wt_client.towers.get(tower_id)
|
||||||
|
|
||||||
if not tower:
|
if not tower:
|
||||||
return {"error": f"{tower_id} is not a registered tower"}
|
response = {"error": f"{tower_id} is not a registered tower"}
|
||||||
if tower.get("status") != "unreachable":
|
if tower.get("status") not in ["unreachable", "subscription error"]:
|
||||||
return {"error": f"{tower_id} is not unreachable"}
|
response = {"error": f"{tower_id} is not unreachable. {tower.get('status')}"}
|
||||||
if not tower.get("pending_appointments"):
|
if not tower.get("pending_appointments"):
|
||||||
return {"error": f"{tower_id} does not have pending appointments"}
|
response = {"error": f"{tower_id} does not have pending appointments"}
|
||||||
|
|
||||||
message = f"Retrying tower {tower_id}"
|
if not response:
|
||||||
plugin.log(message)
|
response = f"Retrying tower {tower_id}"
|
||||||
plugin.wt_client.retrier.temp_unreachable_towers.put(tower_id)
|
plugin.log(response)
|
||||||
|
plugin.wt_client.towers[tower_id]["status"] = "temporarily unreachable"
|
||||||
|
plugin.wt_client.retrier.temp_unreachable_towers.put(tower_id)
|
||||||
|
|
||||||
return message
|
plugin.wt_client.lock.release()
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@plugin.hook("commitment_revocation")
|
@plugin.hook("commitment_revocation")
|
||||||
@@ -260,8 +265,10 @@ def on_commitment_revocation(plugin, **kwargs):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if tower.get("status") == "reachable":
|
if tower.get("status") == "reachable":
|
||||||
signature, available_slots = add_appointment(plugin, tower_id, tower, appointment.to_dict(), signature)
|
tower_signature, available_slots = add_appointment(
|
||||||
tower_update["appointment"] = (appointment.locator, signature)
|
plugin, tower_id, tower, appointment.to_dict(), signature
|
||||||
|
)
|
||||||
|
tower_update["appointment"] = (appointment.locator, tower_signature)
|
||||||
tower_update["available_slots"] = available_slots
|
tower_update["available_slots"] = available_slots
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user