Repository navigation
Only intercept ENet disconnects addressed to our peer - #162
Merged
cgutman merged 1 commit intoOct 24, 2026
Merged
Conversation
ignoreDisconnectIntercept() runs on every datagram the control stream socket receives, before ENet has validated the packet. It only checked the length and command, so any 12-byte DISCONNECT from any source set disconnectPending, which tears down the session about a second later. Check that the header's peer ID and session ID match our peer and that the packet came from the peer's current address before acting on it. Anything else is passed to ENet unchanged, so a genuine disconnect that does not match (for example from another address of a multi-homed host) is still handled, just without the grace period. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 24, 2026
MrOz59
pushed a commit
to MrOz59/moonlight-common-c
that referenced
this pull request
Oct 26, 2026
…am#162) ignoreDisconnectIntercept() runs on every datagram the control stream socket receives, before ENet has validated the packet. It only checked the length and command, so any 12-byte DISCONNECT from any source set disconnectPending, which tears down the session about a second later. Check that the header's peer ID and session ID match our peer and that the packet came from the peer's current address before acting on it. Anything else is passed to ENet unchanged, so a genuine disconnect that does not match (for example from another address of a multi-homed host) is still handled, just without the grace period. (cherry picked from commit 41cedb8)
MrOz59
pushed a commit
to MrOz59/moonlight-common-c
that referenced
this pull request
Oct 26, 2026
…am#162) ignoreDisconnectIntercept() runs on every datagram the control stream socket receives, before ENet has validated the packet. It only checked the length and command, so any 12-byte DISCONNECT from any source set disconnectPending, which tears down the session about a second later. Check that the header's peer ID and session ID match our peer and that the packet came from the peer's current address before acting on it. Anything else is passed to ENet unchanged, so a genuine disconnect that does not match (for example from another address of a multi-homed host) is still handled, just without the grace period. (cherry picked from commit 41cedb8)
MrOz59
pushed a commit
to MrOz59/moonlight-common-c
that referenced
this pull request
Oct 26, 2026
…am#162) ignoreDisconnectIntercept() runs on every datagram the control stream socket receives, before ENet has validated the packet. It only checked the length and command, so any 12-byte DISCONNECT from any source set disconnectPending, which tears down the session about a second later. Check that the header's peer ID and session ID match our peer and that the packet came from the peer's current address before acting on it. Anything else is passed to ENet unchanged, so a genuine disconnect that does not match (for example from another address of a multi-homed host) is still handled, just without the grace period. (cherry picked from commit 41cedb8)
pabragin
pushed a commit
to pabragin/moonlight-common-c
that referenced
this pull request
Oct 27, 2026
…am#162) ignoreDisconnectIntercept() runs on every datagram the control stream socket receives, before ENet has validated the packet. It only checked the length and command, so any 12-byte DISCONNECT from any source set disconnectPending, which tears down the session about a second later. Check that the header's peer ID and session ID match our peer and that the packet came from the peer's current address before acting on it. Anything else is passed to ENet unchanged, so a genuine disconnect that does not match (for example from another address of a multi-homed host) is still handled, just without the grace period. (cherry picked from commit 41cedb8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ignoreDisconnectIntercept()is installed as the control stream's ENetinterceptcallback, so it sees every datagram on the control socket before ENet validates it. It only checked the datagram length and the command, so any 12-byte DISCONNECT from any source setdisconnectPending. The receive thread then ends the session about a second later.This PR acts on the disconnect only if the header's peer ID and session ID match our peer and the datagram came from the peer's current address. Anything else returns 0 and goes through ENet's normal processing unchanged. So a real disconnect that doesn't match (for example from another address of a multi-homed host) is still handled, just without the grace period this intercept adds.
Note: this makes the intercept no looser than ENet itself. ENet's own peer-address check is still disabled in the fork for multi-homed hosts (cgutman/enet@cf38f85), so this narrows the problem but doesn't fully close it. That part probably needs a separate design discussion.
Tested: builds without warnings into moonlight-qt (macOS, Qt 6.12, release) and the app runs. Not tested against a live host.
🤖 Generated with Claude Code