-
Notifications
You must be signed in to change notification settings - Fork 0
check if client is using clientcontext tracker #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the client context tracker to use standard HTTP for stream connections and introduces a CLIENTINFO prefix for packet connections, improving protocol clarity and error handling.
Key changes:
- Stream connections now use HTTP POST requests to
/clientinfowith HTTP 200 OK responses instead of plain-text protocol - Packet connections prefix client info with
CLIENTINFOfor better protocol detection - Enhanced error handling with graceful fallback when client info is absent, logging warnings instead of errors
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tracker/clientcontext/tracker.go | Implements HTTP-based handshake for stream connections, adds CLIENTINFO prefix for packets, and improves error handling with buffered reads for protocol detection |
| tracker/clientcontext/tracker_test.go | Adds test coverage for both presence and absence of client context tracker, refactors test setup to conditionally attach trackers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var buf [32]byte | ||
| n, err := c.Conn.Read(buf[:]) | ||
| if err != nil { | ||
| c.readErr = err | ||
| c.n = n | ||
| return err | ||
| } | ||
| reader := io.MultiReader(bytes.NewReader(buf[:n]), c.Conn) | ||
| if !bytes.HasPrefix(buf[:n], []byte("POST /clientinfo")) { |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The protocol detection only checks the first n bytes read (up to 32 bytes), which may not contain the full prefix 'POST /clientinfo' if the network delivers fewer bytes initially. This could cause incorrect protocol detection. Consider reading enough bytes to ensure the full HTTP method and path can be checked, or use a more robust detection mechanism.
| var buf [32]byte | |
| n, err := c.Conn.Read(buf[:]) | |
| if err != nil { | |
| c.readErr = err | |
| c.n = n | |
| return err | |
| } | |
| reader := io.MultiReader(bytes.NewReader(buf[:n]), c.Conn) | |
| if !bytes.HasPrefix(buf[:n], []byte("POST /clientinfo")) { | |
| prefix := []byte("POST /clientinfo") | |
| buf := make([]byte, 0, 64) // start with a reasonable buffer size | |
| tmp := make([]byte, 32) | |
| var n int | |
| var err error | |
| for len(buf) < len(prefix) { | |
| n, err = c.Conn.Read(tmp) | |
| if n > 0 { | |
| buf = append(buf, tmp[:n]...) | |
| } | |
| if err != nil { | |
| if err != io.EOF || len(buf) < len(prefix) { | |
| c.readErr = err | |
| c.n = len(buf) | |
| return err | |
| } | |
| break | |
| } | |
| } | |
| reader := io.MultiReader(bytes.NewReader(buf), c.Conn) | |
| if len(buf) < len(prefix) || !bytes.HasPrefix(buf, prefix) { |
Co-authored-by: Copilot <[email protected]>
This pull request refactors the client context tracker in
tracker/clientcontext/tracker.goto use standard HTTP for client info exchange on stream connections and introduces a clear packet prefix for client info on packet connections. It also updates the integration tests to reflect the new handshake logic and improves test coverage for tracker usage.Protocol and handshake changes:
/clientinfo, and expect an HTTP 200 OK response, replacing the previous plain-text protocol. (tracker/clientcontext/tracker.go) [1] [2]CLIENTINFO, and the server responds with "OK" as before, but with improved error handling and context management. (tracker/clientcontext/tracker.go) [1] [2]Code structure and error handling improvements:
readConn,writeConn,readPacketConn,writePacketConn) to improve error handling, context propagation, and to cache initial reads for protocol detection. (tracker/clientcontext/tracker.go) [1] [2] [3]tracker/clientcontext/tracker.go) [1] [2]Testing improvements:
tracker/clientcontext/tracker_test.go)newTestBoxnow only attaches a tracker if one is provided, making test setup more flexible. (tracker/clientcontext/tracker_test.go)Dependency and import updates:
net/http,io, andbytes, to support the new handshake logic. (tracker/clientcontext/tracker.go)