From 7fc49196d7e14358494a493c8c6198e0cdce6d53 Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Tue, 5 Apr 2022 14:03:26 +0000 Subject: [PATCH] Agent: Extract proxy timeout to const, change it to 2.5 --- monkey/infection_monkey/transport/base.py | 1 + monkey/infection_monkey/transport/http.py | 8 ++++++-- monkey/infection_monkey/transport/tcp.py | 12 ++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/transport/base.py b/monkey/infection_monkey/transport/base.py index 77be3f3af..f61f7b115 100644 --- a/monkey/infection_monkey/transport/base.py +++ b/monkey/infection_monkey/transport/base.py @@ -2,6 +2,7 @@ import time from threading import Thread g_last_served = None +PROXY_TIMEOUT = 2.5 class TransportProxyBase(Thread): diff --git a/monkey/infection_monkey/transport/http.py b/monkey/infection_monkey/transport/http.py index 49272481f..63aaa0b36 100644 --- a/monkey/infection_monkey/transport/http.py +++ b/monkey/infection_monkey/transport/http.py @@ -7,7 +7,11 @@ from logging import getLogger from urllib.parse import urlsplit from infection_monkey.network.tools import get_interface_to_target -from infection_monkey.transport.base import TransportProxyBase, update_last_serve_time +from infection_monkey.transport.base import ( + PROXY_TIMEOUT, + TransportProxyBase, + update_last_serve_time, +) logger = getLogger(__name__) @@ -227,6 +231,6 @@ class LockedHTTPServer(threading.Thread): class HTTPConnectProxy(TransportProxyBase): def run(self): httpd = http.server.HTTPServer((self.local_host, self.local_port), HTTPConnectProxyHandler) - httpd.timeout = 10 + httpd.timeout = PROXY_TIMEOUT while not self._stopped: httpd.handle_request() diff --git a/monkey/infection_monkey/transport/tcp.py b/monkey/infection_monkey/transport/tcp.py index 500dc2a22..83c631c3b 100644 --- a/monkey/infection_monkey/transport/tcp.py +++ b/monkey/infection_monkey/transport/tcp.py @@ -3,16 +3,20 @@ import socket from logging import getLogger from threading import Thread -from infection_monkey.transport.base import TransportProxyBase, update_last_serve_time +from infection_monkey.transport.base import ( + PROXY_TIMEOUT, + TransportProxyBase, + update_last_serve_time, +) READ_BUFFER_SIZE = 8192 -DEFAULT_TIMEOUT = 10 +SOCKET_READ_TIMEOUT = 10 logger = getLogger(__name__) class SocketsPipe(Thread): - def __init__(self, source, dest, timeout=DEFAULT_TIMEOUT): + def __init__(self, source, dest, timeout=SOCKET_READ_TIMEOUT): Thread.__init__(self) self.source = source self.dest = dest @@ -51,7 +55,7 @@ class TcpProxy(TransportProxyBase): pipes = [] l_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) l_socket.bind((self.local_host, self.local_port)) - l_socket.settimeout(DEFAULT_TIMEOUT) + l_socket.settimeout(PROXY_TIMEOUT) l_socket.listen(5) while not self._stopped: