Added missed changes to secure DHT.
@@ -1010,7 +1010,12 @@ class KademliaProtocolAppend(KademliaProtocol):
else:
old_value_ = self.storage[key]
old_value = json.loads(old_value_)
+ try:
new_value = list(set(old_value + pvalue))
+ except TypeError:
+ # When the key have been used for single values it does not contain a list
+ # Just replace old value
+ new_value = pvalue
_log.debug("append key: %s old: %s add: %s new: %s" %
(base64.b64encode(key), old_value, pvalue, new_value))
self.storage[key] = json.dumps(new_value)
@@ -1063,7 +1068,12 @@ class KademliaProtocolAppend(KademliaProtocol):
self.set_keys.add(key)
if key in self.storage:
old_value = json.loads(self.storage[key])
+ if isinstance(old_value, list):
new_value = list(set(old_value) - set(pvalue))
+ else:
+ # When the key have been used for single values it does not contain a list
+ # Just empty it
+ new_value = []
self.storage[key] = json.dumps(new_value)
_log.debug("remove key: %s old: %s add: %s new: %s" %
(base64.b64encode(key), old_value, pvalue, new_value))
