inboundhandler.go 843 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package mocks
  2. import (
  3. "bytes"
  4. "github.com/v2ray/v2ray-core"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. )
  7. type InboundConnectionHandler struct {
  8. Data2Send []byte
  9. DataReturned *bytes.Buffer
  10. Port uint16
  11. Server *core.Point
  12. }
  13. func (handler *InboundConnectionHandler) Listen(port uint16) error {
  14. handler.Port = port
  15. return nil
  16. }
  17. func (handler *InboundConnectionHandler) Communicate(dest *v2net.Destination) error {
  18. ray := handler.Server.NewInboundConnectionAccepted(dest)
  19. input := ray.InboundInput()
  20. output := ray.InboundOutput()
  21. input <- handler.Data2Send
  22. close(input)
  23. v2net.ChanToWriter(handler.DataReturned, output)
  24. return nil
  25. }
  26. func (handler *InboundConnectionHandler) Create(point *core.Point, config []byte) (core.InboundConnectionHandler, error) {
  27. handler.Server = point
  28. return handler, nil
  29. }