将tlsLayer.Conn从结构改为接口

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent 3c9aed0435
commit 60e8124bde
6 changed files with 27 additions and 27 deletions

View File

@@ -73,7 +73,7 @@ type incomingInserverConnState struct {
cachedRemoteAddr string
inServerTlsConn *tlsLayer.Conn
inServerTlsConn tlsLayer.Conn
inServerTlsRawReadRecorder *tlsLayer.Recorder
isFallbackH2 bool

View File

@@ -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(),

View File

@@ -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
}

View File

@@ -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),
}

View File

@@ -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

View File

@@ -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)
}