2015-09-19 15:56:09 -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 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
|
|
|
|
}
|
|
|
|
|
2015-09-20 12:22:29 -04:00
|
|
|
func (handler *InboundConnectionHandler) Communicate(dest v2net.Destination) error {
|
2015-09-19 15:56:09 -04:00
|
|
|
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
|
|
|
|
}
|