From 3db64d039f6f0126409131a890578f8083bbcd20 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 3 Apr 2026 17:53:28 +0800 Subject: [PATCH] chore: add get tls connection state function in component/tls --- component/tls/utls.go | 12 ++++++++++++ transport/gun/gun.go | 17 ++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/component/tls/utls.go b/component/tls/utls.go index 6a8081875..6cf9fc681 100644 --- a/component/tls/utls.go +++ b/component/tls/utls.go @@ -308,6 +308,18 @@ func BuildRemovedX25519MLKEM768HandshakeState(c *UConn) error { return nil } +func GetTLSConnectionState(conn net.Conn) (tlsState tls.ConnectionState) { + switch tlsConn := conn.(type) { + case interface{ ConnectionState() tls.ConnectionState }: + state := tlsConn.ConnectionState() + return state + case interface{ ConnectionState() utls.ConnectionState }: + state := tlsConn.ConnectionState() + return tlsConnectionState(state) + } + return +} + var globalFingerprint string func SetGlobalFingerprint(fingerprint string) { diff --git a/transport/gun/gun.go b/transport/gun/gun.go index 136a32b18..b5681e065 100644 --- a/transport/gun/gun.go +++ b/transport/gun/gun.go @@ -267,19 +267,10 @@ func NewTransport(dialFn DialFn, tlsConfig *vmess.TLSConfig, gunCfg *Config) *Tr } if tlsConfig.Reality == nil { // reality doesn't return the negotiated ALPN - switch tlsConn := conn.(type) { - case interface{ ConnectionState() tls.ConnectionState }: - state := tlsConn.ConnectionState() - if p := state.NegotiatedProtocol; p != http.Http2NextProtoTLS { - _ = conn.Close() - return nil, fmt.Errorf("http2: unexpected ALPN protocol %s, want %s", p, http.Http2NextProtoTLS) - } - case interface{ ConnectionState() tlsC.ConnectionState }: - state := tlsConn.ConnectionState() - if p := state.NegotiatedProtocol; p != http.Http2NextProtoTLS { - _ = conn.Close() - return nil, fmt.Errorf("http2: unexpected ALPN protocol %s, want %s", p, http.Http2NextProtoTLS) - } + state := tlsC.GetTLSConnectionState(conn) + if p := state.NegotiatedProtocol; p != http.Http2NextProtoTLS { + _ = conn.Close() + return nil, fmt.Errorf("http2: unexpected ALPN protocol %s, want %s", p, http.Http2NextProtoTLS) } } return conn, nil