blackhole.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package blackhole
  2. import (
  3. "v2ray.com/core/app"
  4. "v2ray.com/core/common/buf"
  5. v2net "v2ray.com/core/common/net"
  6. "v2ray.com/core/proxy"
  7. "v2ray.com/core/transport/ray"
  8. )
  9. // BlackHole is an outbound connection that sliently swallow the entire payload.
  10. type BlackHole struct {
  11. meta *proxy.OutboundHandlerMeta
  12. response ResponseConfig
  13. }
  14. func NewBlackHole(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) (*BlackHole, error) {
  15. response, err := config.GetInternalResponse()
  16. if err != nil {
  17. return nil, err
  18. }
  19. return &BlackHole{
  20. meta: meta,
  21. response: response,
  22. }, nil
  23. }
  24. func (v *BlackHole) Dispatch(destination v2net.Destination, payload *buf.Buffer, ray ray.OutboundRay) {
  25. payload.Release()
  26. v.response.WriteTo(ray.OutboundOutput())
  27. ray.OutboundOutput().Close()
  28. ray.OutboundInput().Release()
  29. }
  30. type Factory struct{}
  31. func (v *Factory) StreamCapability() v2net.NetworkList {
  32. return v2net.NetworkList{
  33. Network: []v2net.Network{v2net.Network_RawTCP},
  34. }
  35. }
  36. func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
  37. return NewBlackHole(space, config.(*Config), meta)
  38. }