mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-13 14:44:15 +00:00
fix test break
This commit is contained in:
1 parent
3212337aa3
commit
4f59d6847f
2 files changed
+28
-22
No files matched your search
@@ -6,23 +6,29 @@ import (
|
||||
)
|
||||
|
||||
type TestPacketDispatcher struct {
|
||||
LastPacket v2net.Packet
|
||||
LastPacket chan v2net.Packet
|
||||
Handler func(packet v2net.Packet, traffic ray.OutboundRay)
|
||||
}
|
||||
|
||||
func (this *TestPacketDispatcher) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
||||
traffic := ray.NewRay()
|
||||
this.LastPacket = packet
|
||||
if this.Handler == nil {
|
||||
go func() {
|
||||
func NewTestPacketDispatcher(handler func(packet v2net.Packet, traffic ray.OutboundRay)) *TestPacketDispatcher {
|
||||
if handler == nil {
|
||||
handler = func(packet v2net.Packet, traffic ray.OutboundRay) {
|
||||
for payload := range traffic.OutboundInput() {
|
||||
traffic.OutboundOutput() <- payload.Prepend([]byte("Processed: "))
|
||||
}
|
||||
close(traffic.OutboundOutput())
|
||||
}()
|
||||
} else {
|
||||
go this.Handler(packet, traffic)
|
||||
}
|
||||
}
|
||||
return &TestPacketDispatcher{
|
||||
LastPacket: make(chan v2net.Packet, 16),
|
||||
Handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TestPacketDispatcher) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
||||
traffic := ray.NewRay()
|
||||
this.LastPacket <- packet
|
||||
go this.Handler(packet, traffic)
|
||||
|
||||
return traffic
|
||||
}
|
||||
Reference in new issue
Block a user