mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-16 14:11:19 +08:00
40 lines
693 B
Go
40 lines
693 B
Go
package restls
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
tls "github.com/3andne/restls-client-go"
|
|
)
|
|
|
|
const (
|
|
Mode string = "restls"
|
|
)
|
|
|
|
type Restls struct {
|
|
*tls.UConn
|
|
}
|
|
|
|
func (r *Restls) Upstream() any {
|
|
return r.UConn.NetConn()
|
|
}
|
|
|
|
// NewRestls return a Restls Connection
|
|
func NewRestls(ctx context.Context, conn net.Conn, config *tls.Config) (net.Conn, error) {
|
|
clientHellowID := tls.HelloChrome_Auto
|
|
if config != nil {
|
|
clientIDPtr := config.ClientID.Load()
|
|
if clientIDPtr != nil {
|
|
clientHellowID = *clientIDPtr
|
|
}
|
|
}
|
|
restls := &Restls{
|
|
UConn: tls.UClient(conn, config, clientHellowID),
|
|
}
|
|
if err := restls.HandshakeContext(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return restls, nil
|
|
}
|