From ccb874d65acc5ec47a60a59f072fe0b76264b2d0 Mon Sep 17 00:00:00 2001 From: v2ray Date: Thu, 28 Apr 2016 21:13:41 +0200 Subject: [PATCH] tls connection --- transport/hub/connection.go | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/transport/hub/connection.go b/transport/hub/connection.go index 584242492..2069b1f63 100644 --- a/transport/hub/connection.go +++ b/transport/hub/connection.go @@ -1,6 +1,7 @@ package hub import ( + "crypto/tls" "net" "time" @@ -95,3 +96,68 @@ func (this *TCPConnection) CloseWrite() error { } 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 +}