Add backend ability to understand shorter addresses.
Introduces addresses version 4.
This commit is contained in:
parent
ac4146904b
commit
f6a07a374a
|
@ -97,13 +97,23 @@ def calculateInventoryHash(data):
|
||||||
return sha2.digest()[0:32]
|
return sha2.digest()[0:32]
|
||||||
|
|
||||||
def encodeAddress(version,stream,ripe):
|
def encodeAddress(version,stream,ripe):
|
||||||
if version >= 2:
|
if version >= 2 and version < 4:
|
||||||
if len(ripe) != 20:
|
if len(ripe) != 20:
|
||||||
raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.")
|
raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.")
|
||||||
if ripe[:2] == '\x00\x00':
|
if ripe[:2] == '\x00\x00':
|
||||||
ripe = ripe[2:]
|
ripe = ripe[2:]
|
||||||
elif ripe[:1] == '\x00':
|
elif ripe[:1] == '\x00':
|
||||||
ripe = ripe[1:]
|
ripe = ripe[1:]
|
||||||
|
elif version == 4:
|
||||||
|
if len(ripe) != 20:
|
||||||
|
raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.")
|
||||||
|
emptybitcounter = 0
|
||||||
|
while True:
|
||||||
|
if ripe[emptybitcounter] != '\x00':
|
||||||
|
break
|
||||||
|
emptybitcounter += 1
|
||||||
|
ripe = ripe[emptybitcounter:]
|
||||||
|
|
||||||
a = encodeVarint(version) + encodeVarint(stream) + ripe
|
a = encodeVarint(version) + encodeVarint(stream) + ripe
|
||||||
sha = hashlib.new('sha512')
|
sha = hashlib.new('sha512')
|
||||||
sha.update(a)
|
sha.update(a)
|
||||||
|
@ -164,7 +174,7 @@ def decodeAddress(address):
|
||||||
#print 'addressVersionNumber', addressVersionNumber
|
#print 'addressVersionNumber', addressVersionNumber
|
||||||
#print 'bytesUsedByVersionNumber', bytesUsedByVersionNumber
|
#print 'bytesUsedByVersionNumber', bytesUsedByVersionNumber
|
||||||
|
|
||||||
if addressVersionNumber > 3:
|
if addressVersionNumber > 4:
|
||||||
print 'cannot decode address version numbers this high'
|
print 'cannot decode address version numbers this high'
|
||||||
status = 'versiontoohigh'
|
status = 'versiontoohigh'
|
||||||
return status,0,0,0
|
return status,0,0,0
|
||||||
|
@ -191,6 +201,17 @@ def decodeAddress(address):
|
||||||
return 'ripetoolong',0,0,0
|
return 'ripetoolong',0,0,0
|
||||||
else:
|
else:
|
||||||
return 'otherproblem',0,0,0
|
return 'otherproblem',0,0,0
|
||||||
|
elif addressVersionNumber == 4:
|
||||||
|
if len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4]) > 20:
|
||||||
|
return 'ripetoolong',0,0,0
|
||||||
|
elif len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4]) < 4:
|
||||||
|
return 'ripetooshort',0,0,0
|
||||||
|
else:
|
||||||
|
x00string = ''
|
||||||
|
for i in range(20 - len(data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4])):
|
||||||
|
x00string += '\x00'
|
||||||
|
return status,addressVersionNumber,streamNumber,x00string+data[bytesUsedByVersionNumber+bytesUsedByStreamNumber:-4]
|
||||||
|
|
||||||
|
|
||||||
def addBMIfNotPresent(address):
|
def addBMIfNotPresent(address):
|
||||||
address = str(address).strip()
|
address = str(address).strip()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user