mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 06:34:19 +01:00
Adds a bunch of comments related to the open issues. Clear old comments.
This commit is contained in:
@@ -24,9 +24,6 @@ class Blob:
|
|||||||
# Transaction to be encrypted
|
# Transaction to be encrypted
|
||||||
# FIXME: The blob data should contain more things that just the transaction. Leaving like this for now.
|
# FIXME: The blob data should contain more things that just the transaction. Leaving like this for now.
|
||||||
tx = unhexlify(self.data)
|
tx = unhexlify(self.data)
|
||||||
|
|
||||||
# FIXME: tx_id should not be necessary (can be derived from tx SegWit-like). Passing it for now
|
|
||||||
# Extend the key using HKDF
|
|
||||||
tx_id = unhexlify(tx_id)
|
tx_id = unhexlify(tx_id)
|
||||||
|
|
||||||
# master_key = H(tx_id | tx_id)
|
# master_key = H(tx_id | tx_id)
|
||||||
|
|||||||
@@ -131,8 +131,6 @@ def build_appointment(tx, tx_id, start_block, end_block, dispute_delta, debug, l
|
|||||||
|
|
||||||
# FIXME: The blob data should contain more things that just the transaction. Leaving like this for now.
|
# FIXME: The blob data should contain more things that just the transaction. Leaving like this for now.
|
||||||
blob = Blob(tx, cipher, hash_function)
|
blob = Blob(tx, cipher, hash_function)
|
||||||
|
|
||||||
# FIXME: tx_id should not be necessary (can be derived from tx SegWit-like). Passing it for now
|
|
||||||
encrypted_blob = blob.encrypt(tx_id, debug, logging)
|
encrypted_blob = blob.encrypt(tx_id, debug, logging)
|
||||||
|
|
||||||
appointment = {"locator": locator, "start_time": start_block, "end_time": end_block,
|
appointment = {"locator": locator, "start_time": start_block, "end_time": end_block,
|
||||||
@@ -146,7 +144,7 @@ def check_txid_format(txid):
|
|||||||
if len(txid) != 64:
|
if len(txid) != 64:
|
||||||
sys.exit("locator does not matches the expected size (32-byte / 64 hex chars).")
|
sys.exit("locator does not matches the expected size (32-byte / 64 hex chars).")
|
||||||
|
|
||||||
# TODO: Check this regexp
|
# TODO: #12-check-txid-regexp
|
||||||
return re.search(r'^[0-9A-Fa-f]+$', txid) is not None
|
return re.search(r'^[0-9A-Fa-f]+$', txid) is not None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
pisa/api.py
15
pisa/api.py
@@ -14,6 +14,7 @@ from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
HTTP_OK = 200
|
HTTP_OK = 200
|
||||||
HTTP_BAD_REQUEST = 400
|
HTTP_BAD_REQUEST = 400
|
||||||
|
HTTP_SERVICE_UNAVAILABLE = 503
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
@@ -32,22 +33,21 @@ def add_appointment():
|
|||||||
appointment_added = watcher.add_appointment(appointment, debug, logging)
|
appointment_added = watcher.add_appointment(appointment, debug, logging)
|
||||||
rcode = HTTP_OK
|
rcode = HTTP_OK
|
||||||
|
|
||||||
# FIXME: Response should be signed receipt (created and signed by the API)
|
# ToDo: #13-create-server-side-signature-receipt
|
||||||
if appointment_added:
|
if appointment_added:
|
||||||
response = "appointment accepted. locator: {}".format(appointment.locator)
|
response = "appointment accepted. locator: {}".format(appointment.locator)
|
||||||
else:
|
else:
|
||||||
response = "appointment rejected"
|
response = "appointment rejected"
|
||||||
# FIXME: change the response code maybe?
|
|
||||||
|
|
||||||
elif type(appointment) == tuple:
|
elif type(appointment) == tuple:
|
||||||
rcode = HTTP_BAD_REQUEST
|
rcode = HTTP_BAD_REQUEST
|
||||||
response = "appointment rejected. Error {}: {}".format(appointment[0], appointment[1])
|
response = "appointment rejected. Error {}: {}".format(appointment[0], appointment[1])
|
||||||
else:
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
# We should never end up here, since inspect only returns appointments or tuples. Just in case.
|
||||||
rcode = HTTP_BAD_REQUEST
|
rcode = HTTP_BAD_REQUEST
|
||||||
response = "appointment rejected. Request does not match the standard"
|
response = "appointment rejected. Request does not match the standard"
|
||||||
|
|
||||||
# Send response back. Change multiprocessing.connection for an http based connection
|
|
||||||
if debug:
|
if debug:
|
||||||
logging.info('[API] sending response and disconnecting: {} --> {}:{}'.format(response, remote_addr,
|
logging.info('[API] sending response and disconnecting: {} --> {}:{}'.format(response, remote_addr,
|
||||||
remote_port))
|
remote_port))
|
||||||
@@ -56,11 +56,14 @@ def add_appointment():
|
|||||||
|
|
||||||
|
|
||||||
# FIXME: THE NEXT THREE API ENDPOINTS ARE FOR TESTING AND SHOULD BE REMOVED / PROPERLY MANAGED BEFORE PRODUCTION!
|
# FIXME: THE NEXT THREE API ENDPOINTS ARE FOR TESTING AND SHOULD BE REMOVED / PROPERLY MANAGED BEFORE PRODUCTION!
|
||||||
|
# ToDo: #17-add-api-keys
|
||||||
@app.route('/get_appointment', methods=['GET'])
|
@app.route('/get_appointment', methods=['GET'])
|
||||||
def get_appointment():
|
def get_appointment():
|
||||||
locator = request.args.get('locator')
|
locator = request.args.get('locator')
|
||||||
response = []
|
response = []
|
||||||
|
|
||||||
|
# ToDo: #15-add-system-monitor
|
||||||
|
|
||||||
appointment_in_watcher = watcher.appointments.get(locator)
|
appointment_in_watcher = watcher.appointments.get(locator)
|
||||||
|
|
||||||
if appointment_in_watcher:
|
if appointment_in_watcher:
|
||||||
@@ -92,6 +95,8 @@ def get_all_appointments():
|
|||||||
watcher_appointments = []
|
watcher_appointments = []
|
||||||
responder_jobs = []
|
responder_jobs = []
|
||||||
|
|
||||||
|
# ToDo: #15-add-system-monitor
|
||||||
|
|
||||||
if request.remote_addr in request.host or request.remote_addr == '127.0.0.1':
|
if request.remote_addr in request.host or request.remote_addr == '127.0.0.1':
|
||||||
for app_id, appointment in watcher.appointments.items():
|
for app_id, appointment in watcher.appointments.items():
|
||||||
jobs_data = [job.to_json() for job in appointment]
|
jobs_data = [job.to_json() for job in appointment]
|
||||||
@@ -125,6 +130,8 @@ def start_api(d, l):
|
|||||||
global debug, logging, watcher, inspector
|
global debug, logging, watcher, inspector
|
||||||
debug = d
|
debug = d
|
||||||
logging = l
|
logging = l
|
||||||
|
|
||||||
|
# ToDo: #18-separate-api-from-watcher
|
||||||
watcher = Watcher()
|
watcher = Watcher()
|
||||||
inspector = Inspector(debug, logging)
|
inspector = Inspector(debug, logging)
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class Inspector:
|
|||||||
elif len(locator) != 64:
|
elif len(locator) != 64:
|
||||||
rcode = errors.APPOINTMENT_WRONG_FIELD_SIZE
|
rcode = errors.APPOINTMENT_WRONG_FIELD_SIZE
|
||||||
message = "wrong locator size ({})".format(len(locator))
|
message = "wrong locator size ({})".format(len(locator))
|
||||||
# TODO: Check this regexp
|
# TODO: #12-check-txid-regexp
|
||||||
elif re.search(r'^[0-9A-Fa-f]+$', locator) is None:
|
elif re.search(r'^[0-9A-Fa-f]+$', locator) is None:
|
||||||
rcode = errors.APPOINTMENT_WRONG_FIELD_FORMAT
|
rcode = errors.APPOINTMENT_WRONG_FIELD_FORMAT
|
||||||
message = "wrong locator format ({})".format(locator)
|
message = "wrong locator format ({})".format(locator)
|
||||||
@@ -146,7 +146,7 @@ class Inspector:
|
|||||||
|
|
||||||
return rcode, message
|
return rcode, message
|
||||||
|
|
||||||
# ToDo: #5-define-checks-encrypted-blob
|
# ToDo: #6-define-checks-encrypted-blob
|
||||||
def check_blob(self, encrypted_blob):
|
def check_blob(self, encrypted_blob):
|
||||||
message = None
|
message = None
|
||||||
rcode = 0
|
rcode = 0
|
||||||
@@ -160,7 +160,7 @@ class Inspector:
|
|||||||
rcode = errors.APPOINTMENT_WRONG_FIELD_TYPE
|
rcode = errors.APPOINTMENT_WRONG_FIELD_TYPE
|
||||||
message = "wrong encrypted_blob data type ({})".format(t)
|
message = "wrong encrypted_blob data type ({})".format(t)
|
||||||
elif encrypted_blob == '':
|
elif encrypted_blob == '':
|
||||||
# ToDo: #5 We may want to define this to be at least as long as one block of the cipher we are using
|
# ToDo: #6 We may want to define this to be at least as long as one block of the cipher we are using
|
||||||
rcode = errors.APPOINTMENT_WRONG_FIELD
|
rcode = errors.APPOINTMENT_WRONG_FIELD
|
||||||
message = "wrong encrypted_blob"
|
message = "wrong encrypted_blob"
|
||||||
if self.debug and message:
|
if self.debug and message:
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if can_connect_to_bitcoind(bitcoin_cli):
|
if can_connect_to_bitcoind(bitcoin_cli):
|
||||||
if in_correct_network(bitcoin_cli, BTC_NETWORK):
|
if in_correct_network(bitcoin_cli, BTC_NETWORK):
|
||||||
|
# ToDo: This may not have to be a thead. The main thread only creates this and terminates.
|
||||||
api_thread = Thread(target=start_api, args=[debug, logging])
|
api_thread = Thread(target=start_api, args=[debug, logging])
|
||||||
api_thread.start()
|
api_thread.start()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user