Skip to content

Commit

Permalink
added more logs, last tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vesellov committed Sep 21, 2018
1 parent 44622cb commit 7422d67
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ Feedback
You can contact [BitDust contributors](https://github.com/bitdust-io) on GitHub if you have any questions or ideas.
Welcome to the future!


2 changes: 2 additions & 0 deletions dht/dht_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ def request(self, key):
lg.out(_DebugLevel, ' found in _dataStore and saved as internal')
else:
value = internal_value
if value is None:
value = 0
if _Debug:
lg.out(_DebugLevel, ' read internal value, counter=%d' % counter('request'))
return {key: value, }
Expand Down
58 changes: 31 additions & 27 deletions dht/entangled/kademlia/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,37 @@ def encode(self, data):
@return: The encoded data
@rtype: str
"""
if type(data) in six.integer_types:
return 'i%de' % data
elif isinstance(data, six.text_type):
return '%d:%s' % (len(data.encode('utf-8')), data.encode('utf-8'))
elif isinstance(data, six.binary_type):
return '%d:%s' % (len(data), data)
elif type(data) in (list, tuple):
encodedListItems = ''
for item in data:
encodedListItems += self.encode(item)
return 'l%se' % encodedListItems
elif isinstance(data, dict):
encodedDictItems = ''
keys = sorted(data.keys())
for key in keys:
e_key = self.encode(key)
e_data = self.encode(data[key])
encodedDictItems += e_key
encodedDictItems += e_data
return 'd%se' % encodedDictItems
elif isinstance(data, float):
# This (float data type) is a non-standard extension to the original Bencode algorithm
return 'f%fe' % data
elif data is None:
return 'i0e' # return 0
else:
raise TypeError("Cannot bencode '%s' object" % type(data))
try:
if type(data) in six.integer_types:
return 'i%de' % data
elif isinstance(data, six.text_type):
return '%d:%s' % (len(data.encode('utf-8')), data.encode('utf-8'))
elif isinstance(data, six.binary_type):
return '%d:%s' % (len(data), data)
elif type(data) in (list, tuple):
encodedListItems = ''
for item in data:
encodedListItems += self.encode(item)
return 'l%se' % encodedListItems
elif isinstance(data, dict):
encodedDictItems = ''
keys = sorted(data.keys())
for key in keys:
e_key = self.encode(key)
e_data = self.encode(data[key])
encodedDictItems += e_key
encodedDictItems += e_data
return 'd%se' % encodedDictItems
elif isinstance(data, float):
# This (float data type) is a non-standard extension to the original Bencode algorithm
return 'f%fe' % data
elif data is None:
return 'i0e' # return 0
else:
raise TypeError("Cannot bencode '%s' object" % type(data))
except:
import traceback
traceback.print_exc()

def decode(self, data):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/raidworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():

# TEST
# call with parameters like that:
# python raidworker.py C:\temp\joomla2.sql ecc/7x7 myID_ABC 1234 c:\temp\somedir
# python raidworker.py ./somefile ecc/7x7 myID_ABC 1234 ./somefolder/
tasks = {}

def _cb(cmd, taskdata, result):
Expand Down
1 change: 1 addition & 0 deletions userid/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def makehash(self):
hsh += sep + self.date.replace(u' ', u'_')
hsh += sep + self.version
hsh += sep + self.revision
lg.out(12, "identity.makehash: %s" % hsh)
hashcode = key.Hash(strng.to_bin(hsh))
return hashcode

Expand Down

0 comments on commit 7422d67

Please sign in to comment.