Skip to content

refactor: move the connection code into transport.go - #43

Merged
ilyam8 merged 2 commits into
engine-requestsfrom
engine-transport
Oct 11, 2026
Merged

ilyam8 merged 2 commits into
engine-requestsfrom
engine-transport

Conversation

@ilyam8

@ilyam8 ilyam8 commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Second restructuring step of the request engine: the connection code in one file. No behavior or exported API change; the exported connection fields stay on GoSNMP.

  • transport.go: Connect, ConnectIPv4, ConnectIPv6, Close, connect, netConnect and receive move from gosnmp.go and marshal.go unchanged. The write branch of sendOneRequest (WriteTo on an unconnected UDP socket, Write otherwise) becomes write there.

The first commit pins the connection setup, which the unit tests did not observe (the engine harness builds clients without Connect, and the Close tests build only with the end2end tag). TestConnect pins, on loopback sockets, the network each Connect* chooses (udp4/tcp4 for an IPv4 local address; known bug: a second ConnectIPv4 dials udp44), the validation before dialing, the error wrapping, the Control hook, the local address, the dial timeout (skipped on Windows, whose UDP dial does not check the context after connecting) and the context. TestCloseOnce pins that Close returns the connection's error, clears it and does nothing the second time. Both pass on the previous code.

Testing

  • go test ./... on darwin/arm64 and GOARCH=386; -race; GOOS=windows go vet; the FIPS 140-only tests; golangci-lint v2.14.0 (incl. end2end): 0 issues.
  • Every golden and the API test unchanged.
  • 22 mutation probes on transport.go: 21 caught, 1 equivalent (reusing the receive buffer across Connects: receive copies out and never reads stale bytes).
  • BenchmarkSendOneRequest, interleaved A/B, 6 rounds: time unchanged (p = 1.000), B/op and allocs/op identical.

@ilyam8
ilyam8 added this pull request to stack #38 October 9, 2026 15:18
@ilyam8 ilyam8 changed the title engine transport refactor: move the connection code into transport.go Oct 9, 2026
@ilyam8
ilyam8 force-pushed the engine-transport branch 2 times, most recently from b05b8d1 to 2d7cffe Compare October 11, 2026 09:46
Mutation probes on the connection code found it unpinned by the unit tests:
the engine harness builds clients without Connect and the Close tests build
only with the end2end tag.

TestConnect pins, on loopback sockets, the network Connect, ConnectIPv4 and
ConnectIPv6 choose (udp4/tcp4 for an IPv4 local address; known bug: a second
ConnectIPv4 dials "udp44"), the validation before dialing, the error wrapping,
the Control hook, the local address, the dial timeout (Unix) and the context.
TestCloseOnce pins that Close returns the connection's error, clears it and
does nothing the second time. Both pass on the current code.
Connect, ConnectIPv4, ConnectIPv6, Close, connect, netConnect and receive
move from gosnmp.go and marshal.go into transport.go unchanged, and the
write branch of sendOneRequest (WriteTo on an unconnected UDP socket, Write
otherwise) becomes write there. The exported fields stay where they are.

No behavior change: every golden, TestConnect and TestCloseOnce unchanged.
@ilyam8
ilyam8 merged commit 575fdcd into master Oct 11, 2026
21 checks passed
@ilyam8
ilyam8 deleted the engine-transport branch October 11, 2026 10:12
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.

2 participants