1
0
mirror of https://github.com/fumiama/terasu-cloudflared.git synced 2026-06-09 04:30:31 +08:00

feat: embed terasu inside

This commit is contained in:
源文雨
2025-12-21 16:51:38 +08:00
parent 0d2a7a0385
commit f99b9330df
23 changed files with 1195 additions and 18 deletions

View File

@@ -10,6 +10,8 @@ import (
"net"
"strings"
"time"
"github.com/fumiama/terasu"
)
const (
@@ -131,11 +133,23 @@ func (c *Client) DialContext(ctx context.Context, address string) (conn *Conn, e
if useTLS {
network = strings.TrimSuffix(network, "-tls")
tlsDialer := tls.Dialer{
NetDialer: &d,
Config: c.TLSConfig,
var rawConn net.Conn
rawConn, err = d.DialContext(ctx, network, address)
if err == nil {
tlsCn := tls.Client(terasu.NewConn(rawConn), c.TLSConfig)
if deadline, ok := ctx.Deadline(); ok {
rawConn.SetDeadline(deadline)
}
err = tlsCn.Handshake()
if _, ok := ctx.Deadline(); ok {
rawConn.SetDeadline(time.Time{})
}
if err != nil {
rawConn.Close()
} else {
conn.Conn = tlsCn
}
}
conn.Conn, err = tlsDialer.DialContext(ctx, network, address)
} else {
conn.Conn, err = d.DialContext(ctx, network, address)
}