2424import helper_sent
2525import hashlib
2626
27+ import state
2728from pyelliptic .openssl import OpenSSL
2829from struct import pack
2930
@@ -251,15 +252,15 @@ def HandleCreateRandomAddress(self, params):
251252 elif len (params ) == 3 :
252253 label , eighteenByteRipe , totalDifficulty = params
253254 nonceTrialsPerByte = int (
254- shared .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
255+ protocol .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
255256 payloadLengthExtraBytes = BMConfigParser ().get (
256257 'bitmessagesettings' , 'defaultpayloadlengthextrabytes' )
257258 elif len (params ) == 4 :
258259 label , eighteenByteRipe , totalDifficulty , smallMessageDifficulty = params
259260 nonceTrialsPerByte = int (
260- shared .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
261+ protocol .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
261262 payloadLengthExtraBytes = int (
262- shared .networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty )
263+ protocol .networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty )
263264 else :
264265 raise APIError (0 , 'Too many parameters!' )
265266 label = self ._decode (label , "base64" )
@@ -319,15 +320,15 @@ def HandleCreateDeterministicAddresses(self, params):
319320 elif len (params ) == 6 :
320321 passphrase , numberOfAddresses , addressVersionNumber , streamNumber , eighteenByteRipe , totalDifficulty = params
321322 nonceTrialsPerByte = int (
322- shared .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
323+ protocol .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
323324 payloadLengthExtraBytes = BMConfigParser ().get (
324325 'bitmessagesettings' , 'defaultpayloadlengthextrabytes' )
325326 elif len (params ) == 7 :
326327 passphrase , numberOfAddresses , addressVersionNumber , streamNumber , eighteenByteRipe , totalDifficulty , smallMessageDifficulty = params
327328 nonceTrialsPerByte = int (
328- shared .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
329+ protocol .networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty )
329330 payloadLengthExtraBytes = int (
330- shared .networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty )
331+ protocol .networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty )
331332 else :
332333 raise APIError (0 , 'Too many parameters!' )
333334 if len (passphrase ) == 0 :
@@ -450,7 +451,7 @@ def HandleLeaveChan(self, params):
450451 if not BMConfigParser ().safeGetBoolean (address , 'chan' ):
451452 raise APIError (25 , 'Specified address is not a chan address. Use deleteAddress API call instead.' )
452453 BMConfigParser ().remove_section (address )
453- with open (shared .appdata + 'keys.dat' , 'wb' ) as configfile :
454+ with open (state .appdata + 'keys.dat' , 'wb' ) as configfile :
454455 BMConfigParser ().write (configfile )
455456 return 'success'
456457
@@ -464,7 +465,7 @@ def HandleDeleteAddress(self, params):
464465 if not BMConfigParser ().has_section (address ):
465466 raise APIError (13 , 'Could not find this address in your keys.dat file.' )
466467 BMConfigParser ().remove_section (address )
467- with open (shared .appdata + 'keys.dat' , 'wb' ) as configfile :
468+ with open (state .appdata + 'keys.dat' , 'wb' ) as configfile :
468469 BMConfigParser ().write (configfile )
469470 shared .UISignalQueue .put (('rerenderMessagelistFromLabels' ,'' ))
470471 shared .UISignalQueue .put (('rerenderMessagelistToLabels' ,'' ))
@@ -837,7 +838,7 @@ def HandleDisseminatePreEncryptedMsg(self, params):
837838 # Let us do the POW and attach it to the front
838839 target = 2 ** 64 / ((len (encryptedPayload )+ requiredPayloadLengthExtraBytes + 8 ) * requiredAverageProofOfWorkNonceTrialsPerByte )
839840 with shared .printLock :
840- print '(For msg message via API) Doing proof of work. Total required difficulty:' , float (requiredAverageProofOfWorkNonceTrialsPerByte ) / shared .networkDefaultProofOfWorkNonceTrialsPerByte , 'Required small message difficulty:' , float (requiredPayloadLengthExtraBytes ) / shared .networkDefaultPayloadLengthExtraBytes
841+ print '(For msg message via API) Doing proof of work. Total required difficulty:' , float (requiredAverageProofOfWorkNonceTrialsPerByte ) / protocol .networkDefaultProofOfWorkNonceTrialsPerByte , 'Required small message difficulty:' , float (requiredPayloadLengthExtraBytes ) / protocol .networkDefaultPayloadLengthExtraBytes
841842 powStartTime = time .time ()
842843 initialHash = hashlib .sha512 (encryptedPayload ).digest ()
843844 trialValue , nonce = proofofwork .run (target , initialHash )
@@ -856,7 +857,7 @@ def HandleDisseminatePreEncryptedMsg(self, params):
856857 objectType , toStreamNumber , encryptedPayload , int (time .time ()) + TTL ,'' )
857858 with shared .printLock :
858859 print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):' , hexlify (inventoryHash )
859- shared .broadcastToSendDataQueues ((
860+ protocol .broadcastToSendDataQueues ((
860861 toStreamNumber , 'advertiseobject' , inventoryHash ))
861862
862863 def HandleTrashSentMessageByAckDAta (self , params ):
@@ -879,8 +880,8 @@ def HandleDissimatePubKey(self, params):
879880 payload = self ._decode (payload , "hex" )
880881
881882 # Let us do the POW
882- target = 2 ** 64 / ((len (payload ) + shared .networkDefaultPayloadLengthExtraBytes +
883- 8 ) * shared .networkDefaultProofOfWorkNonceTrialsPerByte )
883+ target = 2 ** 64 / ((len (payload ) + protocol .networkDefaultPayloadLengthExtraBytes +
884+ 8 ) * protocol .networkDefaultProofOfWorkNonceTrialsPerByte )
884885 print '(For pubkey message via API) Doing proof of work...'
885886 initialHash = hashlib .sha512 (payload ).digest ()
886887 trialValue , nonce = proofofwork .run (target , initialHash )
@@ -903,7 +904,7 @@ def HandleDissimatePubKey(self, params):
903904 objectType , pubkeyStreamNumber , payload , int (time .time ()) + TTL ,'' )
904905 with shared .printLock :
905906 print 'broadcasting inv within API command disseminatePubkey with hash:' , hexlify (inventoryHash )
906- shared .broadcastToSendDataQueues ((
907+ protocol .broadcastToSendDataQueues ((
907908 streamNumber , 'advertiseobject' , inventoryHash ))
908909
909910 def HandleGetMessageDataByDestinationHash (self , params ):
0 commit comments