Skip to content

Commit

Permalink
Remove result if it's too large
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Aug 18, 2024
1 parent 7789b44 commit 256fe31
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/donate-cpu-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,8 @@ def read_data(connection, cmd, pos_nl, max_data_size, check_done, cmd_name, time

if data and (len(data) >= max_data_size):
print_ts('Maximum allowed data ({} bytes) exceeded ({}).'.format(max_data_size, cmd_name))
data = None

if data and check_done and not data.endswith('\nDONE'):
elif data and check_done and not data.endswith('\nDONE'):
print_ts('Incomplete data received ({}).'.format(cmd_name))
data = None

Expand Down Expand Up @@ -1334,9 +1333,10 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
continue
elif cmd.startswith('write\nftp://') or cmd.startswith('write\nhttp://'):
t_start = time.perf_counter()
data = read_data(connection, cmd, pos_nl, max_data_size=10 * 1024 * 1024, check_done=True, cmd_name='write')
data = read_data(connection, cmd, pos_nl, max_data_size=1024 * 1024, check_done=True, cmd_name='write')
if data is None:
continue
truncated_data = len(data) >= 1024 * 1024

pos = data.find('\n')
if pos == -1:
Expand Down Expand Up @@ -1376,6 +1376,10 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
print_ts('Unexpected old version. Ignoring result data.')
continue
filename = os.path.join(resultPath, res.group(1))
if truncated_data:
print_ts('Data is too large. Removing result.')
os.remove(filename)
continue
with open(filename, 'wt') as f:
f.write(strDateTime() + '\n' + data)
# track latest added results..
Expand All @@ -1393,6 +1397,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
data = read_data(connection, cmd, pos_nl, max_data_size=7 * 1024 * 1024, check_done=True, cmd_name='write_info')
if data is None:
continue
truncated_data = len(data) >= 7 * 1024 * 1024

pos = data.find('\n')
if pos == -1:
Expand All @@ -1418,6 +1423,10 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
if not os.path.exists(info_path):
os.mkdir(info_path)
filename = info_path + '/' + res.group(1)
if truncated_data:
print_ts('Data is too large. Removing result.')
os.remove(filename)
continue
with open(filename, 'wt') as f:
f.write(strDateTime() + '\n' + data)
print_ts('write_info finished for {} ({} bytes / {}s)'.format(res.group(1), len(data), (time.perf_counter() - t_start)))
Expand Down

0 comments on commit 256fe31

Please sign in to comment.