fix(masque): address review findings for PR #76

- Return errors from MasqueConn.Read/Write instead of silently
  succeeding (prevents infinite busy-loops and silent data loss
  if these methods are accidentally called).
- Set recorder Network field in protocol dispatch switch rather
  than hardcoding "udp", so early errors don't misreport type.
- Clarify that DatagramConn context-ID handling only supports
  context ID 0 (sufficient for CONNECT-UDP per RFC 9298).
This commit is contained in:
ginuerzh
2026-05-21 22:36:30 +08:00
parent 66b53580af
commit 01a2bbaa11
3 changed files with 15 additions and 11 deletions
+7 -6
View File
@@ -3,6 +3,7 @@ package masque
import (
"context"
"crypto/tls"
"errors"
"net"
"time"
@@ -11,6 +12,8 @@ import (
"github.com/quic-go/quic-go/http3"
)
var errReadWriteNotSupported = errors.New("masque: direct Read/Write not supported on MasqueConn, use GetRequestStream")
// Client manages HTTP/3 connections for MASQUE proxying.
// It wraps a QUIC connection and HTTP/3 client, following the session pattern
// used by other gost dialers (ssh, quic, mws, etc.).
@@ -105,17 +108,15 @@ func (c *MasqueConn) GetHost() string {
}
// Read implements net.Conn but is not used for MASQUE.
// The actual data transfer happens via datagrams.
// The actual data transfer happens via datagrams or the request stream.
func (c *MasqueConn) Read(b []byte) (n int, err error) {
// This should not be called - datagrams are used for data transfer
return 0, nil
return 0, errReadWriteNotSupported
}
// Write implements net.Conn but is not used for MASQUE.
// The actual data transfer happens via datagrams.
// The actual data transfer happens via datagrams or the request stream.
func (c *MasqueConn) Write(b []byte) (n int, err error) {
// This should not be called - datagrams are used for data transfer
return len(b), nil
return 0, errReadWriteNotSupported
}
// Close closes the connection.