outboundhandler.go 761 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 OutboundConnectionHandler struct {
  8. Data2Send *bytes.Buffer
  9. Data2Return []byte
  10. Destination *v2net.Destination
  11. }
  12. func (handler *OutboundConnectionHandler) Start(ray core.OutboundRay) error {
  13. input := ray.OutboundInput()
  14. output := ray.OutboundOutput()
  15. go func() {
  16. for {
  17. data, open := <-input
  18. if !open {
  19. break
  20. }
  21. handler.Data2Send.Write(data)
  22. }
  23. output <- handler.Data2Return
  24. close(output)
  25. }()
  26. return nil
  27. }
  28. func (handler *OutboundConnectionHandler) Create(point *core.Point, config []byte, dest *v2net.Destination) (core.OutboundConnectionHandler, error) {
  29. handler.Destination = dest
  30. return handler, nil
  31. }