Merge pull request #1138 from lbryio/dht-compat
make dht forwards-compatible for upcoming switch to standardized bencode dict keys
This commit is contained in:
commit
6dd8138c05
5 changed files with 23 additions and 23 deletions
|
@ -30,7 +30,7 @@ at anytime.
|
|||
### Added
|
||||
* scripts to autogenerate documentation
|
||||
* now updating new channel also takes into consideration the original bid amount, so now channel could be updated for wallet balance + the original bid amount
|
||||
*
|
||||
* forward-compaitibility for upcoming DHT bencoding changes
|
||||
|
||||
### Removed
|
||||
* short(single dashed) arguments for `lbrynet-cli`
|
||||
|
|
|
@ -2045,7 +2045,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
.format(MAX_UPDATE_FEE_ESTIMATE - balance))
|
||||
elif bid > max_bid_amount:
|
||||
raise InsufficientFundsError(
|
||||
"Please lower the bid value, the maximum amount you can specify for this claim is {}"
|
||||
"Please lower the bid. After accounting for the estimated fee, you only have {} left."
|
||||
.format(max_bid_amount))
|
||||
|
||||
metadata = metadata or {}
|
||||
|
|
|
@ -64,16 +64,9 @@ class Bencode(Encoding):
|
|||
keys = data.keys()
|
||||
keys.sort()
|
||||
for key in keys:
|
||||
encodedDictItems += self.encode(key)
|
||||
encodedDictItems += self.encode(key) # TODO: keys should always be bytestrings
|
||||
encodedDictItems += self.encode(data[key])
|
||||
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:
|
||||
# This (None/NULL data type) is a non-standard extension
|
||||
# to the original Bencode algorithm
|
||||
return 'n'
|
||||
else:
|
||||
print data
|
||||
raise TypeError("Cannot bencode '%s' object" % type(data))
|
||||
|
|
|
@ -43,24 +43,31 @@ class MessageTranslator(object):
|
|||
class DefaultFormat(MessageTranslator):
|
||||
""" The default on-the-wire message format for this library """
|
||||
typeRequest, typeResponse, typeError = range(3)
|
||||
headerType, headerMsgID, headerNodeID, headerPayload, headerArgs = range(5)
|
||||
headerType, headerMsgID, headerNodeID, headerPayload, headerArgs = range(5) # TODO: make str
|
||||
|
||||
@staticmethod
|
||||
def get(primitive, key):
|
||||
try:
|
||||
return primitive[key]
|
||||
except KeyError:
|
||||
return primitive[str(key)] # TODO: switch to int()
|
||||
|
||||
def fromPrimitive(self, msgPrimitive):
|
||||
msgType = msgPrimitive[self.headerType]
|
||||
if msgType == self.typeRequest:
|
||||
msg = msgtypes.RequestMessage(msgPrimitive[self.headerNodeID],
|
||||
msgPrimitive[self.headerPayload],
|
||||
msgPrimitive[self.headerArgs],
|
||||
msgPrimitive[self.headerMsgID])
|
||||
msg = msgtypes.RequestMessage(self.get(msgPrimitive, self.headerNodeID),
|
||||
self.get(msgPrimitive, self.headerPayload),
|
||||
self.get(msgPrimitive, self.headerArgs),
|
||||
self.get(msgPrimitive, self.headerMsgID))
|
||||
elif msgType == self.typeResponse:
|
||||
msg = msgtypes.ResponseMessage(msgPrimitive[self.headerMsgID],
|
||||
msgPrimitive[self.headerNodeID],
|
||||
msgPrimitive[self.headerPayload])
|
||||
msg = msgtypes.ResponseMessage(self.get(msgPrimitive, self.headerMsgID),
|
||||
self.get(msgPrimitive, self.headerNodeID),
|
||||
self.get(msgPrimitive, self.headerPayload))
|
||||
elif msgType == self.typeError:
|
||||
msg = msgtypes.ErrorMessage(msgPrimitive[self.headerMsgID],
|
||||
msgPrimitive[self.headerNodeID],
|
||||
msgPrimitive[self.headerPayload],
|
||||
msgPrimitive[self.headerArgs])
|
||||
msg = msgtypes.ErrorMessage(self.get(msgPrimitive, self.headerMsgID),
|
||||
self.get(msgPrimitive, self.headerNodeID),
|
||||
self.get(msgPrimitive, self.headerPayload),
|
||||
self.get(msgPrimitive, self.headerArgs))
|
||||
else:
|
||||
# Unknown message, no payload
|
||||
msg = msgtypes.Message(msgPrimitive[self.headerMsgID], msgPrimitive[self.headerNodeID])
|
||||
|
|
|
@ -209,7 +209,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
|||
except (encoding.DecodeError, ValueError):
|
||||
# We received some rubbish here
|
||||
return
|
||||
except IndexError:
|
||||
except (IndexError, KeyError):
|
||||
log.warning("Couldn't decode dht datagram from %s", address)
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in a new issue