2015-11-01 15:15:08 -05:00
|
|
|
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"
|
2015-11-01 15:15:08 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2016-01-02 17:32:18 -05:00
|
|
|
"github.com/v2ray/v2ray-core/proxy"
|
2015-11-01 15:15:08 -05:00
|
|
|
"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-04-18 12:44:10 -04:00
|
|
|
v2io.Pipe(input, v2io.NewAdaptiveWriter(this.ConnOutput))
|
2015-11-01 15:15:08 -05:00
|
|
|
writeFinish.Unlock()
|
2016-04-18 12:44:10 -04:00
|
|
|
input.Release()
|
2015-11-01 15:15:08 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
writeFinish.Lock()
|
|
|
|
}
|
|
|
|
|
2016-04-18 12:44:10 -04:00
|
|
|
v2io.Pipe(v2io.NewAdaptiveReader(this.ConnInput), output)
|
|
|
|
output.Close()
|
2015-11-01 15:15:08 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-25 11:18:24 -05:00
|
|
|
func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
|
2015-11-01 15:15:08 -05:00
|
|
|
return this, nil
|
|
|
|
}
|