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

39 lines
772 B
Go
Raw Normal View History

2015-09-19 09:35:20 -04:00
package mocks
import (
"bytes"
"github.com/v2ray/v2ray-core"
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
}
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
}