mirror of https://github.com/XTLS/Xray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
810 B
37 lines
810 B
package xtls
|
|
|
|
import (
|
|
xtls "github.com/xtls/go"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
)
|
|
|
|
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
|
|
|
type Conn struct {
|
|
*xtls.Conn
|
|
}
|
|
|
|
func (c *Conn) HandshakeAddress() net.Address {
|
|
if err := c.Handshake(); err != nil {
|
|
return nil
|
|
}
|
|
state := c.ConnectionState()
|
|
if state.ServerName == "" {
|
|
return nil
|
|
}
|
|
return net.ParseAddress(state.ServerName)
|
|
}
|
|
|
|
// Client initiates a XTLS client handshake on the given connection.
|
|
func Client(c net.Conn, config *xtls.Config) net.Conn {
|
|
xtlsConn := xtls.Client(c, config)
|
|
return &Conn{Conn: xtlsConn}
|
|
}
|
|
|
|
// Server initiates a XTLS server handshake on the given connection.
|
|
func Server(c net.Conn, config *xtls.Config) net.Conn {
|
|
xtlsConn := xtls.Server(c, config)
|
|
return &Conn{Conn: xtlsConn}
|
|
}
|