mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-01-13 06:07:14 +08:00
Compare commits
1 Commits
v25.12.2
...
fix-vision
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5e54e92fb |
@@ -19,7 +19,7 @@ import (
|
||||
var (
|
||||
Version_x byte = 25
|
||||
Version_y byte = 12
|
||||
Version_z byte = 2
|
||||
Version_z byte = 1
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -57,12 +57,7 @@ type Handler struct {
|
||||
|
||||
testpre uint32
|
||||
initpre sync.Once
|
||||
preConns chan *ConnExpire
|
||||
}
|
||||
|
||||
type ConnExpire struct {
|
||||
Conn stat.Connection
|
||||
Expire time.Time
|
||||
preConns chan stat.Connection
|
||||
}
|
||||
|
||||
// New creates a new VLess outbound handler.
|
||||
@@ -146,33 +141,25 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
|
||||
if h.testpre > 0 && h.reverse == nil {
|
||||
h.initpre.Do(func() {
|
||||
h.preConns = make(chan *ConnExpire)
|
||||
h.preConns = make(chan stat.Connection)
|
||||
for range h.testpre { // TODO: randomize
|
||||
go func() {
|
||||
defer func() { recover() }()
|
||||
ctx := xctx.ContextWithID(context.Background(), session.NewID())
|
||||
for {
|
||||
time.Sleep(time.Millisecond * 200) // TODO: randomize
|
||||
conn, err := dialer.Dial(ctx, rec.Destination)
|
||||
if err != nil {
|
||||
errors.LogWarningInner(ctx, err, "pre-connect failed")
|
||||
continue
|
||||
}
|
||||
h.preConns <- &ConnExpire{Conn: conn, Expire: time.Now().Add(time.Minute * 2)} // TODO: customize & randomize
|
||||
time.Sleep(time.Millisecond * 200) // TODO: customize & randomize
|
||||
h.preConns <- conn
|
||||
}
|
||||
}()
|
||||
}
|
||||
})
|
||||
for {
|
||||
connTime := <-h.preConns
|
||||
if connTime == nil {
|
||||
return errors.New("closed handler").AtWarning()
|
||||
}
|
||||
if time.Now().Before(connTime.Expire) {
|
||||
conn = connTime.Conn
|
||||
break
|
||||
}
|
||||
connTime.Conn.Close()
|
||||
if conn = <-h.preConns; conn == nil {
|
||||
return errors.New("closed handler").AtWarning()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user