github.com/kelleygo/clashcore@v1.0.2/transport/restls/restls.go (about) 1 package restls 2 3 import ( 4 "context" 5 "net" 6 7 tls "github.com/3andne/restls-client-go" 8 ) 9 10 const ( 11 Mode string = "restls" 12 ) 13 14 type Restls struct { 15 *tls.UConn 16 } 17 18 func (r *Restls) Upstream() any { 19 return r.UConn.NetConn() 20 } 21 22 // NewRestls return a Restls Connection 23 func NewRestls(ctx context.Context, conn net.Conn, config *tls.Config) (net.Conn, error) { 24 clientHellowID := tls.HelloChrome_Auto 25 if config != nil { 26 clientIDPtr := config.ClientID.Load() 27 if clientIDPtr != nil { 28 clientHellowID = *clientIDPtr 29 } 30 } 31 restls := &Restls{ 32 UConn: tls.UClient(conn, config, clientHellowID), 33 } 34 if err := restls.HandshakeContext(ctx); err != nil { 35 return nil, err 36 } 37 38 return restls, nil 39 }