From 0b08fe6bad9fea63c6fe50ba6af82f04e896f8e5 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 26 Jun 2013 11:55:33 -0400 Subject: [PATCH 1/2] Some initial coding work for chans --- src/bitmessagemain.py | 5 ----- src/class_addressGenerator.py | 36 ++++++++++++++++++++++++----------- src/helper_startup.py | 30 ++++++++++++++--------------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 74f48d1a..c4c2b6db 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -706,11 +706,6 @@ if __name__ == "__main__": signal.signal(signal.SIGINT, helper_generic.signal_handler) # signal.signal(signal.SIGINT, signal.SIG_DFL) - # Check the Major version, the first element in the array - if sqlite3.sqlite_version_info[0] < 3: - print 'This program requires sqlite version 3 or higher because 2 and lower cannot store NULL values. I see version:', sqlite3.sqlite_version_info - os._exit(0) - helper_startup.loadConfig() helper_bootstrap.knownNodes() diff --git a/src/class_addressGenerator.py b/src/class_addressGenerator.py index 38c7d5b9..08c7773e 100644 --- a/src/class_addressGenerator.py +++ b/src/class_addressGenerator.py @@ -21,7 +21,15 @@ class addressGenerator(threading.Thread): queueValue = shared.addressGeneratorQueue.get() nonceTrialsPerByte = 0 payloadLengthExtraBytes = 0 - if len(queueValue) == 7: + if queueValue[0] == 'createChan': + command, addressVersionNumber, streamNumber, label, deterministicPassphrase = queueValue + eighteenByteRipe = False + numberOfAddressesToMake = 1 + elif queueValue[0] == 'joinChan': + command, chanAddress, label, deterministicPassphrase = queueValue + eighteenByteRipe = False + numberOfAddressesToMake = 1 + elif len(queueValue) == 7: command, addressVersionNumber, streamNumber, label, numberOfAddressesToMake, deterministicPassphrase, eighteenByteRipe = queueValue elif len(queueValue) == 9: command, addressVersionNumber, streamNumber, label, numberOfAddressesToMake, deterministicPassphrase, eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes = queueValue @@ -122,7 +130,7 @@ class addressGenerator(threading.Thread): shared.workerQueue.put(( 'doPOWForMyV3Pubkey', ripe.digest())) - elif command == 'createDeterministicAddresses' or command == 'getDeterministicAddress': + elif command == 'createDeterministicAddresses' or command == 'getDeterministicAddress' or command == 'createChan' or command == 'joinChan': if len(deterministicPassphrase) == 0: sys.stderr.write( 'WARNING: You are creating deterministic address(es) using a blank passphrase. Bitmessage will do it but it is rather stupid.') @@ -176,7 +184,17 @@ class addressGenerator(threading.Thread): print 'Address generator calculated', numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix, 'addresses at', numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix / (time.time() - startTime), 'keys per second.' address = encodeAddress(3, streamNumber, ripe.digest()) - if command == 'createDeterministicAddresses': + saveAddressToDisk = True + # If we are joining an existing chan, let us check to make sure it matches the provided Bitmessage address + if command == 'joinChan': + if address != chanAddress: + #todo: show an error message in the UI + shared.apiAddressGeneratorReturnQueue.put('API Error 0018: Chan name does not match address.') + saveAddressToDisk = False + if command == 'getDeterministicAddress': + saveAddressToDisk = False + + if saveAddressToDisk: # An excellent way for us to store our keys is in Wallet Import Format. Let us convert now. # https://en.bitcoin.it/wiki/Wallet_import_format privSigningKey = '\x80' + potentialPrivSigningKey @@ -198,6 +216,8 @@ class addressGenerator(threading.Thread): shared.config.set(address, 'label', label) shared.config.set(address, 'enabled', 'true') shared.config.set(address, 'decoy', 'false') + if command == 'joinChan' or command == 'createChan': + shared.config.set(address, 'chan', 'true') shared.config.set(address, 'noncetrialsperbyte', str( nonceTrialsPerByte)) shared.config.set(address, 'payloadlengthextrabytes', str( @@ -213,18 +233,11 @@ class addressGenerator(threading.Thread): label, address, str(streamNumber)))) listOfNewAddressesToSendOutThroughTheAPI.append( address) - # if eighteenByteRipe: - # shared.reloadMyAddressHashes()#This is - # necessary here (rather than just at the end) - # because otherwise if the human generates a - # large number of new addresses and uses one - # before they are done generating, the program - # will receive a getpubkey message and will - # ignore it. shared.myECCryptorObjects[ripe.digest()] = highlevelcrypto.makeCryptor( potentialPrivEncryptionKey.encode('hex')) shared.myAddressesByHash[ ripe.digest()] = address + #todo: don't send out pubkey if dealing with a chan; save in pubkeys table instead. shared.workerQueue.put(( 'doPOWForMyV3Pubkey', ripe.digest())) except: @@ -242,6 +255,7 @@ class addressGenerator(threading.Thread): # shared.reloadMyAddressHashes() elif command == 'getDeterministicAddress': shared.apiAddressGeneratorReturnQueue.put(address) + #todo: return things to the API if createChan or joinChan assuming saveAddressToDisk else: raise Exception( "Error in the addressGenerator thread. Thread was given a command it could not understand: " + command) diff --git a/src/helper_startup.py b/src/helper_startup.py index df27fd6e..08f8d48a 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -77,18 +77,18 @@ def loadConfig(): with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) - if shared.config.getint('bitmessagesettings', 'settingsversion') == 1: - shared.config.set('bitmessagesettings', 'settingsversion', '4') - # If the settings version is equal to 2 or 3 then the - # sqlThread will modify the pubkeys table and change - # the settings version to 4. - shared.config.set('bitmessagesettings', 'socksproxytype', 'none') - shared.config.set('bitmessagesettings', 'sockshostname', 'localhost') - shared.config.set('bitmessagesettings', 'socksport', '9050') - shared.config.set('bitmessagesettings', 'socksauthentication', 'false') - shared.config.set('bitmessagesettings', 'socksusername', '') - shared.config.set('bitmessagesettings', 'sockspassword', '') - shared.config.set('bitmessagesettings', 'keysencrypted', 'false') - shared.config.set('bitmessagesettings', 'messagesencrypted', 'false') - with open(shared.appdata + 'keys.dat', 'wb') as configfile: - shared.config.write(configfile) + if shared.config.getint('bitmessagesettings', 'settingsversion') == 1: + shared.config.set('bitmessagesettings', 'settingsversion', '4') + # If the settings version is equal to 2 or 3 then the + # sqlThread will modify the pubkeys table and change + # the settings version to 4. + shared.config.set('bitmessagesettings', 'socksproxytype', 'none') + shared.config.set('bitmessagesettings', 'sockshostname', 'localhost') + shared.config.set('bitmessagesettings', 'socksport', '9050') + shared.config.set('bitmessagesettings', 'socksauthentication', 'false') + shared.config.set('bitmessagesettings', 'socksusername', '') + shared.config.set('bitmessagesettings', 'sockspassword', '') + shared.config.set('bitmessagesettings', 'keysencrypted', 'false') + shared.config.set('bitmessagesettings', 'messagesencrypted', 'false') + with open(shared.appdata + 'keys.dat', 'wb') as configfile: + shared.config.write(configfile) From 1657dfec2410833ca6c37e0b81d35e4cb87c8812 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 26 Jun 2013 13:35:53 -0400 Subject: [PATCH 2/2] Move code related to settings file upgrade --- src/class_sqlThread.py | 18 +++++++++++++++++- src/helper_startup.py | 16 ---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 5848e868..ebe6a7ff 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -69,6 +69,22 @@ class sqlThread(threading.Thread): 'ERROR trying to create database file (message.dat). Error message: %s\n' % str(err)) os._exit(0) + if shared.config.getint('bitmessagesettings', 'settingsversion') == 1: + shared.config.set('bitmessagesettings', 'settingsversion', '2') + # If the settings version is equal to 2 or 3 then the + # sqlThread will modify the pubkeys table and change + # the settings version to 4. + shared.config.set('bitmessagesettings', 'socksproxytype', 'none') + shared.config.set('bitmessagesettings', 'sockshostname', 'localhost') + shared.config.set('bitmessagesettings', 'socksport', '9050') + shared.config.set('bitmessagesettings', 'socksauthentication', 'false') + shared.config.set('bitmessagesettings', 'socksusername', '') + shared.config.set('bitmessagesettings', 'sockspassword', '') + shared.config.set('bitmessagesettings', 'keysencrypted', 'false') + shared.config.set('bitmessagesettings', 'messagesencrypted', 'false') + with open(shared.appdata + 'keys.dat', 'wb') as configfile: + shared.config.write(configfile) + # People running earlier versions of PyBitmessage do not have the # usedpersonally field in their pubkeys table. Let's add it. if shared.config.getint('bitmessagesettings', 'settingsversion') == 2: @@ -158,7 +174,7 @@ class sqlThread(threading.Thread): self.cur.execute( ''' VACUUM ''') # After code refactoring, the possible status values for sent messages - # as changed. + # have changed. self.cur.execute( '''update sent set status='doingmsgpow' where status='doingpow' ''') self.cur.execute( diff --git a/src/helper_startup.py b/src/helper_startup.py index 08f8d48a..e6590b0e 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -76,19 +76,3 @@ def loadConfig(): os.makedirs(shared.appdata) with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) - - if shared.config.getint('bitmessagesettings', 'settingsversion') == 1: - shared.config.set('bitmessagesettings', 'settingsversion', '4') - # If the settings version is equal to 2 or 3 then the - # sqlThread will modify the pubkeys table and change - # the settings version to 4. - shared.config.set('bitmessagesettings', 'socksproxytype', 'none') - shared.config.set('bitmessagesettings', 'sockshostname', 'localhost') - shared.config.set('bitmessagesettings', 'socksport', '9050') - shared.config.set('bitmessagesettings', 'socksauthentication', 'false') - shared.config.set('bitmessagesettings', 'socksusername', '') - shared.config.set('bitmessagesettings', 'sockspassword', '') - shared.config.set('bitmessagesettings', 'keysencrypted', 'false') - shared.config.set('bitmessagesettings', 'messagesencrypted', 'false') - with open(shared.appdata + 'keys.dat', 'wb') as configfile: - shared.config.write(configfile)