Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fileSizeMax to sender #1285 #1286

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sarracenia/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2829,6 +2829,10 @@ def do_send(self):
self.reject(msg, 422, f"new_file message field missing, do not know name of file to write. skipping." )
continue

if self.o.fileSizeMax > 0 and msg['size'] > self.o.fileSizeMax:
self.reject(msg, 413, f"Payload Too Large {msg.getIDStr()}")
continue

# weed out non-file transfer operations that are configured to not be done.
if 'fileOp' in msg:
if ('directory' in msg['fileOp']) and ('remove' in msg['fileOp']) and ( 'rmdir' not in self.o.fileEvents ):
Expand Down
14 changes: 12 additions & 2 deletions sarracenia/flowcb/send/am.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def __init__(self, options):

self.o.add_option('MaxBulLen', 'count', 32768)

# Get a default value if not set
if self.o.fileSizeMax <= 0:
self.o.fileSizeMax = self.o.MaxBulLen
logger.warning(f"Attributing fileSizeMax, MaxBulLen value : {self.o.MaxBulLen} bytes max")

# Initialise socket
## Create a TCP/IP socket
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down Expand Up @@ -80,8 +85,9 @@ def wrapbulletin(self, sarra_msg):
header = strdata[0:size]

# Step out of the function if the bulletin size is too big
if len(strdata) > self.o.MaxBulLen:
raise Exception(f"Bulletin length too long. Bulletin limit length: {self.o.MaxBulLen}. Latest bulletin length: {len(strdata)}. Path to bulletin: {msg_path}")
if len(strdata) > self.o.fileSizeMax:
logger.error(f"Bulletin length too long. Bulletin limit length: {self.o.fileSizeMax}. Latest bulletin length: {len(strdata)}. Path to bulletin: {msg_path}")
return None

## Attach rest of header with NULLs (if not long enough)
nulheader = ['\0' for _ in range(size)]
Expand Down Expand Up @@ -145,6 +151,10 @@ def send(self, bulletin):
try:
self.packed_bulletin = self.wrapbulletin(bulletin)

# We don't want to send nothing.
if self.packed_bulletin == None:
return False

while True:
try:
bytesSent = self.s.send(self.packed_bulletin)
Expand Down
Loading