mirror of https://github.com/v2ray/v2ray-core
				
				
				
			receive handshake address from tls conn
							parent
							
								
									9a9b6f9077
								
							
						
					
					
						commit
						14dc6371d3
					
				| 
						 | 
				
			
			@ -54,6 +54,10 @@ func (d *DokodemoDoor) policy() core.Policy {
 | 
			
		|||
	return p
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type hasHandshakeAddress interface {
 | 
			
		||||
	HandshakeAddress() net.Address
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher core.Dispatcher) error {
 | 
			
		||||
	newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog(session.ExportIDToError(ctx))
 | 
			
		||||
	dest := net.Destination{
 | 
			
		||||
| 
						 | 
				
			
			@ -65,6 +69,12 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
 | 
			
		|||
		if origDest, ok := proxy.OriginalTargetFromContext(ctx); ok {
 | 
			
		||||
			dest = origDest
 | 
			
		||||
		}
 | 
			
		||||
		if handshake, ok := conn.(hasHandshakeAddress); ok {
 | 
			
		||||
			addr := handshake.HandshakeAddress()
 | 
			
		||||
			if addr != nil {
 | 
			
		||||
				dest.Address = addr
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if !dest.IsValid() || dest.Address == nil {
 | 
			
		||||
		return newError("unable to get destination")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,9 +2,9 @@ package tls
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/tls"
 | 
			
		||||
	"net"
 | 
			
		||||
 | 
			
		||||
	"v2ray.com/core/common/buf"
 | 
			
		||||
	"v2ray.com/core/common/net"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg tls -path Transport,Internet,TLS
 | 
			
		||||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ var (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
type conn struct {
 | 
			
		||||
	net.Conn
 | 
			
		||||
	*tls.Conn
 | 
			
		||||
 | 
			
		||||
	mergingWriter *buf.BufferedWriter
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -29,6 +29,17 @@ func (c *conn) WriteMultiBuffer(mb buf.MultiBuffer) error {
 | 
			
		|||
	return c.mergingWriter.Flush()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *conn) HandshakeAddress() net.Address {
 | 
			
		||||
	if err := c.Handshake(); err != nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	state := c.Conn.ConnectionState()
 | 
			
		||||
	if len(state.ServerName) == 0 {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return net.ParseAddress(state.ServerName)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Client initiates a TLS client handshake on the given connection.
 | 
			
		||||
func Client(c net.Conn, config *tls.Config) net.Conn {
 | 
			
		||||
	tlsConn := tls.Client(c, config)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue