Define stream number validity
This commit is contained in:
parent
bb7d8018c6
commit
69e540b504
|
@ -36,6 +36,12 @@ class BMObjectUnwantedStreamError(Exception):
|
||||||
errorCodes = ("Object in unwanted stream")
|
errorCodes = ("Object in unwanted stream")
|
||||||
|
|
||||||
|
|
||||||
|
class BMObjectInvalidStreamError(Exception):
|
||||||
|
"""Exception indicating the object is in a stream
|
||||||
|
outside of specification."""
|
||||||
|
errorCodes = ("Object in invalid stream")
|
||||||
|
|
||||||
|
|
||||||
class BMObjectInvalidError(Exception):
|
class BMObjectInvalidError(Exception):
|
||||||
"""The object's data does not match object specification."""
|
"""The object's data does not match object specification."""
|
||||||
errorCodes = ("Invalid object")
|
errorCodes = ("Invalid object")
|
||||||
|
@ -106,6 +112,9 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
|
||||||
'The streamNumber %i isn\'t one we are interested in.',
|
'The streamNumber %i isn\'t one we are interested in.',
|
||||||
self.streamNumber)
|
self.streamNumber)
|
||||||
raise BMObjectUnwantedStreamError()
|
raise BMObjectUnwantedStreamError()
|
||||||
|
if self.streamNumber < protocol.MIN_VALID_STREAM \
|
||||||
|
or self.streamNumber > protocol.MAX_VALID_STREAM:
|
||||||
|
raise BMObjectInvalidStreamError()
|
||||||
|
|
||||||
def checkAlreadyHave(self):
|
def checkAlreadyHave(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -22,7 +22,8 @@ from network.advanceddispatcher import AdvancedDispatcher
|
||||||
from network.bmobject import (
|
from network.bmobject import (
|
||||||
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
|
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
|
||||||
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
|
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
|
||||||
BMObjectInvalidError, BMObjectUnwantedStreamError
|
BMObjectInvalidError, BMObjectUnwantedStreamError,
|
||||||
|
BMObjectInvalidStreamError
|
||||||
)
|
)
|
||||||
from network.constants import (
|
from network.constants import (
|
||||||
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
|
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
|
||||||
|
@ -409,6 +410,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
self.object.inventoryHash, acceptmismatch)
|
self.object.inventoryHash, acceptmismatch)
|
||||||
if not acceptmismatch:
|
if not acceptmismatch:
|
||||||
raise
|
raise
|
||||||
|
except BMObjectInvalidStreamError:
|
||||||
|
BMProto.stopDownloadingObject(
|
||||||
|
self.object.inventoryHash)
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.object.checkObjectByType()
|
self.object.checkObjectByType()
|
||||||
|
|
|
@ -90,6 +90,11 @@ def isBitSetWithinBitfield(fourByteString, n):
|
||||||
x, = unpack('>L', fourByteString)
|
x, = unpack('>L', fourByteString)
|
||||||
return x & 2**n != 0
|
return x & 2**n != 0
|
||||||
|
|
||||||
|
# Streams
|
||||||
|
|
||||||
|
|
||||||
|
MIN_VALID_STREAM = 1
|
||||||
|
MAX_VALID_STREAM = 2**63 - 1
|
||||||
|
|
||||||
# IP addresses
|
# IP addresses
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user