Enable support for extended encoding
- receiving extended encoding now works - sending works from the GUI by pressing "Shift" while clicking on "Send" - requires https://pypi.python.org/pypi/msgpack-python
This commit is contained in:
parent
966b4382d8
commit
612333a267
|
@ -1890,6 +1890,8 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
more work your computer must do to send the message. A Time-To-Live of four or five days is often appropriate."""), QMessageBox.Ok)
|
more work your computer must do to send the message. A Time-To-Live of four or five days is often appropriate."""), QMessageBox.Ok)
|
||||||
|
|
||||||
def click_pushButtonSend(self):
|
def click_pushButtonSend(self):
|
||||||
|
encoding = 3 if QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier else 2
|
||||||
|
|
||||||
self.statusBar().clearMessage()
|
self.statusBar().clearMessage()
|
||||||
|
|
||||||
if self.ui.tabWidgetSend.currentIndex() == 0:
|
if self.ui.tabWidgetSend.currentIndex() == 0:
|
||||||
|
@ -2022,7 +2024,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
'msgqueued',
|
'msgqueued',
|
||||||
0, # retryNumber
|
0, # retryNumber
|
||||||
'sent', # folder
|
'sent', # folder
|
||||||
2, # encodingtype
|
encoding, # encodingtype
|
||||||
shared.config.getint('bitmessagesettings', 'ttl')
|
shared.config.getint('bitmessagesettings', 'ttl')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2075,7 +2077,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
'broadcastqueued',
|
'broadcastqueued',
|
||||||
0, # retryNumber
|
0, # retryNumber
|
||||||
'sent', # folder
|
'sent', # folder
|
||||||
2, # encoding type
|
encoding, # encoding type
|
||||||
shared.config.getint('bitmessagesettings', 'ttl')
|
shared.config.getint('bitmessagesettings', 'ttl')
|
||||||
)
|
)
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
|
|
|
@ -17,6 +17,7 @@ import helper_generic
|
||||||
from helper_generic import addDataPadding
|
from helper_generic import addDataPadding
|
||||||
import helper_bitcoin
|
import helper_bitcoin
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
|
import helper_msgcoding
|
||||||
import helper_sent
|
import helper_sent
|
||||||
from helper_sql import *
|
from helper_sql import *
|
||||||
import tr
|
import tr
|
||||||
|
@ -482,24 +483,15 @@ class objectProcessor(threading.Thread):
|
||||||
if queryreturn == []:
|
if queryreturn == []:
|
||||||
logger.info('Message ignored because address not in whitelist.')
|
logger.info('Message ignored because address not in whitelist.')
|
||||||
blockMessage = True
|
blockMessage = True
|
||||||
|
|
||||||
toLabel = shared.config.get(toAddress, 'label')
|
toLabel = shared.config.get(toAddress, 'label')
|
||||||
if toLabel == '':
|
if toLabel == '':
|
||||||
toLabel = toAddress
|
toLabel = toAddress
|
||||||
|
|
||||||
if messageEncodingType == 2:
|
decodedMessage = helper_msgcoding.MsgDecode(messageEncodingType, message)
|
||||||
subject, body = self.decodeType2Message(message)
|
subject = decodedMessage.subject
|
||||||
logger.info('Message subject (first 100 characters): %s' % repr(subject)[:100])
|
body = decodedMessage.body
|
||||||
elif messageEncodingType == 1:
|
|
||||||
body = message
|
|
||||||
subject = ''
|
|
||||||
elif messageEncodingType == 0:
|
|
||||||
logger.info('messageEncodingType == 0. Doing nothing with the message. They probably just sent it so that we would store their public key or send their ack data for them.')
|
|
||||||
subject = ''
|
|
||||||
body = ''
|
|
||||||
else:
|
|
||||||
body = 'Unknown encoding type.\n\n' + repr(message)
|
|
||||||
subject = ''
|
|
||||||
# Let us make sure that we haven't already received this message
|
# Let us make sure that we haven't already received this message
|
||||||
if helper_inbox.isMessageAlreadyInInbox(sigHash):
|
if helper_inbox.isMessageAlreadyInInbox(sigHash):
|
||||||
logger.info('This msg is already in our inbox. Ignoring it.')
|
logger.info('This msg is already in our inbox. Ignoring it.')
|
||||||
|
@ -562,7 +554,7 @@ class objectProcessor(threading.Thread):
|
||||||
'broadcastqueued',
|
'broadcastqueued',
|
||||||
0,
|
0,
|
||||||
'sent',
|
'sent',
|
||||||
2,
|
messageEncodingType,
|
||||||
TTL)
|
TTL)
|
||||||
helper_sent.insert(t)
|
helper_sent.insert(t)
|
||||||
|
|
||||||
|
@ -746,18 +738,9 @@ class objectProcessor(threading.Thread):
|
||||||
sendersAddressVersion, sendersStream, calculatedRipe)
|
sendersAddressVersion, sendersStream, calculatedRipe)
|
||||||
logger.debug('fromAddress: ' + fromAddress)
|
logger.debug('fromAddress: ' + fromAddress)
|
||||||
|
|
||||||
if messageEncodingType == 2:
|
decodedMessage = helper_msgcoding.MsgDecode(messageEncodingType, message)
|
||||||
subject, body = self.decodeType2Message(message)
|
subject = decodedMessage.subject
|
||||||
logger.info('Broadcast subject (first 100 characters): %s' % repr(subject)[:100])
|
body = decodedMessage.body
|
||||||
elif messageEncodingType == 1:
|
|
||||||
body = message
|
|
||||||
subject = ''
|
|
||||||
elif messageEncodingType == 0:
|
|
||||||
logger.info('messageEncodingType == 0. Doing nothing with the message.')
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
body = 'Unknown encoding type.\n\n' + repr(message)
|
|
||||||
subject = ''
|
|
||||||
|
|
||||||
toAddress = '[Broadcast subscribers]'
|
toAddress = '[Broadcast subscribers]'
|
||||||
if helper_inbox.isMessageAlreadyInInbox(sigHash):
|
if helper_inbox.isMessageAlreadyInInbox(sigHash):
|
||||||
|
|
|
@ -15,6 +15,7 @@ from debug import logger
|
||||||
from helper_sql import *
|
from helper_sql import *
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
from helper_generic import addDataPadding
|
from helper_generic import addDataPadding
|
||||||
|
import helper_msgcoding
|
||||||
from helper_threading import *
|
from helper_threading import *
|
||||||
import l10n
|
import l10n
|
||||||
from protocol import *
|
from protocol import *
|
||||||
|
@ -370,10 +371,10 @@ class singleWorker(threading.Thread, StoppableThread):
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'''UPDATE sent SET status='broadcastqueued' WHERE status = 'doingbroadcastpow' ''')
|
'''UPDATE sent SET status='broadcastqueued' WHERE status = 'doingbroadcastpow' ''')
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''SELECT fromaddress, subject, message, ackdata, ttl FROM sent WHERE status=? and folder='sent' ''', 'broadcastqueued')
|
'''SELECT fromaddress, subject, message, ackdata, ttl, encodingtype FROM sent WHERE status=? and folder='sent' ''', 'broadcastqueued')
|
||||||
|
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
fromaddress, subject, body, ackdata, TTL = row
|
fromaddress, subject, body, ackdata, TTL, encoding = row
|
||||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
||||||
fromaddress)
|
fromaddress)
|
||||||
if addressVersionNumber <= 1:
|
if addressVersionNumber <= 1:
|
||||||
|
@ -436,9 +437,10 @@ class singleWorker(threading.Thread, StoppableThread):
|
||||||
if addressVersionNumber >= 3:
|
if addressVersionNumber >= 3:
|
||||||
dataToEncrypt += encodeVarint(shared.config.getint(fromaddress,'noncetrialsperbyte'))
|
dataToEncrypt += encodeVarint(shared.config.getint(fromaddress,'noncetrialsperbyte'))
|
||||||
dataToEncrypt += encodeVarint(shared.config.getint(fromaddress,'payloadlengthextrabytes'))
|
dataToEncrypt += encodeVarint(shared.config.getint(fromaddress,'payloadlengthextrabytes'))
|
||||||
dataToEncrypt += '\x02' # message encoding type
|
dataToEncrypt += encodeVarint(encoding) # message encoding type
|
||||||
dataToEncrypt += encodeVarint(len('Subject:' + subject + '\n' + 'Body:' + body)) #Type 2 is simple UTF-8 message encoding per the documentation on the wiki.
|
encodedMessage = helper_msgcoding.MsgEncode({"subject": subject, "body": body}, encoding)
|
||||||
dataToEncrypt += 'Subject:' + subject + '\n' + 'Body:' + body
|
dataToEncrypt += encodeVarint(encodedMessage.length)
|
||||||
|
dataToEncrypt += encodedMessage.data
|
||||||
dataToSign = payload + dataToEncrypt
|
dataToSign = payload + dataToEncrypt
|
||||||
|
|
||||||
signature = highlevelcrypto.sign(
|
signature = highlevelcrypto.sign(
|
||||||
|
@ -503,9 +505,9 @@ class singleWorker(threading.Thread, StoppableThread):
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'''UPDATE sent SET status='msgqueued' WHERE status IN ('doingpubkeypow', 'doingmsgpow')''')
|
'''UPDATE sent SET status='msgqueued' WHERE status IN ('doingpubkeypow', 'doingmsgpow')''')
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''SELECT toaddress, fromaddress, subject, message, ackdata, status, ttl, retrynumber FROM sent WHERE (status='msgqueued' or status='forcepow') and folder='sent' ''')
|
'''SELECT toaddress, fromaddress, subject, message, ackdata, status, ttl, retrynumber, encodingtype FROM sent WHERE (status='msgqueued' or status='forcepow') and folder='sent' ''')
|
||||||
for row in queryreturn: # while we have a msg that needs some work
|
for row in queryreturn: # while we have a msg that needs some work
|
||||||
toaddress, fromaddress, subject, message, ackdata, status, TTL, retryNumber = row
|
toaddress, fromaddress, subject, message, ackdata, status, TTL, retryNumber, encoding = row
|
||||||
toStatus, toAddressVersionNumber, toStreamNumber, toRipe = decodeAddress(
|
toStatus, toAddressVersionNumber, toStreamNumber, toRipe = decodeAddress(
|
||||||
toaddress)
|
toaddress)
|
||||||
fromStatus, fromAddressVersionNumber, fromStreamNumber, fromRipe = decodeAddress(
|
fromStatus, fromAddressVersionNumber, fromStreamNumber, fromRipe = decodeAddress(
|
||||||
|
@ -751,11 +753,10 @@ class singleWorker(threading.Thread, StoppableThread):
|
||||||
fromaddress, 'payloadlengthextrabytes'))
|
fromaddress, 'payloadlengthextrabytes'))
|
||||||
|
|
||||||
payload += toRipe # This hash will be checked by the receiver of the message to verify that toRipe belongs to them. This prevents a Surreptitious Forwarding Attack.
|
payload += toRipe # This hash will be checked by the receiver of the message to verify that toRipe belongs to them. This prevents a Surreptitious Forwarding Attack.
|
||||||
payload += '\x02' # Type 2 is simple UTF-8 message encoding as specified on the Protocol Specification on the Bitmessage Wiki.
|
payload += encodeVarint(encoding) # message encoding type
|
||||||
messageToTransmit = 'Subject:' + \
|
encodedMessage = helper_msgcoding.MsgEncode({"subject": subject, "body": message}, encoding)
|
||||||
subject + '\n' + 'Body:' + message
|
payload += encodeVarint(encodedMessage.length)
|
||||||
payload += encodeVarint(len(messageToTransmit))
|
payload += encodedMessage.data
|
||||||
payload += messageToTransmit
|
|
||||||
if shared.config.has_section(toaddress):
|
if shared.config.has_section(toaddress):
|
||||||
logger.info('Not bothering to include ackdata because we are sending to ourselves or a chan.')
|
logger.info('Not bothering to include ackdata because we are sending to ourselves or a chan.')
|
||||||
fullAckPayload = ''
|
fullAckPayload = ''
|
||||||
|
|
Reference in New Issue
Block a user