some initial work done to support particular android client

This commit is contained in:
Jonathan Warren 2013-08-02 18:35:31 -04:00
parent db31cb4147
commit 17533237fe
4 changed files with 105 additions and 14 deletions

View File

@ -738,6 +738,73 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += json.dumps({'label':label.encode('base64'), 'address': address, 'enabled': enabled == 1}, indent=4, separators=(',',': '))
data += ']}'
return data
elif method == 'disseminatePreEncryptedMsg':
# The device issuing this command to PyBitmessage supplies a msg object that has
# already been encrypted and had the necessary proof of work done for it to be
# disseminated to the rest of the Bitmessage network. PyBitmessage accepts this msg
# object and sends it out to the rest of the Bitmessage network as if it had generated the
# message itself.
if len(params) != 1:
return 'API Error 0000: I need 1 parameter!'
encryptedPayload, = params
inventoryHash = calculateInventoryHash(encryptedPayload)
objectType = 'msg'
shared.inventory[inventoryHash] = (
objectType, toStreamNumber, encryptedPayload, int(time.time()))
with shared.printLock:
print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', inventoryHash.encode('hex')
shared.broadcastToSendDataQueues((
streamNumber, 'sendinv', inventoryHash))
elif method == 'disseminatePubkey':
# The device issuing this command to PyBitmessage supplies a pubkey object that has
# already had the necessary proof of work done for it to be disseminated to the rest of the
# Bitmessage network. PyBitmessage accepts this pubkey object and sends it out to the
# rest of the Bitmessage network, as if it had generated the pubkey object itself.
if len(params) != 1:
return 'API Error 0000: I need 1 parameter!'
payload, = params
inventoryHash = calculateInventoryHash(payload)
objectType = 'pubkey'
shared.inventory[inventoryHash] = (
objectType, streamNumber, payload, int(time.time()))
with shared.printLock:
print 'broadcasting inv within API command disseminatePubkey with hash:', inventoryHash.encode('hex')
shared.broadcastToSendDataQueues((
streamNumber, 'sendinv', inventoryHash))
elif method == 'getMessageDataByDestinationRIPEHash':
# Method will eventually be used by a particular Android app.
if len(params) != 1:
return 'API Error 0000: I need 1 parameter!'
hash, = params
#if len(hash) != 40:
# return 'API Error 0019: The length of hash should be 20 bytes (encoded in hex thus 40 characters).'
print repr(hash)
hash = hash.decode('hex')
print repr(hash)
with shared.sqlLock:
shared.sqlSubmitQueue.put('''PRAGMA case_sensitive_like = true''')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
hash = string.replace(hash,'e','ee')
hash = string.replace(hash,'%','e%')
hash = string.replace(hash,'_','e_')
print 'searching for hash:', repr(hash)
parameters = ('%'+ hash + '%',)
with shared.sqlLock:
shared.sqlSubmitQueue.put('''SELECT payload FROM inventory WHERE hash LIKE ? ESCAPE'e'; ''')
shared.sqlSubmitQueue.put(parameters)
queryreturn = shared.sqlReturnQueue.get()
data = '{"receivedMessageDatas":['
for row in queryreturn:
payload, = row
if len(data) > 25:
data += ','
data += json.dumps({'data':payload.encode('hex')}, indent=4, separators=(',', ': '))
data += ']}'
return data
elif method == 'clientStatus':
return '{ "networkConnections" : "%s" }' % str(len(shared.connectedHostsList))
else:

View File

@ -3290,6 +3290,7 @@ def run():
try:
translator.load("translations/bitmessage_" + str(locale.getdefaultlocale()[0]))
#translator.load("translations/bitmessage_fr_BE") # test French
except:
# The above is not compatible with all versions of OSX.
translator.load("translations/bitmessage_en_US") # Default to english.

View File

@ -189,7 +189,15 @@ class sqlThread(threading.Thread):
if not shared.config.has_option('bitmessagesettings', 'sockslisten'):
shared.config.set('bitmessagesettings', 'sockslisten', 'false')
# Some prewritten code for future use whenever we need to modify the database
"""item = '''SELECT value FROM settings WHERE key='version';'''
parameters = ''
self.cur.execute(item, parameters)
if self.cur.fetchall()[0][0] == 1:
do something
increment the version to 2"""
try:
testpayload = '\x00\x00'
t = ('1234', testpayload, '12345678', 'no')

View File

@ -5,19 +5,10 @@
import sqlite3
from time import strftime, localtime
import sys
import shared
import string
APPNAME = "PyBitmessage"
from os import path, environ
if sys.platform == 'darwin':
if "HOME" in environ:
appdata = path.join(environ["HOME"], "Library/Application support/", APPNAME) + '/'
else:
print 'Could not find home folder, please report this message and your OS X version to the BitMessage Github.'
sys.exit()
elif 'win' in sys.platform:
appdata = path.join(environ['APPDATA'], APPNAME) + '\\'
else:
appdata = path.expanduser(path.join("~", "." + APPNAME + "/"))
appdata = shared.lookupAppdataFolder()
conn = sqlite3.connect( appdata + 'messages.dat' )
conn.text_factory = str
@ -71,6 +62,29 @@ def readInventory():
hash, objecttype, streamnumber, payload, receivedtime = row
print 'Hash:', hash.encode('hex'), objecttype, streamnumber, '\t', payload.encode('hex'), '\t', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(receivedtime)),'utf-8')
def readInventory2():
searchValue = ' '
item = '''PRAGMA case_sensitive_like = true '''
parameters = ''
cur.execute(item, parameters)
searchValue = string.replace(searchValue,'e','ee')
searchValue = string.replace(searchValue,'%','e%')
searchValue = string.replace(searchValue,'_','e_')
print 'Printing subset of inventory table:'
item = '''SELECT * FROM inventory WHERE hash LIKE ? ESCAPE'e'; '''
parameters = ('%'+ searchValue + '%',)
print repr(parameters), len(parameters[0])
cur.execute(item, parameters)
output = cur.fetchall()
print 'Number of results:', len(output)
for row in output[:20]:
hash, objecttype, streamnumber, payload, receivedtime = row
print 'Hash:', hash.encode('hex'), objecttype, streamnumber, '\t', payload.encode('hex'), '\t', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(receivedtime)),'utf-8')
print 'done'
def takeInboxMessagesOutOfTrash():
item = '''update inbox set folder='inbox' where folder='trash' '''
@ -107,12 +121,13 @@ def vacuum():
#takeInboxMessagesOutOfTrash()
#takeSentMessagesOutOfTrash()
#markAllInboxMessagesAsUnread()
readInbox()
#readInbox()
#readSent()
#readPubkeys()
#readSubscriptions()
#readInventory()
#vacuum() #will defragment and clean empty space from the messages.dat file.
readInventory2()