blackhole.go 911 B

12345678910111213141516171819202122232425262728293031323334353637
  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. }
  13. func NewBlackHole() *BlackHole {
  14. return &BlackHole{}
  15. }
  16. func (this *BlackHole) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
  17. payload.Release()
  18. ray.OutboundOutput().Close()
  19. ray.OutboundOutput().Release()
  20. ray.OutboundInput().Close()
  21. ray.OutboundInput().Release()
  22. return nil
  23. }
  24. func init() {
  25. internal.MustRegisterOutboundHandlerCreator("blackhole",
  26. func(space app.Space, config interface{}) (proxy.OutboundHandler, error) {
  27. return NewBlackHole(), nil
  28. })
  29. }