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

Method HandleDissimatePubKey

src/api.py:879–915  ·  view source on GitHub ↗
(self, params)

Source from the content-addressed store, hash-verified

877 return 'Trashed sent message (assuming message existed).'
878
879 def HandleDissimatePubKey(self, params):
880 # The device issuing this command to PyBitmessage supplies a pubkey object to be
881 # disseminated to the rest of the Bitmessage network. PyBitmessage accepts this
882 # pubkey object and sends it out to the rest of the Bitmessage network as if it
883 # had generated the pubkey object itself. Please do not yet add this to the api
884 # doc.
885 if len(params) != 1:
886 raise APIError(0, 'I need 1 parameter!')
887 payload, = params
888 payload = self._decode(payload, "hex")
889
890 # Let us do the POW
891 target = 2 ** 64 / ((len(payload) + defaults.networkDefaultPayloadLengthExtraBytes +
892 8) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
893 print '(For pubkey message via API) Doing proof of work...'
894 initialHash = hashlib.sha512(payload).digest()
895 trialValue, nonce = proofofwork.run(target, initialHash)
896 print '(For pubkey message via API) Found proof of work', trialValue, 'Nonce:', nonce
897 payload = pack('>Q', nonce) + payload
898
899 pubkeyReadPosition = 8 # bypass the nonce
900 if payload[pubkeyReadPosition:pubkeyReadPosition+4] == '\x00\x00\x00\x00': # if this pubkey uses 8 byte time
901 pubkeyReadPosition += 8
902 else:
903 pubkeyReadPosition += 4
904 addressVersion, addressVersionLength = decodeVarint(payload[pubkeyReadPosition:pubkeyReadPosition+10])
905 pubkeyReadPosition += addressVersionLength
906 pubkeyStreamNumber = decodeVarint(payload[pubkeyReadPosition:pubkeyReadPosition+10])[0]
907 inventoryHash = calculateInventoryHash(payload)
908 objectType = 1
909 #todo: support v4 pubkeys
910 TTL = 28 * 24 * 60 * 60
911 Inventory()[inventoryHash] = (
912 objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL,'')
913 with shared.printLock:
914 print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)
915 queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
916
917 def HandleGetMessageDataByDestinationHash(self, params):
918 # Method will eventually be used by a particular Android app to

Callers

nothing calls this directly

Calls 7

_decodeMethod · 0.95
decodeVarintFunction · 0.90
calculateInventoryHashFunction · 0.90
InventoryClass · 0.90
APIErrorClass · 0.85
putMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected