Use decodeObjectParameters() in disseminatePreEncryptedMsg API command handler
This commit is contained in:
parent
9747f65884
commit
1794384f01
20
src/api.py
20
src/api.py
|
@ -66,7 +66,7 @@ import socket
|
||||||
import subprocess # nosec B404
|
import subprocess # nosec B404
|
||||||
import time
|
import time
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from struct import pack, unpack
|
from struct import pack
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six.moves import configparser, http_client, xmlrpc_server
|
from six.moves import configparser, http_client, xmlrpc_server
|
||||||
|
@ -74,6 +74,7 @@ from six.moves import configparser, http_client, xmlrpc_server
|
||||||
import defaults
|
import defaults
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
import helper_sent
|
import helper_sent
|
||||||
|
import protocol
|
||||||
import proofofwork
|
import proofofwork
|
||||||
import queues
|
import queues
|
||||||
import shared
|
import shared
|
||||||
|
@ -1284,7 +1285,7 @@ class BMRPCDispatcher(object):
|
||||||
return {'subscriptions': data}
|
return {'subscriptions': data}
|
||||||
|
|
||||||
@command('disseminatePreEncryptedMsg')
|
@command('disseminatePreEncryptedMsg')
|
||||||
def HandleDisseminatePreEncryptedMsg( # pylint: disable=too-many-locals
|
def HandleDisseminatePreEncryptedMsg(
|
||||||
self, encryptedPayload, requiredAverageProofOfWorkNonceTrialsPerByte,
|
self, encryptedPayload, requiredAverageProofOfWorkNonceTrialsPerByte,
|
||||||
requiredPayloadLengthExtraBytes):
|
requiredPayloadLengthExtraBytes):
|
||||||
"""Handle a request to disseminate an encrypted message"""
|
"""Handle a request to disseminate an encrypted message"""
|
||||||
|
@ -1294,9 +1295,12 @@ class BMRPCDispatcher(object):
|
||||||
# to be done. PyBitmessage accepts this msg object and sends it out
|
# to be done. PyBitmessage accepts this msg object and sends it out
|
||||||
# to the rest of the Bitmessage network as if it had generated
|
# to the rest of the Bitmessage network as if it had generated
|
||||||
# the message itself. Please do not yet add this to the api doc.
|
# the message itself. Please do not yet add this to the api doc.
|
||||||
encryptedPayload = self._decode(encryptedPayload, "hex")
|
encryptedPayload = b'\x00' * 8 + self._decode(encryptedPayload, "hex")
|
||||||
expiresTime = unpack('>Q', encryptedPayload[0:8])[0]
|
# compatibility stub ^, since disseminatePreEncryptedMsg
|
||||||
objectType = unpack('>I', encryptedPayload[8:12])[0]
|
# still expects the encryptedPayload without a nonce
|
||||||
|
objectType, toStreamNumber, expiresTime = \
|
||||||
|
protocol.decodeObjectParameters(encryptedPayload)
|
||||||
|
encryptedPayload = encryptedPayload[8:]
|
||||||
TTL = expiresTime - time.time() + 300 # a bit of extra padding
|
TTL = expiresTime - time.time() + 300 # a bit of extra padding
|
||||||
# Let us do the POW and attach it to the front
|
# Let us do the POW and attach it to the front
|
||||||
target = 2**64 / (
|
target = 2**64 / (
|
||||||
|
@ -1329,12 +1333,6 @@ class BMRPCDispatcher(object):
|
||||||
nonce / (time.time() - powStartTime)
|
nonce / (time.time() - powStartTime)
|
||||||
)
|
)
|
||||||
encryptedPayload = pack('>Q', nonce) + encryptedPayload
|
encryptedPayload = pack('>Q', nonce) + encryptedPayload
|
||||||
parserPos = 20
|
|
||||||
_, objectVersionLength = decodeVarint(
|
|
||||||
encryptedPayload[parserPos:parserPos + 10])
|
|
||||||
parserPos += objectVersionLength
|
|
||||||
toStreamNumber, _ = decodeVarint(
|
|
||||||
encryptedPayload[parserPos:parserPos + 10])
|
|
||||||
inventoryHash = calculateInventoryHash(encryptedPayload)
|
inventoryHash = calculateInventoryHash(encryptedPayload)
|
||||||
Inventory()[inventoryHash] = (
|
Inventory()[inventoryHash] = (
|
||||||
objectType, toStreamNumber, encryptedPayload,
|
objectType, toStreamNumber, encryptedPayload,
|
||||||
|
|
Reference in New Issue
Block a user