Skip to content

Network: set_network (LANConfig 325), incl. DHCP↔static, verified live - #15

Open
widgetii wants to merge 1 commit into
masterfrom
setters-network
Open

widgetii wants to merge 1 commit into
masterfrom
setters-network

Conversation

@widgetii

Copy link
Copy Markdown
Member

What

Wired network config over code 325 = NetworkConfig/LANConfig (disasm MsgSetNetworkLANConfig, confirmed live on an MTF45-4G_AF).

  • set_network(ip=, netmask=, gateway=, dns1=, dns2=, dhcp=, hostname=, mtu=, confirm=True) — read-modify-write of the <LANConfig> element: only the given fields change; MacAddress and everything else are preserved. dhcp is a bool.

Verified live

  • A reversible DNS2 change with IP/mask/gateway preserved.
  • A DHCP↔static switch (static → DHCP=1 → back to static 10.216.128.149), re-finding the camera via anjoy.discovery between steps. On this network there is no DHCP server, so the camera kept its IP under DHCP and stayed reachable throughout.

Safety

Changing ip/netmask/gateway or enabling dhcp can move the camera to a different address, so the docstring warns to reconnect at (or discover()) the new IP; confirm=True-gated.

Changes

  • anjoy/comm.py: set_network (RMW over _rmw_section).
  • anjoy/const.py: CFG_LAN="325".
  • tests/test_comm.py: field change + preservation, only-given-fields, confirm gate (97 tests pass).
  • docs/devices.md: the 325 code + the DHCP↔static verification.

Code 325 = NetworkConfig/LANConfig (disasm MsgSetNetworkLANConfig + live).
set_network(ip=, netmask=, gateway=, dns1=, dns2=, dhcp=, hostname=, mtu=,
confirm=True) read-modify-writes the LANConfig: only the given fields change,
MacAddress and the rest are preserved.

Verified live on MTF45-4G_AF:
- reversible DNS2 change with IP/mask/gateway preserved;
- a DHCP<->static switch (static -> DHCP=1 -> back to static 10.216.128.149),
  re-finding the camera via anjoy.discovery between steps.

Changing ip/netmask/gateway or enabling dhcp can move the camera, so the
docstring warns to reconnect at / discover the new address; confirm-gated.
const.CFG_LAN="325". Tests: field change + preservation, only-given-fields,
confirm gate. Docs updated.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add confirmed LAN network configuration setter

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds wired-network updates for static addressing, DNS, DHCP, hostname, and MTU.
• Preserves unspecified LANConfig fields through read-modify-write operations using protocol code
 325.
• Covers safety, field preservation, and verified DHCP↔static behavior in tests and documentation.
Diagram

graph TD
  Caller["API Caller"] --> Client["set_network"] --> Guard{"Confirmed?"}
  Guard -->|yes| Read["Read Config"] --> Update["Patch LANConfig"] --> Write["Write Code 325"] --> Camera["Camera Network"]
  Guard -->|no| Error["Raise AnjoyError"]
Loading
High-Level Assessment

The selected approach is appropriate: reusing the existing read-modify-write helper avoids duplicating XML parsing and preserves unknown device-specific fields. A full LANConfig replacement or dedicated serializer would increase clobbering and maintenance risk without providing a meaningful benefit; the explicit confirmation gate appropriately addresses network-disruption risk.

Files changed (4) +84 / -6

Enhancement (2) +27 / -0
comm.pyAdd confirmation-gated LAN network configuration API +26/-0

Add confirmation-gated LAN network configuration API

• Adds set_network for selectively changing IP address, netmask, gateway, DNS, DHCP, hostname, and MTU values. It uses the existing read-modify-write helper to preserve unspecified attributes and requires confirm=True because applying changes may disconnect or relocate the camera.

anjoy/comm.py

const.pyRegister LAN configuration protocol code 325 +1/-0

Register LAN configuration protocol code 325

• Defines CFG_LAN for the NetworkConfig/LANConfig wired-network configuration section.

anjoy/const.py

Tests (1) +40 / -0
test_comm.pyTest network field updates, preservation, and confirmation +40/-0

Test network field updates, preservation, and confirmation

• Adds fake-server coverage verifying protocol code 325, DHCP boolean conversion, selective field changes, and preservation of MAC and untouched network values. Also verifies that calls without confirm=True raise AnjoyError.

tests/test_comm.py

Documentation (1) +17 / -6
devices.mdDocument LAN protocol mapping and live verification +17/-6

Document LAN protocol mapping and live verification

• Documents protocol code 325, the set_network API, field-preserving behavior, live DNS and DHCP↔static verification, and reconnection precautions. It also clarifies that password changes preserve account privileges and synchronize the client's credential.

docs/devices.md

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Rapid network edits overwrite each other 🐞 Bug ≡ Correctness
Description
set_network passes a complete snapshot of LANConfig through _rmw_section, even though
set_config_section acknowledges before the previous asynchronous write appears in get_config().
If callers make two edits back-to-back, the second read can retrieve the pre-first-write section and
resend its stale values alongside the second field, reverting the first edit and any concurrent LAN
changes.
Code

anjoy/comm.py[613]

+        return self._rmw_section("LANConfig", const.CFG_LAN, {
Evidence
set_config_section documents that the acknowledgement returns immediately while the written values
appear in get_config() only later, and that partial sections are merged. _rmw_section
nevertheless downloads the current configuration and serializes the entire matched element, while
the new set_network delegates directly to that helper; therefore a second acknowledged call can
download stale LAN values and write them back.

anjoy/comm.py[381-409]
anjoy/comm.py[480-495]
anjoy/comm.py[613-618]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`set_network` read-modify-writes the complete `LANConfig` element, so a subsequent call can read stale configuration before an earlier asynchronous write is persisted and then restore the old values.

## Fix Focus Areas
- anjoy/comm.py[613-618]
- tests/test_comm.py[725-735]

## Recommended Fix
Build a `LANConfig` element containing only the non-`None` attributes supplied by the caller and pass it directly to `set_config_section`, relying on the device's documented partial-section merge behavior. Add a test showing that separate consecutive field updates do not include or overwrite unspecified attributes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This adds runtime network configuration behavior with address/DHCP consequences, so it warrants a complete careful review despite the localized scope.

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread anjoy/comm.py
"""
if not confirm:
raise AnjoyError("set_network changes the camera address; pass confirm=True")
return self._rmw_section("LANConfig", const.CFG_LAN, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Rapid network edits overwrite each other 🐞 Bug ≡ Correctness

set_network passes a complete snapshot of LANConfig through _rmw_section, even though
set_config_section acknowledges before the previous asynchronous write appears in get_config().
If callers make two edits back-to-back, the second read can retrieve the pre-first-write section and
resend its stale values alongside the second field, reverting the first edit and any concurrent LAN
changes.
Agent Prompt
## Issue description
`set_network` read-modify-writes the complete `LANConfig` element, so a subsequent call can read stale configuration before an earlier asynchronous write is persisted and then restore the old values.

## Fix Focus Areas
- anjoy/comm.py[613-618]
- tests/test_comm.py[725-735]

## Recommended Fix
Build a `LANConfig` element containing only the non-`None` attributes supplied by the caller and pass it directly to `set_config_section`, relying on the device's documented partial-section merge behavior. Add a test showing that separate consecutive field updates do not include or overwrite unspecified attributes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant