UDP DNS transfer with retry¶
This operation owns all of the library's network transport behavior. It stamps a fresh transaction identifier into the outbound request on every attempt, sends the datagram to the selected DNS server, waits up to one second for a reply, and retries on timeout before finally giving up and raising NoResponseException.
| Field | Value |
|---|---|
| Operation ID | OP-DNS-004 |
| Trigger | Generic DNS lookup needs to send a serialized request and receive a reply |
| Inputs | Target IPEndPoint (server), request byte[] (requestMessage) |
| Outputs | Reply byte[]; throws NoResponseException once retries are exhausted |
| Primary components | Resolver.UdpTransfer, Socket |
| Entry point | SAIF.Framework.DNS\Resolver.cs |
Steps¶
- Initialize
attemptsto zero and enter a loop that continues whileattempts <= _udpRetryAttempts; with_udpRetryAttemptsset to 2, this allows the initial send plus two additional timed-out retries (BR-005). - On each iteration, stamp the current
_uniqueIdinto the first two bytes ofrequestMessage, giving the outbound datagram a fresh transaction identifier. - Create a UDP
Socketconfigured for IPv4 datagram transport. - Set the socket's receive timeout to 1000 milliseconds.
- Send the request bytes to the supplied server endpoint.
- Allocate a 512-byte buffer to receive the reply.
- Attempt to receive a reply into that buffer.
- If the first two reply bytes match the transaction identifier just stamped, accept the datagram and return it immediately (BR-006).
- If the reply identifier does not match, discard the datagram and continue to another loop iteration (BR-006).
- If
socket.ReceivethrowsSocketException(typically the 1-second timeout elapsing), incrementattemptsand let the loop retry the send/receive cycle (BR-005). - In a
finallyblock for every iteration, increment_uniqueIdand close the socket, regardless of whether the attempt succeeded, timed out, or received a mismatched reply. - If the loop exhausts all allowed attempts without returning a matching datagram, throw
NoResponseException(BR-005).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([UdpTransfer called]) --> Stamp[Stamp fresh transaction id]
Stamp --> Send[Send UDP datagram]
Send --> Wait[Wait up to 1 second for a reply]
Wait --> Match{Reply id matches?}
Match -->|Yes| EndOk([Return reply bytes])
Match -->|No, or timeout| Retry{Attempts remaining?}
Retry -->|Yes| Stamp
Retry -->|No| EndFail([Throw NoResponseException])
Failure and edge-case behavior¶
- A receive timeout surfaces internally as
SocketException, which this operation converts into a retry attempt rather than an immediate failure. - A reply with a mismatched transaction identifier is discarded silently; the caller has no way to observe that a stray or unrelated packet was received.
_uniqueIdadvances after every iteration, including timed-out and mismatched attempts, so consecutive attempts never reuse the same transaction identifier.- A new
Socketis created and torn down on every iteration; no socket is reused across attempts.
Related documentation¶
Sources¶
- SAIF.Framework.DNS\Resolver.cs