1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

tls connection

This commit is contained in:
v2ray 2016-04-28 21:13:41 +02:00
parent 94eab286c0
commit ccb874d65a

View File

@ -1,6 +1,7 @@
package hub package hub
import ( import (
"crypto/tls"
"net" "net"
"time" "time"
@ -95,3 +96,68 @@ func (this *TCPConnection) CloseWrite() error {
} }
return this.conn.CloseWrite() return this.conn.CloseWrite()
} }
type TLSConnection struct {
conn *tls.Conn
listener *TCPHub
}
func (this *TLSConnection) Read(b []byte) (int, error) {
if this == nil || this.conn == nil {
return 0, ErrorClosedConnection
}
return this.conn.Read(b)
}
func (this *TLSConnection) Write(b []byte) (int, error) {
if this == nil || this.conn == nil {
return this.conn.Write(b)
}
return this.conn.Write(b)
}
func (this *TLSConnection) Close() error {
if this == nil || this.conn == nil {
return ErrorClosedConnection
}
err := this.conn.Close()
return err
}
func (this *TLSConnection) Release() {
if this == nil || this.listener == nil {
return
}
this.Close()
this.conn = nil
this.listener = nil
}
func (this *TLSConnection) LocalAddr() net.Addr {
return this.conn.LocalAddr()
}
func (this *TLSConnection) RemoteAddr() net.Addr {
return this.conn.RemoteAddr()
}
func (this *TLSConnection) SetDeadline(t time.Time) error {
return this.conn.SetDeadline(t)
}
func (this *TLSConnection) SetReadDeadline(t time.Time) error {
return this.conn.SetReadDeadline(t)
}
func (this *TLSConnection) SetWriteDeadline(t time.Time) error {
return this.conn.SetWriteDeadline(t)
}
func (this *TLSConnection) CloseRead() error {
return nil
}
func (this *TLSConnection) CloseWrite() error {
return nil
}