1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-03 17:23:43 -04:00
v2fly/testing/mocks/inboundhandler.go

43 lines
948 B
Go
Raw Normal View History

2015-09-19 15:56:09 -04:00
package mocks
import (
"bytes"
"github.com/v2ray/v2ray-core"
"github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net"
2015-09-19 15:56:09 -04:00
)
type InboundConnectionHandler struct {
Data2Send []byte
DataReturned *bytes.Buffer
Port uint16
Server *core.Point
}
func (handler *InboundConnectionHandler) Listen(port uint16) error {
handler.Port = port
return nil
}
func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error {
ray := handler.Server.DispatchToOutbound(packet)
2015-09-19 15:56:09 -04:00
input := ray.InboundInput()
output := ray.InboundOutput()
buffer := alloc.NewBuffer()
buffer.Clear()
buffer.Append(handler.Data2Send)
input <- buffer
2015-09-19 15:56:09 -04:00
close(input)
v2net.ChanToWriter(handler.DataReturned, output)
return nil
}
2015-10-06 17:11:08 -04:00
func (handler *InboundConnectionHandler) Create(point *core.Point, config interface{}) (core.InboundConnectionHandler, error) {
2015-09-19 15:56:09 -04:00
handler.Server = point
return handler, nil
}