2015-09-19 15:56:09 -04:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2015-10-14 08:51:19 -04:00
|
|
|
"github.com/v2ray/v2ray-core/app"
|
2015-10-08 08:46:18 -04:00
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
2015-09-19 17:54:36 -04:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2015-10-29 19:11:29 -04:00
|
|
|
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
2015-09-19 15:56:09 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type InboundConnectionHandler struct {
|
|
|
|
Data2Send []byte
|
|
|
|
DataReturned *bytes.Buffer
|
|
|
|
Port uint16
|
2015-10-14 08:51:19 -04:00
|
|
|
Dispatcher app.PacketDispatcher
|
2015-09-19 15:56:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *InboundConnectionHandler) Listen(port uint16) error {
|
|
|
|
handler.Port = port
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-22 08:45:03 -04:00
|
|
|
func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error {
|
2015-10-14 08:51:19 -04:00
|
|
|
ray := handler.Dispatcher.DispatchToOutbound(packet)
|
2015-09-19 15:56:09 -04:00
|
|
|
|
|
|
|
input := ray.InboundInput()
|
|
|
|
output := ray.InboundOutput()
|
|
|
|
|
2015-10-08 08:46:18 -04:00
|
|
|
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-29 19:11:29 -04:00
|
|
|
func (handler *InboundConnectionHandler) Create(dispatcher app.PacketDispatcher, config interface{}) (connhandler.InboundConnectionHandler, error) {
|
2015-10-14 08:51:19 -04:00
|
|
|
handler.Dispatcher = dispatcher
|
2015-09-19 15:56:09 -04:00
|
|
|
return handler, nil
|
|
|
|
}
|