-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add buffer size limits to protocol
Currently the largest message we might send is LIST_MESSAGES, which can span up to 16MB (1+3+2^24). With the maximum size of a message being 1100 bytes (33+33+1026), this would require a minimum of 15,253 message objects to be sent. Realistically the server shouldn't come close to this, and is more likely to be sending a few hundred messages at a time. We will use a default buffer size of 1MiB which should be suitable for all practical purposes.
- Loading branch information
1 parent
69ac37b
commit d010df9
Showing
6 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from .errors import BufferOverflowError | ||
|
||
|
||
def extend_limited_buffer( | ||
buffer: bytearray, | ||
data: bytes | bytearray, | ||
*, | ||
limit: int | None, | ||
) -> None: | ||
if limit is None: | ||
buffer.extend(data) | ||
return | ||
|
||
len_buffer, len_data = len(buffer), len(data) | ||
if len_buffer + len_data > limit: | ||
raise BufferOverflowError(limit, len_buffer, len_data) | ||
|
||
buffer.extend(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters