max request size
This commit is contained in:
parent
46d89929ba
commit
65e74281e0
1 changed files with 11 additions and 0 deletions
|
@ -12,6 +12,9 @@ if typing.TYPE_CHECKING:
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# a standard request will be 295 bytes
|
||||||
|
MAX_REQUEST_SIZE = 1200
|
||||||
|
|
||||||
|
|
||||||
class BlobServerProtocol(asyncio.Protocol):
|
class BlobServerProtocol(asyncio.Protocol):
|
||||||
def __init__(self, loop: asyncio.AbstractEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str):
|
def __init__(self, loop: asyncio.AbstractEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str):
|
||||||
|
@ -24,6 +27,10 @@ class BlobServerProtocol(asyncio.Protocol):
|
||||||
self.lbrycrd_address = lbrycrd_address
|
self.lbrycrd_address = lbrycrd_address
|
||||||
self.peer_address_and_port: typing.Optional[str] = None
|
self.peer_address_and_port: typing.Optional[str] = None
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
if self.transport:
|
||||||
|
self.transport.close()
|
||||||
|
|
||||||
def connection_made(self, transport):
|
def connection_made(self, transport):
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
self.peer_address_and_port = "%s:%i" % self.transport.get_extra_info('peername')
|
self.peer_address_and_port = "%s:%i" % self.transport.get_extra_info('peername')
|
||||||
|
@ -79,6 +86,10 @@ class BlobServerProtocol(asyncio.Protocol):
|
||||||
|
|
||||||
def data_received(self, data):
|
def data_received(self, data):
|
||||||
request = None
|
request = None
|
||||||
|
if len(self.buf) + len(data or b'') >= MAX_REQUEST_SIZE:
|
||||||
|
log.warning("request from %s is too large", self.peer_address_and_port)
|
||||||
|
self.close()
|
||||||
|
return
|
||||||
if data:
|
if data:
|
||||||
self.blob_manager.connection_manager.received_data(self.peer_address_and_port, len(data))
|
self.blob_manager.connection_manager.received_data(self.peer_address_and_port, len(data))
|
||||||
message, separator, remainder = data.rpartition(b'}')
|
message, separator, remainder = data.rpartition(b'}')
|
||||||
|
|
Loading…
Add table
Reference in a new issue