Skip to content

Commit ac348e4

Browse files
committed
Fixes and refactoring
- fixes errors introduced in the earlier refactoring - more variables moved to state.py - path finding functions moved to paths.py - remembers IPv6 network unreachable (in the future can be used to skip IPv6 for a while)
1 parent 5d2beba commit ac348e4

31 files changed

+334
-297
lines changed

src/api.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import helper_sent
2525
import hashlib
2626

27+
import state
2728
from pyelliptic.openssl import OpenSSL
2829
from 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):

src/bitmessagecurses/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from helper_sql import *
2323

2424
import shared
25+
import ConfigParser
2526
from configparser import BMConfigParser
2627
from addresses import *
2728
from pyelliptic.openssl import OpenSSL

src/bitmessagemain.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import shared
3030
from helper_sql import sqlQuery
31+
import state
3132
import threading
3233

3334
# Classes
@@ -49,7 +50,7 @@
4950
from helper_threading import *
5051

5152
def connectToStream(streamNumber):
52-
shared.streamsInWhichIAmParticipating[streamNumber] = 'no data'
53+
state.streamsInWhichIAmParticipating[streamNumber] = 'no data'
5354
selfInitiatedConnections[streamNumber] = {}
5455

5556
if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
@@ -146,10 +147,10 @@ def run(self):
146147
selfInitiatedConnections = {}
147148

148149
if shared.useVeryEasyProofOfWorkForTesting:
149-
shared.networkDefaultProofOfWorkNonceTrialsPerByte = int(
150-
shared.networkDefaultProofOfWorkNonceTrialsPerByte / 100)
151-
shared.networkDefaultPayloadLengthExtraBytes = int(
152-
shared.networkDefaultPayloadLengthExtraBytes / 100)
150+
protocol.networkDefaultProofOfWorkNonceTrialsPerByte = int(
151+
protocol.networkDefaultProofOfWorkNonceTrialsPerByte / 100)
152+
protocol.networkDefaultPayloadLengthExtraBytes = int(
153+
protocol.networkDefaultPayloadLengthExtraBytes / 100)
153154

154155
class Main:
155156
def start(self, daemon=False):

0 commit comments

Comments
 (0)