#1943: apply suggestions from PR + fixing FTP bug + elaborating

This commit is contained in:
Czar.Echavez
2023-10-09 13:25:12 +01:00
parent 853bb9eecc
commit 318539fd8f
10 changed files with 24 additions and 12 deletions

View File

@@ -264,6 +264,12 @@ class FTPClient(FTPServiceABC):
self.sys_log.error(f"{payload} is not an FTP packet")
return False
"""
Ignore ftp payload if status code is None.
This helps prevent an FTP request loop - FTP client and servers can exist on
the same node.
"""
if payload.status_code is None:
return False

View File

@@ -80,7 +80,11 @@ class FTPServer(FTPServiceABC):
return False
"""
Usually
Ignore ftp payload if status code is defined.
This means that an FTP server has already handled the packet and
prevents an FTP request loop - FTP client and servers can exist on
the same node.
"""
if payload.status_code is not None:
return False

View File

@@ -76,6 +76,7 @@ class FTPServiceABC(Service, ABC):
dest_ip_address: Optional[IPv4Address] = None,
dest_port: Optional[Port] = None,
session_id: Optional[str] = None,
is_response: bool = False,
) -> bool:
"""
Sends data from the host FTP Service's machine to another FTP Service's host machine.
@@ -97,6 +98,9 @@ class FTPServiceABC(Service, ABC):
:param: session_id: session ID linked to the FTP Packet. Optional.
:type: session_id: Optional[str]
:param: is_response: is true if the data being sent is in response to a request. Default False.
:type: is_response: bool
"""
# send STOR request
payload: FTPPacket = FTPPacket(
@@ -108,6 +112,7 @@ class FTPServiceABC(Service, ABC):
"real_file_path": file.sim_path if file.real else None,
},
packet_payload_size=file.sim_size,
status_code=FTPStatusCode.OK if is_response else None,
)
self.sys_log.info(f"{self.name}: Sending file {file.folder.name}/{file.name}")
response = self.send(
@@ -148,6 +153,7 @@ class FTPServiceABC(Service, ABC):
dest_file_name=dest_file_name,
dest_folder_name=dest_folder_name,
session_id=session_id,
is_response=True,
)
except Exception as e:
self.sys_log.error(f"Unable to retrieve file from {self.sys_log.hostname}: {e}")

View File

@@ -35,7 +35,7 @@ class WebServer(Service):
This is usually HTML, CSS, JS or PHP files requested by browsers to display the webpage.
"""
# index HTML main file
self.file_system.create_file(file_name="index.html", folder_name="primaite", real=True)
self.file_system.create_file(file_name="index.html", folder_name="primaite")
def _process_http_request(self, payload: HttpRequestPacket, session_id: Optional[str] = None) -> bool:
"""