blackhole.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package blackhole
  2. import (
  3. "github.com/v2ray/v2ray-core/app"
  4. "github.com/v2ray/v2ray-core/common/alloc"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. "github.com/v2ray/v2ray-core/proxy"
  7. "github.com/v2ray/v2ray-core/proxy/internal"
  8. "github.com/v2ray/v2ray-core/transport/ray"
  9. )
  10. // BlackHole is an outbound connection that sliently swallow the entire payload.
  11. type BlackHole struct {
  12. meta *proxy.OutboundHandlerMeta
  13. }
  14. func NewBlackHole(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) *BlackHole {
  15. return &BlackHole{
  16. meta: meta,
  17. }
  18. }
  19. func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
  20. payload.Release()
  21. ray.OutboundOutput().Close()
  22. ray.OutboundOutput().Release()
  23. ray.OutboundInput().Close()
  24. ray.OutboundInput().Release()
  25. return nil
  26. }
  27. func init() {
  28. internal.MustRegisterOutboundHandlerCreator("blackhole",
  29. func(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
  30. return NewBlackHole(space, config.(*Config), meta), nil
  31. })
  32. }