Log why an object has been rejected
This commit is contained in:
parent
1b5d2090e1
commit
de260cfa96
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import logging
|
||||||
import struct
|
import struct
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
@ -81,10 +82,13 @@ class Object(object):
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
if self.is_expired():
|
if self.is_expired():
|
||||||
|
logging.warning('Rejecting object {}, reason: is_expired'.format(self.vector))
|
||||||
return False
|
return False
|
||||||
if len(self.object_payload) > 2**18:
|
if len(self.object_payload) > 2**18:
|
||||||
|
logging.warning('Rejecting object {}, reason: len(payload) > 2**18'.format(self.vector))
|
||||||
return False
|
return False
|
||||||
if self.stream_number != 1:
|
if self.stream_number != 1:
|
||||||
|
logging.warning('Rejecting object {}, reason: not in stream 1'.format(self.vector))
|
||||||
return False
|
return False
|
||||||
data = self.to_bytes()[8:]
|
data = self.to_bytes()[8:]
|
||||||
length = len(data) + 8 + shared.payload_length_extra_bytes
|
length = len(data) + 8 + shared.payload_length_extra_bytes
|
||||||
|
@ -93,7 +97,7 @@ class Object(object):
|
||||||
pow_value = int.from_bytes(hashlib.sha512(hashlib.sha512(self.nonce + h).digest()).digest()[:8], 'big')
|
pow_value = int.from_bytes(hashlib.sha512(hashlib.sha512(self.nonce + h).digest()).digest()[:8], 'big')
|
||||||
target = int(2**64/(shared.nonce_trials_per_byte*(length+(dt*length)/(2**16))))
|
target = int(2**64/(shared.nonce_trials_per_byte*(length+(dt*length)/(2**16))))
|
||||||
if target < pow_value:
|
if target < pow_value:
|
||||||
print('insufficient pow')
|
logging.warning('Rejecting object {}, reason: insufficient pow'.format(self.vector))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user