@@ -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 )
0 commit comments