github.com/ipfans/trojan-go@v0.11.0/tunnel/websocket/conn.go (about) 1 package websocket 2 3 import ( 4 "context" 5 "net" 6 7 "golang.org/x/net/websocket" 8 9 "github.com/ipfans/trojan-go/tunnel" 10 ) 11 12 type OutboundConn struct { 13 *websocket.Conn 14 tcpConn net.Conn 15 } 16 17 func (c *OutboundConn) Metadata() *tunnel.Metadata { 18 return nil 19 } 20 21 func (c *OutboundConn) RemoteAddr() net.Addr { 22 // override RemoteAddr of websocket.Conn, or it will return some url from "Origin" 23 return c.tcpConn.RemoteAddr() 24 } 25 26 type InboundConn struct { 27 OutboundConn 28 ctx context.Context 29 cancel context.CancelFunc 30 } 31 32 func (c *InboundConn) Close() error { 33 c.cancel() 34 return c.Conn.Close() 35 }