Maximum message length configurable within keys.dat

This commit is contained in:
Bob Mottram 2013-08-03 12:45:15 +01:00
parent 7606106096
commit 3063c256d4
3 changed files with 14 additions and 2 deletions

View File

@ -46,6 +46,17 @@ class receiveDataThread(threading.Thread):
self.PORT = port self.PORT = port
self.streamNumber = streamNumber self.streamNumber = streamNumber
self.payloadLength = 0 # This is the protocol payload length thus it doesn't include the 24 byte message header self.payloadLength = 0 # This is the protocol payload length thus it doesn't include the 24 byte message header
self.maxMessageLength = 180000000 # maximum length of a message in bytes, default 180MB
# get the maximum message length from the settings
try:
maxMsgLen = shared.config.getint(
'bitmessagesettings', 'maxmessagelength')
if maxMsgLen > 32768: # minimum of 32K
self.maxMessageLength = maxMsgLen
except Exception:
pass
self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave = {} self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave = {}
self.selfInitiatedConnections = selfInitiatedConnections self.selfInitiatedConnections = selfInitiatedConnections
shared.connectedHostsList[ shared.connectedHostsList[
@ -140,7 +151,7 @@ class receiveDataThread(threading.Thread):
shared.knownNodes[self.streamNumber][ shared.knownNodes[self.streamNumber][
self.HOST] = (self.PORT, int(time.time())) self.HOST] = (self.PORT, int(time.time()))
shared.knownNodesLock.release() shared.knownNodesLock.release()
if self.payloadLength <= 180000000: # If the size of the message is greater than 180MB, ignore it. (I get memory errors when processing messages much larger than this though it is concievable that this value will have to be lowered if some systems are less tolarant of large messages.) if self.payloadLength <= self.maxMessageLength: # If the size of the message is greater than the maximum, ignore it.
remoteCommand = self.data[4:16] remoteCommand = self.data[4:16]
with shared.printLock: with shared.printLock:
print 'remoteCommand', repr(remoteCommand.replace('\x00', '')), ' from', self.HOST print 'remoteCommand', repr(remoteCommand.replace('\x00', '')), ' from', self.HOST

View File

@ -67,6 +67,7 @@ def loadConfig():
shared.config.set( shared.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0') 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
shared.config.set('bitmessagesettings', 'dontconnect', 'true') shared.config.set('bitmessagesettings', 'dontconnect', 'true')
shared.config.set('bitmessagesettings', 'maxMessageLength', '180000000')
if storeConfigFilesInSameDirectoryAsProgramByDefault: if storeConfigFilesInSameDirectoryAsProgramByDefault:
# Just use the same directory as the program and forget about # Just use the same directory as the program and forget about

View File

@ -371,4 +371,4 @@ def fixSensitiveFilePermissions(filename, hasEnabledKeys):
raise raise
helper_startup.loadConfig() helper_startup.loadConfig()
from debug import logger from debug import logger