2015-09-19 09:35:20 -04:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core"
|
2015-09-19 17:54:36 -04:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2015-09-19 09:35:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type OutboundConnectionHandler struct {
|
|
|
|
Data2Send *bytes.Buffer
|
|
|
|
Data2Return []byte
|
2015-09-20 12:22:29 -04:00
|
|
|
Destination v2net.Destination
|
2015-09-19 09:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *OutboundConnectionHandler) Start(ray core.OutboundRay) error {
|
|
|
|
input := ray.OutboundInput()
|
|
|
|
output := ray.OutboundOutput()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
data, open := <-input
|
|
|
|
if !open {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
handler.Data2Send.Write(data)
|
|
|
|
}
|
|
|
|
output <- handler.Data2Return
|
|
|
|
close(output)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-22 08:45:03 -04:00
|
|
|
func (handler *OutboundConnectionHandler) Create(point *core.Point, config []byte, packet v2net.Packet) (core.OutboundConnectionHandler, error) {
|
|
|
|
handler.Destination = packet.Destination()
|
2015-09-19 09:35:20 -04:00
|
|
|
return handler, nil
|
|
|
|
}
|