You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/testing/mocks/inboundhandler.go

39 lines
843 B

package mocks
import (
"bytes"
"github.com/v2ray/v2ray-core"
v2net "github.com/v2ray/v2ray-core/common/net"
)
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(dest *v2net.Destination) error {
ray := handler.Server.NewInboundConnectionAccepted(dest)
input := ray.InboundInput()
output := ray.InboundOutput()
input <- handler.Data2Send
close(input)
v2net.ChanToWriter(handler.DataReturned, output)
return nil
}
func (handler *InboundConnectionHandler) Create(point *core.Point, config []byte) (core.InboundConnectionHandler, error) {
handler.Server = point
return handler, nil
}