From 40033d9e87d0bb821b34cbf6291c0d769d969276 Mon Sep 17 00:00:00 2001 From: Amos Bairn Date: Wed, 11 Sep 2013 23:04:16 -0700 Subject: [PATCH 1/4] add api method addChan This solves issue #484 --- src/bitmessagemain.py | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 88538297..413ae481 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -384,6 +384,70 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): ('getDeterministicAddress', addressVersionNumber, streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe)) return shared.apiAddressGeneratorReturnQueue.get() + elif method == 'addChan': + #get passphrase, addressVersionNumber, and streamNumber + if len(params) == 0: + raise APIError(0, 'I need parameters.') + elif len(params) == 1: + passphrase, = params + address = '' + addressVersionNumber = 0 + streamNumber = 0 + label = '' + elif len(params) == 2: + passphrase, address = params + status, addressVersionNumber, streamNumber, ripe = decodeAddress(address) + label = '' + elif len(params) == 3: + passphrase, addressVersionNumber, streamNumber = params + address = '' + label = '' + elif len(params) == 4: + passphrase, addressVersionNumber, streamNumber, label = params + address = '' + label = self._decode(label, "base64") + else: + raise APIError(0, 'Too many parameters!') + + if len(passphrase) == 0: + raise APIError(1, 'The specified passphrase is blank.') + passphrase = self._decode(passphrase, "base64") + if label == '': + label = '[chan] ' + passphrase + if addressVersionNumber == 0: # 0 means "just use the proper addressVersionNumber" + addressVersionNumber = 3 + if addressVersionNumber != 3: + raise APIError(2,'The address version number currently must be 3 (or 0 which means auto-select). ' + addressVersionNumber + ' isn\'t supported.') + if streamNumber == 0: # 0 means "just use the most available stream" + streamNumber = 1 + if streamNumber != 1: + raise APIError(3,'The stream number must be 1 (or 0 which means auto-select). Others aren\'t supported.') + + #create identity + shared.apiAddressGeneratorReturnQueue.queue.clear() + logger.debug('Requesting that the addressGenerator create chan %s.', passphrase) + shared.addressGeneratorQueue.put(('createChan', addressVersionNumber, streamNumber, label, passphrase)) + queueReturn = shared.apiAddressGeneratorReturnQueue.get() + if len(queueReturn) == 0: + raise APIError(24, 'Chan address already present.') + createdAddress = queueReturn[0] + if address == '': + address = createdAddress + elif createdAddress != address: + raise APIError(18, 'Chan name does not match address.') + + #add address to addressbook + address = addBMIfNotPresent(address) + self._verifyAddress(address) + queryreturn = sqlQuery("SELECT address FROM addressbook WHERE address=?", address) + if queryreturn != []: + raise APIError(16, 'You already have this address in your address book.') + + sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address) + shared.UISignalQueue.put(('rerenderInboxFromLabels','')) + shared.UISignalQueue.put(('rerenderSentToLabels','')) + shared.UISignalQueue.put(('rerenderAddressBook','')) + return "Added chan %s with address %s and label %s." %(passphrase, address, label) elif method == 'getAllInboxMessages': queryreturn = sqlQuery( '''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox where folder='inbox' ORDER BY received''') From cdf4d5d75cbc663ad9ca47e9e631157f066aeec5 Mon Sep 17 00:00:00 2001 From: amos Date: Mon, 23 Sep 2013 21:05:11 -0700 Subject: [PATCH 2/4] Change the accepted address versions Update _verifyAddress to accept version 4. --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 3d7f5c73..4e473c85 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -166,7 +166,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): raise APIError(10, 'Address version number too high (or zero) in address: ' + address) raise APIError(7, 'Could not decode address: ' + address + ' : ' + status) if addressVersionNumber < 2 or addressVersionNumber > 3: - raise APIError(11, 'The address version number currently must be 2 or 3. Others aren\'t supported. Check the address.') + raise APIError(11, 'The address version number currently must be 2, 3 or 4. Others aren\'t supported. Check the address.') if streamNumber != 1: raise APIError(12, 'The stream number must be 1. Others aren\'t supported. Check the address.') From e878fb4c96f983b9b6fa426b3bc15a5aacd56a9c Mon Sep 17 00:00:00 2001 From: amos Date: Mon, 23 Sep 2013 22:35:20 -0700 Subject: [PATCH 3/4] Add api method decodeAddress Add decodeAddress as an api call. Like the addresses.decodeAddress function it return status, addressVersion, streamNumber, and ripe. ripe is base64 encoded. --- src/bitmessagemain.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 47925a46..2e7bb9af 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -818,6 +818,15 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): else: networkStatus = 'connectedAndReceivingIncomingConnections' return json.dumps({'networkConnections':len(shared.connectedHostsList),'numberOfMessagesProcessed':shared.numberOfMessagesProcessed, 'numberOfBroadcastsProcessed':shared.numberOfBroadcastsProcessed, 'numberOfPubkeysProcessed':shared.numberOfPubkeysProcessed, 'networkStatus':networkStatus, 'softwareName':'PyBitmessage','softwareVersion':shared.softwareVersion}, indent=4, separators=(',', ': ')) + elif method == 'decodeAddress': + #decode an address + if len(params) != 1: + raise APIError(0, 'I need 1 parameter!') + address, = params + status, addressVersion, streamNumber, ripe = decodeAddress(address) + return json.dumps({'status':status, 'addressVersion':addressVersion, + 'streamNumber':streamNumber, 'ripe':ripe.encode('base64')}, indent=4, + separators=(',', ': ')) else: raise APIError(20, 'Invalid method: %s' % method) From 379d27b5d8ce2593c4979e8219cb609de8ab44f6 Mon Sep 17 00:00:00 2001 From: amos Date: Mon, 23 Sep 2013 23:00:50 -0700 Subject: [PATCH 4/4] update address versions in addChan --- src/bitmessagemain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 76a4e53c..98760deb 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -418,9 +418,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if label == '': label = '[chan] ' + passphrase if addressVersionNumber == 0: # 0 means "just use the proper addressVersionNumber" - addressVersionNumber = 3 - if addressVersionNumber != 3: - raise APIError(2,'The address version number currently must be 3 (or 0 which means auto-select). ' + addressVersionNumber + ' isn\'t supported.') + addressVersionNumber = 4 + if addressVersionNumber != 3 and addressVersionNumber != 4: + raise APIError(2,'The address version number currently must be 3 or 4 (or 0 which means auto-select). ' + addressVersionNumber + ' isn\'t supported.') if streamNumber == 0: # 0 means "just use the most available stream" streamNumber = 1 if streamNumber != 1: