Xray-core/transport/internet/xtls/xtls.go

37 lines
810 B
Go
Raw Normal View History

2020-11-25 14:01:53 +03:00
package xtls
import (
xtls "github.com/xtls/go"
2020-12-04 04:36:16 +03:00
"github.com/xtls/xray-core/common/net"
2020-11-25 14:01:53 +03:00
)
2020-12-04 04:36:16 +03:00
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
2020-11-25 14:01:53 +03:00
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}
}