MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / processmsg

Method processmsg

src/class_objectProcessor.py:338–610  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

336
337
338 def processmsg(self, data):
339 messageProcessingStartTime = time.time()
340 shared.numberOfMessagesProcessed += 1
341 queues.UISignalQueue.put((
342 'updateNumberOfMessagesProcessed', 'no data'))
343 readPosition = 20 # bypass the nonce, time, and object type
344 msgVersion, msgVersionLength = decodeVarint(data[readPosition:readPosition + 9])
345 if msgVersion != 1:
346 logger.info('Cannot understand message versions other than one. Ignoring message.')
347 return
348 readPosition += msgVersionLength
349
350 streamNumberAsClaimedByMsg, streamNumberAsClaimedByMsgLength = decodeVarint(
351 data[readPosition:readPosition + 9])
352 readPosition += streamNumberAsClaimedByMsgLength
353 inventoryHash = calculateInventoryHash(data)
354 initialDecryptionSuccessful = False
355
356 # This is not an acknowledgement bound for me. See if it is a message
357 # bound for me by trying to decrypt it with my private keys.
358
359 for key, cryptorObject in sorted(shared.myECCryptorObjects.items(), key=lambda x: random.random()):
360 try:
361 if initialDecryptionSuccessful: # continue decryption attempts to avoid timing attacks
362 cryptorObject.decrypt(data[readPosition:])
363 else:
364 decryptedData = cryptorObject.decrypt(data[readPosition:])
365 toRipe = key # This is the RIPE hash of my pubkeys. We need this below to compare to the destination_ripe included in the encrypted data.
366 initialDecryptionSuccessful = True
367 logger.info('EC decryption successful using key associated with ripe hash: %s.' % hexlify(key))
368 except Exception as err:
369 pass
370 if not initialDecryptionSuccessful:
371 # This is not a message bound for me.
372 logger.info('Length of time program spent failing to decrypt this message: %s seconds.' % (time.time() - messageProcessingStartTime,))
373 return
374
375 # This is a message bound for me.
376 toAddress = shared.myAddressesByHash[
377 toRipe] # Look up my address based on the RIPE hash.
378 readPosition = 0
379 sendersAddressVersionNumber, sendersAddressVersionNumberLength = decodeVarint(
380 decryptedData[readPosition:readPosition + 10])
381 readPosition += sendersAddressVersionNumberLength
382 if sendersAddressVersionNumber == 0:
383 logger.info('Cannot understand sendersAddressVersionNumber = 0. Ignoring message.')
384 return
385 if sendersAddressVersionNumber > 4:
386 logger.info('Sender\'s address version number %s not yet supported. Ignoring message.' % sendersAddressVersionNumber)
387 return
388 if len(decryptedData) < 170:
389 logger.info('Length of the unencrypted data is unreasonably short. Sanity check failed. Ignoring message.')
390 return
391 sendersStreamNumber, sendersStreamNumberLength = decodeVarint(
392 decryptedData[readPosition:readPosition + 10])
393 if sendersStreamNumber == 0:
394 logger.info('sender\'s stream number is 0. Ignoring message.&#x27;)
395 return

Callers 1

runMethod · 0.95

Calls 15

possibleNewPubkeyMethod · 0.95
BMConfigParserClass · 0.90
genAckPayloadFunction · 0.90
decodeVarintFunction · 0.85
calculateInventoryHashFunction · 0.85
encodeVarintFunction · 0.85
encodeAddressFunction · 0.85
sqlExecuteFunction · 0.85
decodeAddressFunction · 0.85
sqlQueryFunction · 0.85

Tested by

no test coverage detected