1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00
v2fly/testing/mocks/outboundhandler.go

43 lines
848 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
}
2015-09-22 12:11:55 -04:00
func (handler *OutboundConnectionHandler) Initialize(config []byte) error {
return nil
}
func (handler *OutboundConnectionHandler) Create(point *core.Point, packet v2net.Packet) (core.OutboundConnectionHandler, error) {
handler.Destination = packet.Destination()
2015-09-19 09:35:20 -04:00
return handler, nil
}