* fixes #512: geo download failed when startup - 启动阶段,executor还未初始化tunnel,tcpIn==nil导致geo下载失败,阻塞在 tcpIn <- context * chore: handled by the upper layer * chore: remove useless parameters --------- Co-authored-by: Skyxim <noreply@skyxim.dev>
This commit is contained in:
parent
1eefa71e1f
commit
463da578dd
3 changed files with 22 additions and 15 deletions
|
@ -30,21 +30,18 @@ func NewSocket(target socks5.Addr, conn net.Conn, source C.Type, additions ...Ad
|
||||||
return context.NewConnContext(conn, metadata)
|
return context.NewConnContext(conn, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInner(conn net.Conn, dst string, host string) *context.ConnContext {
|
func NewInner(conn net.Conn, address string) *context.ConnContext {
|
||||||
metadata := &C.Metadata{}
|
metadata := &C.Metadata{}
|
||||||
metadata.NetWork = C.TCP
|
metadata.NetWork = C.TCP
|
||||||
metadata.Type = C.INNER
|
metadata.Type = C.INNER
|
||||||
metadata.DNSMode = C.DNSNormal
|
metadata.DNSMode = C.DNSNormal
|
||||||
metadata.Host = host
|
|
||||||
metadata.Process = C.ClashName
|
metadata.Process = C.ClashName
|
||||||
if h, port, err := net.SplitHostPort(dst); err == nil {
|
if h, port, err := net.SplitHostPort(address); err == nil {
|
||||||
metadata.DstPort = port
|
metadata.DstPort = port
|
||||||
if host == "" {
|
if ip, err := netip.ParseAddr(h); err == nil {
|
||||||
if ip, err := netip.ParseAddr(h); err == nil {
|
metadata.DstIP = ip
|
||||||
metadata.DstIP = ip
|
} else {
|
||||||
} else {
|
metadata.Host = h
|
||||||
metadata.Host = h
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,12 @@ func HttpRequest(ctx context.Context, url, method string, header map[string][]st
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
ExpectContinueTimeout: 1 * time.Second,
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
conn := inner.HandleTcp(address, "")
|
if conn, err := inner.HandleTcp(address); err == nil {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
|
} else {
|
||||||
|
d := net.Dialer{}
|
||||||
|
return d.DialContext(ctx, network, address)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
TLSClientConfig: tls.GetDefaultTLSConfig(),
|
TLSClientConfig: tls.GetDefaultTLSConfig(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package inner
|
package inner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/adapter/inbound"
|
"github.com/Dreamacro/clash/adapter/inbound"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var tcpIn chan<- C.ConnContext
|
var tcpIn chan<- C.ConnContext
|
||||||
|
@ -12,9 +14,13 @@ func New(in chan<- C.ConnContext) {
|
||||||
tcpIn = in
|
tcpIn = in
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleTcp(dst string, host string) net.Conn {
|
func HandleTcp(address string) (conn net.Conn, err error) {
|
||||||
|
if tcpIn == nil {
|
||||||
|
return nil, errors.New("tcp uninitialized")
|
||||||
|
}
|
||||||
|
// executor Parsed
|
||||||
conn1, conn2 := net.Pipe()
|
conn1, conn2 := net.Pipe()
|
||||||
context := inbound.NewInner(conn2, dst, host)
|
context := inbound.NewInner(conn2, address)
|
||||||
tcpIn <- context
|
tcpIn <- context
|
||||||
return conn1
|
return conn1, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue