- added a cancel function to the api

This commit is contained in:
land_and_air
2025-08-12 20:41:05 -05:00
parent 76f10804c3
commit 158f1d287f
3 changed files with 26 additions and 1 deletions

View File

@@ -107,6 +107,15 @@ class RNFSView(FlaskView):
else:
return 'Not Found'
@route('/cancel/<id>', methods=['GET'], endpoint='cancel')
def cancel_request(self, id):
"""cancel request to the network"""
ret = self.info.cancel_request(id)
if ret:
return 'success'
else:
return 'Not Found'
def start_server_thread(server_info):
t = Thread(target=start_server, args=[server_info], daemon=True)

View File

@@ -93,6 +93,15 @@ class RNSInterface:
}
return json.dumps(status)
def cancel_request(self, id: str):
ret = False
if id in self.hash_progress:
self.hash_progress.pop(id)
if id in self.desired_hash_translation_map:
self.desired_hash_translation_map.pop(id)
ret = True
return ret
def load_allowed_peers(self, path):
allowed_dest = []
if path or not self.allow_all:
@@ -251,7 +260,10 @@ class RNSInterface:
request_id = response_rec.get_request_id()
hash_str = self.request_id_to_hash[request_id]
progress = response_rec.get_progress()
if hash_str in self.hash_progress:
self.hash_progress[hash_str] = progress
else:
response_rec.link.teardown()
def service_desired_hash_list(self):
"""Thread to service the desired hash dictionary"""

View File

@@ -75,6 +75,10 @@ class ServerCommandState:
self.cid_store.save_index()
return ret
def cancel_request(self, id: str):
ret = self.rns_interface.cancel_request(id)
return ret
def updated_hash_callback(self, node_hash):
"""Called when the cid storage has added any nodes from a dictionary(json file)"""
node = self.cid_store.get_node_obj(node_hash)