blackhole.go 843 B

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