Skip to content

Commit

Permalink
Add fileSizeMax to sender #1285
Browse files Browse the repository at this point in the history
  • Loading branch information
andreleblanc11 committed Nov 5, 2024
1 parent 4a9f642 commit 864e322
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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
7 changes: 6 additions & 1 deletion 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,7 +85,7 @@ 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:
if len(strdata) > self.o.fileSizeMax:
raise Exception(f"Bulletin length too long. Bulletin limit length: {self.o.MaxBulLen}. Latest bulletin length: {len(strdata)}. Path to bulletin: {msg_path}")

## Attach rest of header with NULLs (if not long enough)
Expand Down

0 comments on commit 864e322

Please sign in to comment.