blackhole.go 926 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package blackhole
  2. import (
  3. "io/ioutil"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. "github.com/v2ray/v2ray-core/proxy/common/connhandler"
  6. "github.com/v2ray/v2ray-core/transport/ray"
  7. )
  8. // BlackHole is an outbound connection that sliently swallow the entire payload.
  9. type BlackHole struct {
  10. }
  11. func NewBlackHole() *BlackHole {
  12. return &BlackHole{}
  13. }
  14. func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
  15. if chunk := firstPacket.Chunk(); chunk != nil {
  16. chunk.Release()
  17. }
  18. close(ray.OutboundOutput())
  19. if firstPacket.MoreChunks() {
  20. v2net.ChanToWriter(ioutil.Discard, ray.OutboundInput())
  21. }
  22. return nil
  23. }
  24. type BlackHoleFactory struct {
  25. }
  26. func (this BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
  27. return NewBlackHole(), nil
  28. }
  29. func init() {
  30. connhandler.RegisterOutboundConnectionHandlerFactory("blackhole", BlackHoleFactory{})
  31. }