Skip to content

Commit 0b08fe6

Browse files
committed
Some initial coding work for chans
1 parent 8bd00dc commit 0b08fe6

3 files changed

Lines changed: 40 additions & 31 deletions

File tree

src/bitmessagemain.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,6 @@ def run(self):
706706
signal.signal(signal.SIGINT, helper_generic.signal_handler)
707707
# signal.signal(signal.SIGINT, signal.SIG_DFL)
708708

709-
# Check the Major version, the first element in the array
710-
if sqlite3.sqlite_version_info[0] < 3:
711-
print 'This program requires sqlite version 3 or higher because 2 and lower cannot store NULL values. I see version:', sqlite3.sqlite_version_info
712-
os._exit(0)
713-
714709
helper_startup.loadConfig()
715710

716711
helper_bootstrap.knownNodes()

src/class_addressGenerator.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ def run(self):
2121
queueValue = shared.addressGeneratorQueue.get()
2222
nonceTrialsPerByte = 0
2323
payloadLengthExtraBytes = 0
24-
if len(queueValue) == 7:
24+
if queueValue[0] == 'createChan':
25+
command, addressVersionNumber, streamNumber, label, deterministicPassphrase = queueValue
26+
eighteenByteRipe = False
27+
numberOfAddressesToMake = 1
28+
elif queueValue[0] == 'joinChan':
29+
command, chanAddress, label, deterministicPassphrase = queueValue
30+
eighteenByteRipe = False
31+
numberOfAddressesToMake = 1
32+
elif len(queueValue) == 7:
2533
command, addressVersionNumber, streamNumber, label, numberOfAddressesToMake, deterministicPassphrase, eighteenByteRipe = queueValue
2634
elif len(queueValue) == 9:
2735
command, addressVersionNumber, streamNumber, label, numberOfAddressesToMake, deterministicPassphrase, eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes = queueValue
@@ -122,7 +130,7 @@ def run(self):
122130
shared.workerQueue.put((
123131
'doPOWForMyV3Pubkey', ripe.digest()))
124132

125-
elif command == 'createDeterministicAddresses' or command == 'getDeterministicAddress':
133+
elif command == 'createDeterministicAddresses' or command == 'getDeterministicAddress' or command == 'createChan' or command == 'joinChan':
126134
if len(deterministicPassphrase) == 0:
127135
sys.stderr.write(
128136
'WARNING: You are creating deterministic address(es) using a blank passphrase. Bitmessage will do it but it is rather stupid.')
@@ -176,7 +184,17 @@ def run(self):
176184
print 'Address generator calculated', numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix, 'addresses at', numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix / (time.time() - startTime), 'keys per second.'
177185
address = encodeAddress(3, streamNumber, ripe.digest())
178186

179-
if command == 'createDeterministicAddresses':
187+
saveAddressToDisk = True
188+
# If we are joining an existing chan, let us check to make sure it matches the provided Bitmessage address
189+
if command == 'joinChan':
190+
if address != chanAddress:
191+
#todo: show an error message in the UI
192+
shared.apiAddressGeneratorReturnQueue.put('API Error 0018: Chan name does not match address.')
193+
saveAddressToDisk = False
194+
if command == 'getDeterministicAddress':
195+
saveAddressToDisk = False
196+
197+
if saveAddressToDisk:
180198
# An excellent way for us to store our keys is in Wallet Import Format. Let us convert now.
181199
# https://en.bitcoin.it/wiki/Wallet_import_format
182200
privSigningKey = '\x80' + potentialPrivSigningKey
@@ -198,6 +216,8 @@ def run(self):
198216
shared.config.set(address, 'label', label)
199217
shared.config.set(address, 'enabled', 'true')
200218
shared.config.set(address, 'decoy', 'false')
219+
if command == 'joinChan' or command == 'createChan':
220+
shared.config.set(address, 'chan', 'true')
201221
shared.config.set(address, 'noncetrialsperbyte', str(
202222
nonceTrialsPerByte))
203223
shared.config.set(address, 'payloadlengthextrabytes', str(
@@ -213,18 +233,11 @@ def run(self):
213233
label, address, str(streamNumber))))
214234
listOfNewAddressesToSendOutThroughTheAPI.append(
215235
address)
216-
# if eighteenByteRipe:
217-
# shared.reloadMyAddressHashes()#This is
218-
# necessary here (rather than just at the end)
219-
# because otherwise if the human generates a
220-
# large number of new addresses and uses one
221-
# before they are done generating, the program
222-
# will receive a getpubkey message and will
223-
# ignore it.
224236
shared.myECCryptorObjects[ripe.digest()] = highlevelcrypto.makeCryptor(
225237
potentialPrivEncryptionKey.encode('hex'))
226238
shared.myAddressesByHash[
227239
ripe.digest()] = address
240+
#todo: don't send out pubkey if dealing with a chan; save in pubkeys table instead.
228241
shared.workerQueue.put((
229242
'doPOWForMyV3Pubkey', ripe.digest()))
230243
except:
@@ -242,6 +255,7 @@ def run(self):
242255
# shared.reloadMyAddressHashes()
243256
elif command == 'getDeterministicAddress':
244257
shared.apiAddressGeneratorReturnQueue.put(address)
258+
#todo: return things to the API if createChan or joinChan assuming saveAddressToDisk
245259
else:
246260
raise Exception(
247261
"Error in the addressGenerator thread. Thread was given a command it could not understand: " + command)

src/helper_startup.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ def loadConfig():
7777
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
7878
shared.config.write(configfile)
7979

80-
if shared.config.getint('bitmessagesettings', 'settingsversion') == 1:
81-
shared.config.set('bitmessagesettings', 'settingsversion', '4')
82-
# If the settings version is equal to 2 or 3 then the
83-
# sqlThread will modify the pubkeys table and change
84-
# the settings version to 4.
85-
shared.config.set('bitmessagesettings', 'socksproxytype', 'none')
86-
shared.config.set('bitmessagesettings', 'sockshostname', 'localhost')
87-
shared.config.set('bitmessagesettings', 'socksport', '9050')
88-
shared.config.set('bitmessagesettings', 'socksauthentication', 'false')
89-
shared.config.set('bitmessagesettings', 'socksusername', '')
90-
shared.config.set('bitmessagesettings', 'sockspassword', '')
91-
shared.config.set('bitmessagesettings', 'keysencrypted', 'false')
92-
shared.config.set('bitmessagesettings', 'messagesencrypted', 'false')
93-
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
94-
shared.config.write(configfile)
80+
if shared.config.getint('bitmessagesettings', 'settingsversion') == 1:
81+
shared.config.set('bitmessagesettings', 'settingsversion', '4')
82+
# If the settings version is equal to 2 or 3 then the
83+
# sqlThread will modify the pubkeys table and change
84+
# the settings version to 4.
85+
shared.config.set('bitmessagesettings', 'socksproxytype', 'none')
86+
shared.config.set('bitmessagesettings', 'sockshostname', 'localhost')
87+
shared.config.set('bitmessagesettings', 'socksport', '9050')
88+
shared.config.set('bitmessagesettings', 'socksauthentication', 'false')
89+
shared.config.set('bitmessagesettings', 'socksusername', '')
90+
shared.config.set('bitmessagesettings', 'sockspassword', '')
91+
shared.config.set('bitmessagesettings', 'keysencrypted', 'false')
92+
shared.config.set('bitmessagesettings', 'messagesencrypted', 'false')
93+
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
94+
shared.config.write(configfile)

0 commit comments

Comments
 (0)