1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 11:51:02 -05:00
v2fly/proxy/testing/mocks/outboundhandler.go

52 lines
1.1 KiB
Go
Raw Normal View History

package mocks
import (
"io"
"sync"
2015-12-06 05:00:10 -05:00
"github.com/v2ray/v2ray-core/app"
2016-01-29 08:39:55 -05:00
v2io "github.com/v2ray/v2ray-core/common/io"
v2net "github.com/v2ray/v2ray-core/common/net"
2016-01-02 17:32:18 -05:00
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/transport/ray"
)
type OutboundConnectionHandler struct {
Destination v2net.Destination
ConnInput io.Reader
ConnOutput io.Writer
}
func (this *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray.OutboundRay) error {
input := ray.OutboundInput()
output := ray.OutboundOutput()
this.Destination = packet.Destination()
if packet.Chunk() != nil {
this.ConnOutput.Write(packet.Chunk().Value)
packet.Chunk().Release()
}
if packet.MoreChunks() {
writeFinish := &sync.Mutex{}
writeFinish.Lock()
go func() {
2016-02-01 06:22:29 -05:00
v2io.ChanToRawWriter(this.ConnOutput, input)
writeFinish.Unlock()
}()
writeFinish.Lock()
}
2016-01-29 08:39:55 -05:00
v2io.RawReaderToChan(output, this.ConnInput)
close(output)
return nil
}
func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
return this, nil
}