1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-27 12:36:34 -05:00
This commit is contained in:
Darien Raymond 2016-12-21 21:43:00 +01:00
parent 25c64f9694
commit 25533412db
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 12 additions and 6 deletions

View File

@ -8,24 +8,26 @@ import (
"v2ray.com/core/transport/ray" "v2ray.com/core/transport/ray"
) )
// BlackHole is an outbound connection that sliently swallow the entire payload. // Handler is an outbound connection that sliently swallow the entire payload.
type BlackHole struct { type Handler struct {
meta *proxy.OutboundHandlerMeta meta *proxy.OutboundHandlerMeta
response ResponseConfig response ResponseConfig
} }
func NewBlackHole(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) (*BlackHole, error) { // New creates a new blackhole handler.
func New(space app.Space, config *Config, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
response, err := config.GetInternalResponse() response, err := config.GetInternalResponse()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &BlackHole{ return &Handler{
meta: meta, meta: meta,
response: response, response: response,
}, nil }, nil
} }
func (v *BlackHole) Dispatch(destination v2net.Destination, payload *buf.Buffer, ray ray.OutboundRay) { // Dispatch implements OutboundHandler.Dispatch().
func (v *Handler) Dispatch(destination v2net.Destination, payload *buf.Buffer, ray ray.OutboundRay) {
payload.Release() payload.Release()
v.response.WriteTo(ray.OutboundOutput()) v.response.WriteTo(ray.OutboundOutput())
@ -34,14 +36,17 @@ func (v *BlackHole) Dispatch(destination v2net.Destination, payload *buf.Buffer,
ray.OutboundInput().Release() ray.OutboundInput().Release()
} }
// Factory is an utility for creating blackhole handlers.
type Factory struct{} type Factory struct{}
// StreamCapability implements OutboundHandlerFactory.StreamCapability().
func (v *Factory) StreamCapability() v2net.NetworkList { func (v *Factory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{ return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP}, Network: []v2net.Network{v2net.Network_RawTCP},
} }
} }
// Create implements OutboundHandlerFactory.Create().
func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) { func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
return NewBlackHole(space, config.(*Config), meta) return New(space, config.(*Config), meta)
} }

View File

@ -2,6 +2,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"v2ray.com/core/common/errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
"v2ray.com/core/proxy/blackhole" "v2ray.com/core/proxy/blackhole"