mihomo/transport/restls/restls.go

40 lines
693 B
Go
Raw Permalink Normal View History

package restls
import (
2023-03-14 16:50:27 +08:00
"context"
"net"
tls "github.com/3andne/restls-client-go"
)
const (
Mode string = "restls"
)
type Restls struct {
2023-03-14 16:50:27 +08:00
*tls.UConn
}
2023-03-14 16:50:27 +08:00
func (r *Restls) Upstream() any {
return r.UConn.NetConn()
}
// NewRestls return a Restls Connection
2023-03-14 16:50:27 +08:00
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 {
2023-03-14 16:50:27 +08:00
clientHellowID = *clientIDPtr
}
}
2023-03-14 16:50:27 +08:00
restls := &Restls{
UConn: tls.UClient(conn, config, clientHellowID),
}
if err := restls.HandshakeContext(ctx); err != nil {
return nil, err
}
return restls, nil
}