return(firstByte,1)#the 1 is the length of the varint
return(firstByte,1)#the 1 is the length of the varint
iffirstByte==253:
# encodes 253 to 65535
iflen(data)<3:
raisevarintDecodeError('The first byte of this varint as an integer is %s but the total length is only %s. It needs to be at least 3.'%(firstByte,len(data)))
encodedValue,=unpack('>H',data[1:3])
raisevarintDecodeError(
'The first byte of this varint as an integer is %s'
' but the total length is only %s. It needs to be'
' at least 3.'%(firstByte,len(data)))
encodedValue,=unpack('>H',data[1:3])
ifencodedValue<253:
raisevarintDecodeError('This varint does not encode the value with the lowest possible number of bytes.')
return(encodedValue,3)
raisevarintDecodeError(
'This varint does not encode the value with the lowest'
' possible number of bytes.')
return(encodedValue,3)
iffirstByte==254:
# encodes 65536 to 4294967295
iflen(data)<5:
raisevarintDecodeError('The first byte of this varint as an integer is %s but the total length is only %s. It needs to be at least 5.'%(firstByte,len(data)))
encodedValue,=unpack('>I',data[1:5])
raisevarintDecodeError(
'The first byte of this varint as an integer is %s'
' but the total length is only %s. It needs to be'
' at least 5.'%(firstByte,len(data)))
encodedValue,=unpack('>I',data[1:5])
ifencodedValue<65536:
raisevarintDecodeError('This varint does not encode the value with the lowest possible number of bytes.')
return(encodedValue,5)
raisevarintDecodeError(
'This varint does not encode the value with the lowest'
' possible number of bytes.')
return(encodedValue,5)
iffirstByte==255:
# encodes 4294967296 to 18446744073709551615
iflen(data)<9:
raisevarintDecodeError('The first byte of this varint as an integer is %s but the total length is only %s. It needs to be at least 9.'%(firstByte,len(data)))
encodedValue,=unpack('>Q',data[1:9])
raisevarintDecodeError(
'The first byte of this varint as an integer is %s'
' but the total length is only %s. It needs to be'
' at least 9.'%(firstByte,len(data)))
encodedValue,=unpack('>Q',data[1:9])
ifencodedValue<4294967296:
raisevarintDecodeError('This varint does not encode the value with the lowest possible number of bytes.')
return(encodedValue,9)
raisevarintDecodeError(
'This varint does not encode the value with the lowest'
print'Let us make an address from scratch. Suppose we generate two random 32 byte values and call the first one the signing key and the second one the encryption key:'
print'Notice that they both begin with the \\x04 which specifies the encoding type. This prefix is not send over the wire. You must strip if off before you send your public key across the wire, and you must add it back when you receive a public key.'
numberOfNullBytesDemandedOnFrontOfRipeHash=1# the default
# the default
numberOfNullBytesDemandedOnFrontOfRipeHash=1
elifqueueValue[0]=='stopThread':
break
else:
sys.stderr.write(
'Programming error: A structure with the wrong number of values was passed into the addressGeneratorQueue. Here is the queueValue: %s\n'%repr(queueValue))
logger.error(
'Programming error: A structure with the wrong number'
' of values was passed into the addressGeneratorQueue.'
' Here is the queueValue: %r\n',queueValue)
ifaddressVersionNumber<3oraddressVersionNumber>4:
sys.stderr.write(
'Program error: For some reason the address generator queue has been given a request to create at least one version %s address which it cannot do.\n'%addressVersionNumber)
logger.error(
'Program error: For some reason the address generator'
' queue has been given a request to create at least'
logger.info('Generated address with ripe digest: %s'%hexlify(ripe.digest()))
logger.info(
'Generated address with ripe digest: %s',
hexlify(ripe.digest()))
try:
logger.info('Address generator calculated %s addresses at %s addresses per second before finding one with the correct ripe-prefix.'%(numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix,numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix/(time.time()-startTime)))
logger.info('Generated address with ripe digest: %s'%hexlify(ripe.digest()))
logger.info(
'Generated address with ripe digest: %s',
hexlify(ripe.digest()))
try:
logger.info('Address generator calculated %s addresses at %s addresses per second before finding one with the correct ripe-prefix.'%(numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix,numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix/(time.time()-startTime)))
# Note that this is the first half of the sha512 hash.
privEncryptionKey=doubleHashOfAddressData[:32]
tag=doubleHashOfAddressData[32:]
state.neededPubkeys[tag]=(toAddress,highlevelcrypto.makeCryptor(hexlify(privEncryptionKey)))# We'll need this for when we receive a pubkey reply: it will be encrypted and we'll need to decrypt it.
# We'll need this for when we receive a pubkey reply:
# it will be encrypted and we'll need to decrypt it.
state.neededPubkeys[tag]=(
toAddress,
highlevelcrypto.makeCryptor(
hexlify(privEncryptionKey))
)
# Initialize the shared.ackdataForWhichImWatching data structure
queryreturn=sqlQuery(
@ -84,16 +101,19 @@ class singleWorker(threading.Thread, StoppableThread):
# Fix legacy (headerless) watched ackdata to include header