mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-13 04:46:40 -05:00
fix lint warnings
This commit is contained in:
parent
4cbcd2fd8d
commit
a24b11af27
@ -20,7 +20,7 @@ func TestProxyDial(t *testing.T) {
|
|||||||
|
|
||||||
space := app.NewSpace()
|
space := app.NewSpace()
|
||||||
outboundManager := outbound.New()
|
outboundManager := outbound.New()
|
||||||
outboundManager.SetHandler("tag", freedom.NewFreedomConnection(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{
|
outboundManager.SetHandler("tag", freedom.New(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{
|
||||||
Tag: "tag",
|
Tag: "tag",
|
||||||
StreamSettings: &internet.StreamConfig{
|
StreamSettings: &internet.StreamConfig{
|
||||||
Network: v2net.Network_RawTCP,
|
Network: v2net.Network_RawTCP,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// Package blackhole is an outbound handler that blocks all connections.
|
||||||
package blackhole
|
package blackhole
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -15,18 +15,23 @@ Content-Length: 0
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ResponseConfig is the configuration for blackhole responses.
|
||||||
type ResponseConfig interface {
|
type ResponseConfig interface {
|
||||||
|
// WriteTo writes predefined response to the give buffer.
|
||||||
WriteTo(buf.Writer)
|
WriteTo(buf.Writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteTo implements ResponseConfig.WriteTo().
|
||||||
func (v *NoneResponse) WriteTo(buf.Writer) {}
|
func (v *NoneResponse) WriteTo(buf.Writer) {}
|
||||||
|
|
||||||
|
// WriteTo implements ResponseConfig.WriteTo().
|
||||||
func (v *HTTPResponse) WriteTo(writer buf.Writer) {
|
func (v *HTTPResponse) WriteTo(writer buf.Writer) {
|
||||||
b := buf.NewLocal(512)
|
b := buf.NewLocal(512)
|
||||||
b.AppendSupplier(serial.WriteString(http403response))
|
b.AppendSupplier(serial.WriteString(http403response))
|
||||||
writer.Write(b)
|
writer.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInternalResponse converts response settings from proto to internal data structure.
|
||||||
func (v *Config) GetInternalResponse() (ResponseConfig, error) {
|
func (v *Config) GetInternalResponse() (ResponseConfig, error) {
|
||||||
if v.GetResponse() == nil {
|
if v.GetResponse() == nil {
|
||||||
return new(NoneResponse), nil
|
return new(NoneResponse), nil
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetPredefinedAddress returns the defined address from proto config. Null if address is not valid.
|
||||||
func (v *Config) GetPredefinedAddress() v2net.Address {
|
func (v *Config) GetPredefinedAddress() v2net.Address {
|
||||||
addr := v.Address.AsAddress()
|
addr := v.Address.AsAddress()
|
||||||
if addr == nil {
|
if addr == nil {
|
||||||
|
@ -40,7 +40,7 @@ func TestDokodemoTCP(t *testing.T) {
|
|||||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||||
ohm := outbound.New()
|
ohm := outbound.New()
|
||||||
ohm.SetDefaultHandler(
|
ohm.SetDefaultHandler(
|
||||||
freedom.NewFreedomConnection(
|
freedom.New(
|
||||||
&freedom.Config{},
|
&freedom.Config{},
|
||||||
space,
|
space,
|
||||||
&proxy.OutboundHandlerMeta{
|
&proxy.OutboundHandlerMeta{
|
||||||
@ -111,7 +111,7 @@ func TestDokodemoUDP(t *testing.T) {
|
|||||||
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
|
||||||
ohm := outbound.New()
|
ohm := outbound.New()
|
||||||
ohm.SetDefaultHandler(
|
ohm.SetDefaultHandler(
|
||||||
freedom.NewFreedomConnection(
|
freedom.New(
|
||||||
&freedom.Config{},
|
&freedom.Config{},
|
||||||
space,
|
space,
|
||||||
&proxy.OutboundHandlerMeta{
|
&proxy.OutboundHandlerMeta{
|
||||||
|
@ -18,15 +18,15 @@ import (
|
|||||||
"v2ray.com/core/transport/ray"
|
"v2ray.com/core/transport/ray"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FreedomConnection struct {
|
type Handler struct {
|
||||||
domainStrategy Config_DomainStrategy
|
domainStrategy Config_DomainStrategy
|
||||||
timeout uint32
|
timeout uint32
|
||||||
dns dns.Server
|
dns dns.Server
|
||||||
meta *proxy.OutboundHandlerMeta
|
meta *proxy.OutboundHandlerMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundHandlerMeta) *FreedomConnection {
|
func New(config *Config, space app.Space, meta *proxy.OutboundHandlerMeta) *Handler {
|
||||||
f := &FreedomConnection{
|
f := &Handler{
|
||||||
domainStrategy: config.DomainStrategy,
|
domainStrategy: config.DomainStrategy,
|
||||||
timeout: config.Timeout,
|
timeout: config.Timeout,
|
||||||
meta: meta,
|
meta: meta,
|
||||||
@ -44,7 +44,7 @@ func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundH
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Private: Visible for testing.
|
// Private: Visible for testing.
|
||||||
func (v *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Destination {
|
func (v *Handler) ResolveIP(destination v2net.Destination) v2net.Destination {
|
||||||
if !destination.Address.Family().IsDomain() {
|
if !destination.Address.Family().IsDomain() {
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func (v *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Desti
|
|||||||
return newDest
|
return newDest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FreedomConnection) Dispatch(destination v2net.Destination, payload *buf.Buffer, ray ray.OutboundRay) {
|
func (v *Handler) Dispatch(destination v2net.Destination, payload *buf.Buffer, ray ray.OutboundRay) {
|
||||||
log.Info("Freedom: Opening connection to ", destination)
|
log.Info("Freedom: Opening connection to ", destination)
|
||||||
|
|
||||||
defer payload.Release()
|
defer payload.Release()
|
||||||
@ -128,18 +128,18 @@ func (v *FreedomConnection) Dispatch(destination v2net.Destination, payload *buf
|
|||||||
ray.OutboundOutput().Close()
|
ray.OutboundOutput().Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
type FreedomFactory struct{}
|
type Factory struct{}
|
||||||
|
|
||||||
func (v *FreedomFactory) 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},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FreedomFactory) 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 NewFreedomConnection(config.(*Config), space, meta), nil
|
return New(config.(*Config), space, meta), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(FreedomFactory))
|
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func TestSinglePacket(t *testing.T) {
|
|||||||
assert.Error(err).IsNil()
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
space := app.NewSpace()
|
space := app.NewSpace()
|
||||||
freedom := NewFreedomConnection(
|
freedom := New(
|
||||||
&Config{},
|
&Config{},
|
||||||
space,
|
space,
|
||||||
&proxy.OutboundHandlerMeta{
|
&proxy.OutboundHandlerMeta{
|
||||||
@ -45,7 +45,7 @@ func TestSinglePacket(t *testing.T) {
|
|||||||
Network: v2net.Network_RawTCP,
|
Network: v2net.Network_RawTCP,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
space.Initialize()
|
assert.Error(space.Initialize()).IsNil()
|
||||||
|
|
||||||
traffic := ray.NewRay()
|
traffic := ray.NewRay()
|
||||||
data2Send := "Data to be sent to remote"
|
data2Send := "Data to be sent to remote"
|
||||||
@ -77,7 +77,7 @@ func TestIPResolution(t *testing.T) {
|
|||||||
})
|
})
|
||||||
space.BindApp(dns.APP_ID, dnsServer)
|
space.BindApp(dns.APP_ID, dnsServer)
|
||||||
|
|
||||||
freedom := NewFreedomConnection(
|
freedom := New(
|
||||||
&Config{DomainStrategy: Config_USE_IP},
|
&Config{DomainStrategy: Config_USE_IP},
|
||||||
space,
|
space,
|
||||||
&proxy.OutboundHandlerMeta{
|
&proxy.OutboundHandlerMeta{
|
||||||
@ -87,7 +87,7 @@ func TestIPResolution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
space.Initialize()
|
assert.Error(space.Initialize()).IsNil()
|
||||||
|
|
||||||
ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
|
ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
|
||||||
assert.Destination(ipDest).IsTCP()
|
assert.Destination(ipDest).IsTCP()
|
||||||
|
Loading…
Reference in New Issue
Block a user