some initial work done to support particular android client
This commit is contained in:
parent
db31cb4147
commit
17533237fe
|
@ -738,6 +738,73 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
data += json.dumps({'label':label.encode('base64'), 'address': address, 'enabled': enabled == 1}, indent=4, separators=(',',': '))
|
data += json.dumps({'label':label.encode('base64'), 'address': address, 'enabled': enabled == 1}, indent=4, separators=(',',': '))
|
||||||
data += ']}'
|
data += ']}'
|
||||||
return 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':
|
elif method == 'clientStatus':
|
||||||
return '{ "networkConnections" : "%s" }' % str(len(shared.connectedHostsList))
|
return '{ "networkConnections" : "%s" }' % str(len(shared.connectedHostsList))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3290,6 +3290,7 @@ def run():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
translator.load("translations/bitmessage_" + str(locale.getdefaultlocale()[0]))
|
translator.load("translations/bitmessage_" + str(locale.getdefaultlocale()[0]))
|
||||||
|
#translator.load("translations/bitmessage_fr_BE") # test French
|
||||||
except:
|
except:
|
||||||
# The above is not compatible with all versions of OSX.
|
# The above is not compatible with all versions of OSX.
|
||||||
translator.load("translations/bitmessage_en_US") # Default to english.
|
translator.load("translations/bitmessage_en_US") # Default to english.
|
||||||
|
|
|
@ -190,6 +190,14 @@ class sqlThread(threading.Thread):
|
||||||
if not shared.config.has_option('bitmessagesettings', 'sockslisten'):
|
if not shared.config.has_option('bitmessagesettings', 'sockslisten'):
|
||||||
shared.config.set('bitmessagesettings', 'sockslisten', 'false')
|
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:
|
try:
|
||||||
testpayload = '\x00\x00'
|
testpayload = '\x00\x00'
|
||||||
t = ('1234', testpayload, '12345678', 'no')
|
t = ('1234', testpayload, '12345678', 'no')
|
||||||
|
|
|
@ -5,19 +5,10 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from time import strftime, localtime
|
from time import strftime, localtime
|
||||||
import sys
|
import sys
|
||||||
|
import shared
|
||||||
|
import string
|
||||||
|
|
||||||
APPNAME = "PyBitmessage"
|
appdata = shared.lookupAppdataFolder()
|
||||||
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 + "/"))
|
|
||||||
|
|
||||||
conn = sqlite3.connect( appdata + 'messages.dat' )
|
conn = sqlite3.connect( appdata + 'messages.dat' )
|
||||||
conn.text_factory = str
|
conn.text_factory = str
|
||||||
|
@ -71,6 +62,29 @@ def readInventory():
|
||||||
hash, objecttype, streamnumber, payload, receivedtime = row
|
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 '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():
|
def takeInboxMessagesOutOfTrash():
|
||||||
item = '''update inbox set folder='inbox' where folder='trash' '''
|
item = '''update inbox set folder='inbox' where folder='trash' '''
|
||||||
|
@ -107,12 +121,13 @@ def vacuum():
|
||||||
#takeInboxMessagesOutOfTrash()
|
#takeInboxMessagesOutOfTrash()
|
||||||
#takeSentMessagesOutOfTrash()
|
#takeSentMessagesOutOfTrash()
|
||||||
#markAllInboxMessagesAsUnread()
|
#markAllInboxMessagesAsUnread()
|
||||||
readInbox()
|
#readInbox()
|
||||||
#readSent()
|
#readSent()
|
||||||
#readPubkeys()
|
#readPubkeys()
|
||||||
#readSubscriptions()
|
#readSubscriptions()
|
||||||
#readInventory()
|
#readInventory()
|
||||||
#vacuum() #will defragment and clean empty space from the messages.dat file.
|
#vacuum() #will defragment and clean empty space from the messages.dat file.
|
||||||
|
readInventory2()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user