Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 6, 2024
1 parent bcf4fd6 commit 0fab8a6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions pytcp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"tcp",
"socket",
"tcp-ss",
"dhcp4",
"service",
"client",
}
Expand Down
35 changes: 29 additions & 6 deletions pytcp/protocols/dhcp4/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def fetch(self) -> Ip4Host | None:
dhcp_host_name="PyTCP",
).raw_packet
)
__debug__ and log("dhcp4", "Sent out DHCP Discover message")
__debug__ and log(
"dhcp4", "Sent out DHCP Discover message to 255.255.255.255"
)

# Wait for DHCP Offer
try:
Expand All @@ -121,13 +123,24 @@ def fetch(self) -> Ip4Host | None:

dhcp_srv_id = dhcp_packet_rx.dhcp_srv_id
dhcp_yiaddr = dhcp_packet_rx.dhcp_yiaddr

dhcp_router_log = (
None
if dhcp_packet_rx.dhcp_router is None
else (
", ".join(
str(address) for address in dhcp_packet_rx.dhcp_router
)
)
)

__debug__ and log(
"dhcp4",
f"ClientUdpDhcp: Received DHCP Offer from "
f"{dhcp_packet_rx.dhcp_srv_id}"
f"Received DHCP Offer from "
f"{dhcp_packet_rx.dhcp_srv_id} - "
f"IP: {dhcp_packet_rx.dhcp_yiaddr}, "
f"Mask: {dhcp_packet_rx.dhcp_subnet_mask}, "
f"Router: {dhcp_packet_rx.dhcp_router}"
f"Router: {dhcp_router_log}, "
f"DNS: {dhcp_packet_rx.dhcp_dns}, "
f"Domain: {dhcp_packet_rx.dhcp_domain_name}",
)
Expand Down Expand Up @@ -176,12 +189,22 @@ def fetch(self) -> Ip4Host | None:
client_socket.close()
return None

dhcp_router_log = (
None
if dhcp_packet_rx.dhcp_router is None
else (
", ".join(
str(address) for address in dhcp_packet_rx.dhcp_router
)
)
)

__debug__ and log(
"dhcp4",
f"Received DHCP Offer from {dhcp_packet_rx.dhcp_srv_id}"
f"Received DHCP Offer from {dhcp_packet_rx.dhcp_srv_id} - "
f"IP: {dhcp_packet_rx.dhcp_yiaddr}, "
f"Mask: {dhcp_packet_rx.dhcp_subnet_mask}, "
f"Router: {dhcp_packet_rx.dhcp_router}, "
f"Router: {dhcp_router_log}, "
f"DNS: {dhcp_packet_rx.dhcp_dns}, "
f"Domain: {dhcp_packet_rx.dhcp_domain_name}",
)
Expand Down
4 changes: 2 additions & 2 deletions pytcp/subsystems/tx_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def enqueue(
self._tx_ring.append(packet_tx)

__debug__ and log(
"rx-ring",
f"{packet_tx.tracker}, queue len: {len(self._tx_ring)}",
"tx-ring",
f"{packet_tx.tracker} - TX Queue len: {len(self._tx_ring)}",
)

self._packet_enqueued.release()

0 comments on commit 0fab8a6

Please sign in to comment.