github.com/TeaOSLab/EdgeNode@v1.3.8/internal/nodes/client_tls_conn.go (about) 1 // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package nodes 4 5 import ( 6 "crypto/tls" 7 "net" 8 "time" 9 ) 10 11 // ClientTLSConn TLS连接封装 12 type ClientTLSConn struct { 13 BaseClientConn 14 } 15 16 func NewClientTLSConn(conn *tls.Conn) net.Conn { 17 return &ClientTLSConn{BaseClientConn{rawConn: conn}} 18 } 19 20 func (this *ClientTLSConn) Read(b []byte) (n int, err error) { 21 n, err = this.rawConn.Read(b) 22 return 23 } 24 25 func (this *ClientTLSConn) Write(b []byte) (n int, err error) { 26 n, err = this.rawConn.Write(b) 27 return 28 } 29 30 func (this *ClientTLSConn) Close() error { 31 this.isClosed = true 32 33 // 单个服务并发数限制 34 sharedClientConnLimiter.Remove(this.rawConn.RemoteAddr().String()) 35 36 return this.rawConn.Close() 37 } 38 39 func (this *ClientTLSConn) LocalAddr() net.Addr { 40 return this.rawConn.LocalAddr() 41 } 42 43 func (this *ClientTLSConn) RemoteAddr() net.Addr { 44 return this.rawConn.RemoteAddr() 45 } 46 47 func (this *ClientTLSConn) SetDeadline(t time.Time) error { 48 return this.rawConn.SetDeadline(t) 49 } 50 51 func (this *ClientTLSConn) SetReadDeadline(t time.Time) error { 52 return this.rawConn.SetReadDeadline(t) 53 } 54 55 func (this *ClientTLSConn) SetWriteDeadline(t time.Time) error { 56 return this.rawConn.SetWriteDeadline(t) 57 } 58 59 func (this *ClientTLSConn) SetIsPersistent(isPersistent bool) { 60 tlsConn, ok := this.rawConn.(*tls.Conn) 61 if ok { 62 var rawConn = tlsConn.NetConn() 63 if rawConn != nil { 64 clientConn, ok := rawConn.(*ClientConn) 65 if ok { 66 clientConn.SetIsPersistent(isPersistent) 67 } 68 } 69 } 70 } 71 72 func (this *ClientTLSConn) Fingerprint() []byte { 73 tlsConn, ok := this.rawConn.(*tls.Conn) 74 if ok { 75 var rawConn = tlsConn.NetConn() 76 if rawConn != nil { 77 clientConn, ok := rawConn.(*ClientConn) 78 if ok { 79 return clientConn.fingerprint 80 } 81 } 82 } 83 return nil 84 } 85 86 // LastRequestBytes 读取上一次请求发送的字节数 87 func (this *ClientTLSConn) LastRequestBytes() int64 { 88 tlsConn, ok := this.rawConn.(*tls.Conn) 89 if ok { 90 var rawConn = tlsConn.NetConn() 91 if rawConn != nil { 92 clientConn, ok := rawConn.(*ClientConn) 93 if ok { 94 return clientConn.LastRequestBytes() 95 } 96 } 97 } 98 return 0 99 }