replaced all the print statement of api.py module with logger
This commit is contained in:
parent
1571176082
commit
3ca87bf41b
37
src/api.py
37
src/api.py
|
@ -1208,27 +1208,31 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
) * requiredAverageProofOfWorkNonceTrialsPerByte
|
) * requiredAverageProofOfWorkNonceTrialsPerByte
|
||||||
)
|
)
|
||||||
with threads.printLock:
|
with threads.printLock:
|
||||||
print(
|
logger.warning(
|
||||||
'(For msg message via API) Doing proof of work.'
|
'(For msg message via API) Doing proof of work.'
|
||||||
'Total required difficulty:',
|
'Total required difficulty: %f'
|
||||||
|
'Required small message difficulty: %f',
|
||||||
float(
|
float(
|
||||||
requiredAverageProofOfWorkNonceTrialsPerByte
|
requiredAverageProofOfWorkNonceTrialsPerByte
|
||||||
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
|
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
|
||||||
'Required small message difficulty:',
|
|
||||||
float(
|
float(
|
||||||
requiredPayloadLengthExtraBytes
|
requiredPayloadLengthExtraBytes
|
||||||
) / defaults.networkDefaultPayloadLengthExtraBytes,
|
) / defaults.networkDefaultPayloadLengthExtraBytes
|
||||||
)
|
)
|
||||||
powStartTime = time.time()
|
powStartTime = time.time()
|
||||||
initialHash = hashlib.sha512(encryptedPayload).digest()
|
initialHash = hashlib.sha512(encryptedPayload).digest()
|
||||||
trialValue, nonce = proofofwork.run(target, initialHash)
|
trialValue, nonce = proofofwork.run(target, initialHash)
|
||||||
with threads.printLock:
|
with threads.printLock:
|
||||||
print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce
|
logger.info(
|
||||||
|
"(For msg message via API) Found proof of work %s Nonce: %s",
|
||||||
|
trialValue, nonce
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
print(
|
logger.warning(
|
||||||
'POW took', int(time.time() - powStartTime),
|
'POW took %d seconds. %f'
|
||||||
'seconds.', nonce / (time.time() - powStartTime),
|
|
||||||
'nonce trials per second.',
|
'nonce trials per second.',
|
||||||
|
int(time.time() - powStartTime),
|
||||||
|
nonce / (time.time() - powStartTime)
|
||||||
)
|
)
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
@ -1242,7 +1246,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
int(time.time()) + TTL, ''
|
int(time.time()) + TTL, ''
|
||||||
)
|
)
|
||||||
with threads.printLock:
|
with threads.printLock:
|
||||||
print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash)
|
logger.warning(
|
||||||
|
'Broadcasting inv for msg(API disseminatePreEncryptedMsg command): %s',
|
||||||
|
hexlify(inventoryHash)
|
||||||
|
)
|
||||||
queues.invQueue.put((toStreamNumber, inventoryHash))
|
queues.invQueue.put((toStreamNumber, inventoryHash))
|
||||||
|
|
||||||
def HandleTrashSentMessageByAckDAta(self, params):
|
def HandleTrashSentMessageByAckDAta(self, params):
|
||||||
|
@ -1272,10 +1279,13 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
target = 2 ** 64 / ((
|
target = 2 ** 64 / ((
|
||||||
len(payload) + defaults.networkDefaultPayloadLengthExtraBytes + 8
|
len(payload) + defaults.networkDefaultPayloadLengthExtraBytes + 8
|
||||||
) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
|
) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
|
||||||
print '(For pubkey message via API) Doing proof of work...'
|
logger.debug('(For pubkey message via API) Doing proof of work...')
|
||||||
initialHash = hashlib.sha512(payload).digest()
|
initialHash = hashlib.sha512(payload).digest()
|
||||||
trialValue, nonce = proofofwork.run(target, initialHash)
|
trialValue, nonce = proofofwork.run(target, initialHash)
|
||||||
print '(For pubkey message via API) Found proof of work', trialValue, 'Nonce:', nonce
|
logger.debug(
|
||||||
|
'(For pubkey message via API) Found proof of work %s Nonce: %s',
|
||||||
|
trialValue, nonce
|
||||||
|
)
|
||||||
payload = pack('>Q', nonce) + payload
|
payload = pack('>Q', nonce) + payload
|
||||||
|
|
||||||
pubkeyReadPosition = 8 # bypass the nonce
|
pubkeyReadPosition = 8 # bypass the nonce
|
||||||
|
@ -1296,7 +1306,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
|
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
|
||||||
)
|
)
|
||||||
with threads.printLock:
|
with threads.printLock:
|
||||||
print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)
|
logger.warning(
|
||||||
|
'broadcasting inv within API command disseminatePubkey with hash: %s',
|
||||||
|
hexlify(inventoryHash)
|
||||||
|
)
|
||||||
queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
|
queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
|
||||||
|
|
||||||
def HandleGetMessageDataByDestinationHash(self, params):
|
def HandleGetMessageDataByDestinationHash(self, params):
|
||||||
|
|
Reference in New Issue
Block a user