diff --git a/iics.go b/iics.go index bbea580..19e51d6 100644 --- a/iics.go +++ b/iics.go @@ -73,7 +73,7 @@ type incomingInserverConnState struct { cachedRemoteAddr string - inServerTlsConn *tlsLayer.Conn + inServerTlsConn tlsLayer.Conn inServerTlsRawReadRecorder *tlsLayer.Recorder isFallbackH2 bool diff --git a/tlsLayer/client.go b/tlsLayer/client.go index c08e814..f378236 100644 --- a/tlsLayer/client.go +++ b/tlsLayer/client.go @@ -53,7 +53,7 @@ func NewClient(conf Conf) *Client { return c } -func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) { +func (c *Client) Handshake(underlay net.Conn) (tlsConn Conn, err error) { switch c.tlsType { case UTls_t: @@ -65,7 +65,7 @@ func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) { if err != nil { return } - tlsConn = &Conn{ + tlsConn = &conn{ Conn: utlsConn, ptr: unsafe.Pointer(utlsConn.Conn), tlsType: UTls_t, @@ -77,7 +77,7 @@ func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) { return } - tlsConn = &Conn{ + tlsConn = &conn{ Conn: officialConn, ptr: unsafe.Pointer(officialConn), tlsType: Tls_t, @@ -89,7 +89,7 @@ func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) { return } - tlsConn = &Conn{ + tlsConn = &conn{ Conn: underlay, tlsType: ShadowTls_t, } @@ -115,7 +115,7 @@ func (c *Client) Handshake(underlay net.Conn) (tlsConn *Conn, err error) { // return // } - tlsConn = &Conn{ + tlsConn = &conn{ Conn: &shadowClientConn{ FakeAppDataConn: &FakeAppDataConn{Conn: rw}, sum: hashR.Sum(), diff --git a/tlsLayer/conn.go b/tlsLayer/conn.go index 010d6c9..8fb3b30 100644 --- a/tlsLayer/conn.go +++ b/tlsLayer/conn.go @@ -17,13 +17,21 @@ type faketlsconn struct { // 本包会用到这个Conn,比如server和client的 Handshake, // 唯一特性就是它可以返回tls连接的底层tcp连接,见 GetRaw -type Conn struct { +type Conn interface { + net.Conn + GetRaw(tls_lazy_encrypt bool) *net.TCPConn + GetTeeConn() *TeeConn + GetAlpn() string + GetSni() string +} + +type conn struct { net.Conn ptr unsafe.Pointer tlsType int } -func (c *Conn) GetRaw(tls_lazy_encrypt bool) *net.TCPConn { +func (c *conn) GetRaw(tls_lazy_encrypt bool) *net.TCPConn { rc := (*faketlsconn)(c.ptr) if rc != nil { @@ -44,7 +52,7 @@ func (c *Conn) GetRaw(tls_lazy_encrypt bool) *net.TCPConn { } // 直接获取TeeConn,仅用于已经确定肯定能获取到的情况 -func (c *Conn) GetTeeConn() *TeeConn { +func (c *conn) GetTeeConn() *TeeConn { rc := (*faketlsconn)(c.ptr) return rc.conn.(*TeeConn) @@ -52,7 +60,7 @@ func (c *Conn) GetTeeConn() *TeeConn { } // return c.Conn.ConnectionState().NegotiatedProtocol -func (c *Conn) GetAlpn() string { +func (c *conn) GetAlpn() string { switch c.tlsType { case UTls_t: @@ -72,7 +80,7 @@ func (c *Conn) GetAlpn() string { return "" } -func (c *Conn) GetSni() string { +func (c *conn) GetSni() string { switch c.tlsType { case UTls_t: @@ -93,11 +101,3 @@ func (c *Conn) GetSni() string { return "" } - -func (c *Conn) WillReadBuffersBenifit() int { - return 0 -} - -func (c *Conn) CanMultiRead() bool { - return false -} diff --git a/tlsLayer/server.go b/tlsLayer/server.go index 0e41626..6398f54 100644 --- a/tlsLayer/server.go +++ b/tlsLayer/server.go @@ -49,7 +49,7 @@ func NewServer(conf Conf) (*Server, error) { return s, nil } -func (s *Server) Handshake(clientConn net.Conn) (tlsConn *Conn, err error) { +func (s *Server) Handshake(clientConn net.Conn) (tlsConn Conn, err error) { switch s.tlstype { case ShadowTls_t: @@ -67,7 +67,7 @@ func (s *Server) Handshake(clientConn net.Conn) (tlsConn *Conn, err error) { return } - tlsConn = &Conn{ + tlsConn = &conn{ Conn: rawTlsConn, ptr: unsafe.Pointer(rawTlsConn), } diff --git a/tlsLayer/shadow.go b/tlsLayer/shadow.go index a9cd651..2b15909 100644 --- a/tlsLayer/shadow.go +++ b/tlsLayer/shadow.go @@ -27,7 +27,7 @@ func getShadowTlsPasswordFromExtra(extra map[string]any) string { return "" } -func shadowTls1(servername string, clientConn net.Conn) (tlsConn *Conn, err error) { +func shadowTls1(servername string, clientConn net.Conn) (tlsConn *conn, err error) { var fakeConn net.Conn fakeConn, err = net.Dial("tcp", servername+":443") if err != nil { @@ -77,7 +77,7 @@ func shadowTls1(servername string, clientConn net.Conn) (tlsConn *Conn, err erro ce.Write() } - tlsConn = &Conn{ + tlsConn = &conn{ Conn: clientConn, tlsType: ShadowTls_t, } @@ -85,7 +85,7 @@ func shadowTls1(servername string, clientConn net.Conn) (tlsConn *Conn, err erro return } -func shadowTls2(servername string, clientConn net.Conn, password string) (tlsConn *Conn, err error) { +func shadowTls2(servername string, clientConn net.Conn, password string) (tlsConn *conn, err error) { var fakeConn net.Conn fakeConn, err = net.Dial("tcp", servername+":443") if err != nil { @@ -123,7 +123,7 @@ func shadowTls2(servername string, clientConn net.Conn, password string) (tlsCon Writer: realconn, } - return &Conn{ + return &conn{ Conn: allDataConn, tlsType: ShadowTls2_t, }, nil diff --git a/tls_lazy.go b/tls_lazy.go index 10760da..d76c3ca 100644 --- a/tls_lazy.go +++ b/tls_lazy.go @@ -107,11 +107,11 @@ func tryTlsLazyRawRelay(connid uint32, useSecureMethod bool, proxy_client proxy. } if isTlsDirectly { - tlsConn := wrc.(*tlsLayer.Conn) + tlsConn := wrc.(tlsLayer.Conn) rawWRC = tlsConn.GetRaw(true) } else { wrcWrapper := wrc.(netLayer.ConnWrapper) - tlsConn := wrcWrapper.Upstream().(*tlsLayer.Conn) + tlsConn := wrcWrapper.Upstream().(tlsLayer.Conn) rawWRC = tlsConn.GetRaw(true) }