Skip to content

Commit 95b1321

Browse files
M03EDImMohammad20000
authored andcommitted
fix: scenario timeout
1 parent f4329bc commit 95b1321

5 files changed

Lines changed: 44 additions & 60 deletions

File tree

proxy/hysteria/server.go

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package hysteria
22

33
import (
44
"context"
5-
"io"
65
"strings"
76
"time"
87

@@ -122,54 +121,30 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
122121
conn = connectiontracker.WrapConn(conn, connEntry)
123122
}
124123

125-
if _, ok := iConn.(*hysteria.InterUdpConn); ok {
126-
r := io.Reader(conn)
127-
b := make([]byte, MaxUDPSize)
128-
df := &Defragger{}
129-
var firstMsg *UDPMessage
130-
var firstDest net.Destination
131-
132-
for {
133-
n, err := r.Read(b)
134-
if err != nil {
135-
return err
136-
}
137-
138-
msg, err := ParseUDPMessage(b[:n])
139-
if err != nil {
140-
continue
141-
}
142-
143-
dfMsg := df.Feed(msg)
144-
if dfMsg == nil {
145-
continue
146-
}
147-
148-
firstMsg = dfMsg
149-
firstDest, err = net.ParseDestination("udp:" + firstMsg.Addr)
150-
if err != nil {
151-
errors.LogDebug(context.Background(), dfMsg.Addr, " ParseDestination err ", err)
152-
continue
153-
}
154-
155-
break
124+
if _, ok := iConn.(*hysteria.InterConn); ok {
125+
reader := &UDPReader{
126+
reader: conn,
127+
df: &Defragger{},
156128
}
157129

158-
reader := &UDPReader{
159-
Reader: r,
160-
buf: b,
161-
df: df,
162-
firstMsg: firstMsg,
163-
firstDest: &firstDest,
130+
b := buf.New()
131+
b.Resize(0, buf.Size)
132+
n, addr, err := reader.ReadFrom(b.Bytes())
133+
if err != nil {
134+
b.Release()
135+
return err
164136
}
137+
b.Resize(0, int32(n))
138+
b.UDP = addr
139+
140+
reader.firstBuf = b
165141

166142
writer := &UDPWriter{
167-
Writer: conn,
168-
buf: make([]byte, MaxUDPSize),
169-
addr: firstMsg.Addr,
143+
writer: conn,
144+
addr: addr.NetAddr(),
170145
}
171146

172-
return dispatcher.DispatchLink(ctx, firstDest, &transport.Link{
147+
return dispatcher.DispatchLink(ctx, *addr, &transport.Link{
173148
Reader: reader,
174149
Writer: writer,
175150
})

testing/scenarios/command_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ func TestRemoveUserClosesExistingConnections(t *testing.T) {
564564
},
565565
Outbound: []*core.OutboundHandlerConfig{
566566
{
567-
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
567+
ProxySettings: serial.ToTypedMessage(&freedom.Config{
568+
IpsBlocked: &freedom.IPRules{},
569+
}),
568570
},
569571
},
570572
}

testing/scenarios/common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ var (
9898
testBinaryPath string
9999
testBinaryCleanFn func()
100100
testBinaryPathGen sync.Once
101+
testBinaryBuild sync.Once
102+
testBinaryErr error
101103
)
102104

103105
func genTestBinaryPath() {
@@ -121,6 +123,17 @@ func genTestBinaryPath() {
121123
})
122124
}
123125

126+
func buildTestBinary(build func() error) error {
127+
genTestBinaryPath()
128+
testBinaryBuild.Do(func() {
129+
if _, err := os.Stat(testBinaryPath); err == nil {
130+
return
131+
}
132+
testBinaryErr = build()
133+
})
134+
return testBinaryErr
135+
}
136+
124137
func GetSourcePath() string {
125138
return filepath.Join("github.com", "xtls", "xray-core", "main")
126139
}

testing/scenarios/common_coverage.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ import (
1212
)
1313

1414
func BuildXray() error {
15-
genTestBinaryPath()
16-
if _, err := os.Stat(testBinaryPath); err == nil {
17-
return nil
18-
}
19-
20-
cmd := exec.Command("go", "test", "-tags", "coverage coveragemain", "-coverpkg", "github.com/xtls/xray-core/...", "-c", "-o", testBinaryPath, GetSourcePath())
21-
return cmd.Run()
15+
return buildTestBinary(func() error {
16+
cmd := exec.Command("go", "test", "-tags", "coverage coveragemain", "-coverpkg", "github.com/xtls/xray-core/...", "-c", "-o", testBinaryPath, GetSourcePath())
17+
return cmd.Run()
18+
})
2219
}
2320

2421
func RunXrayProtobuf(config []byte) *exec.Cmd {

testing/scenarios/common_regular.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ import (
1111
)
1212

1313
func BuildXray() error {
14-
genTestBinaryPath()
15-
if _, err := os.Stat(testBinaryPath); err == nil {
16-
return nil
17-
}
18-
19-
fmt.Printf("Building Xray into path (%s)\n", testBinaryPath)
20-
cmd := exec.Command("go", "build", "-o="+testBinaryPath, GetSourcePath())
21-
cmd.Stdout = os.Stdout
22-
cmd.Stderr = os.Stderr
23-
return cmd.Run()
14+
return buildTestBinary(func() error {
15+
fmt.Printf("Building Xray into path (%s)\n", testBinaryPath)
16+
cmd := exec.Command("go", "build", "-o="+testBinaryPath, GetSourcePath())
17+
cmd.Stdout = os.Stdout
18+
cmd.Stderr = os.Stderr
19+
return cmd.Run()
20+
})
2421
}
2522

2623
func RunXrayProtobuf(config []byte) *exec.Cmd {

0 commit comments

Comments
 (0)