1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

fix lint warnings

This commit is contained in:
Darien Raymond 2016-12-22 13:33:28 +01:00
parent 4cbcd2fd8d
commit a24b11af27
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
7 changed files with 24 additions and 17 deletions

View File

@ -20,7 +20,7 @@ func TestProxyDial(t *testing.T) {
space := app.NewSpace()
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",
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,

View File

@ -1,3 +1,4 @@
// Package blackhole is an outbound handler that blocks all connections.
package blackhole
import (

View File

@ -15,18 +15,23 @@ Content-Length: 0
`
)
// ResponseConfig is the configuration for blackhole responses.
type ResponseConfig interface {
// WriteTo writes predefined response to the give buffer.
WriteTo(buf.Writer)
}
// WriteTo implements ResponseConfig.WriteTo().
func (v *NoneResponse) WriteTo(buf.Writer) {}
// WriteTo implements ResponseConfig.WriteTo().
func (v *HTTPResponse) WriteTo(writer buf.Writer) {
b := buf.NewLocal(512)
b.AppendSupplier(serial.WriteString(http403response))
writer.Write(b)
}
// GetInternalResponse converts response settings from proto to internal data structure.
func (v *Config) GetInternalResponse() (ResponseConfig, error) {
if v.GetResponse() == nil {
return new(NoneResponse), nil

View File

@ -4,6 +4,7 @@ import (
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 {
addr := v.Address.AsAddress()
if addr == nil {

View File

@ -40,7 +40,7 @@ func TestDokodemoTCP(t *testing.T) {
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
ohm := outbound.New()
ohm.SetDefaultHandler(
freedom.NewFreedomConnection(
freedom.New(
&freedom.Config{},
space,
&proxy.OutboundHandlerMeta{
@ -111,7 +111,7 @@ func TestDokodemoUDP(t *testing.T) {
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
ohm := outbound.New()
ohm.SetDefaultHandler(
freedom.NewFreedomConnection(
freedom.New(
&freedom.Config{},
space,
&proxy.OutboundHandlerMeta{

View File

@ -18,15 +18,15 @@ import (
"v2ray.com/core/transport/ray"
)
type FreedomConnection struct {
type Handler struct {
domainStrategy Config_DomainStrategy
timeout uint32
dns dns.Server
meta *proxy.OutboundHandlerMeta
}
func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundHandlerMeta) *FreedomConnection {
f := &FreedomConnection{
func New(config *Config, space app.Space, meta *proxy.OutboundHandlerMeta) *Handler {
f := &Handler{
domainStrategy: config.DomainStrategy,
timeout: config.Timeout,
meta: meta,
@ -44,7 +44,7 @@ func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundH
}
// 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() {
return destination
}
@ -66,7 +66,7 @@ func (v *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Desti
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)
defer payload.Release()
@ -128,18 +128,18 @@ func (v *FreedomConnection) Dispatch(destination v2net.Destination, payload *buf
ray.OutboundOutput().Close()
}
type FreedomFactory struct{}
type Factory struct{}
func (v *FreedomFactory) StreamCapability() v2net.NetworkList {
func (v *Factory) StreamCapability() v2net.NetworkList {
return v2net.NetworkList{
Network: []v2net.Network{v2net.Network_RawTCP},
}
}
func (v *FreedomFactory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
return NewFreedomConnection(config.(*Config), space, meta), nil
func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
return New(config.(*Config), space, meta), nil
}
func init() {
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(FreedomFactory))
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
}

View File

@ -36,7 +36,7 @@ func TestSinglePacket(t *testing.T) {
assert.Error(err).IsNil()
space := app.NewSpace()
freedom := NewFreedomConnection(
freedom := New(
&Config{},
space,
&proxy.OutboundHandlerMeta{
@ -45,7 +45,7 @@ func TestSinglePacket(t *testing.T) {
Network: v2net.Network_RawTCP,
},
})
space.Initialize()
assert.Error(space.Initialize()).IsNil()
traffic := ray.NewRay()
data2Send := "Data to be sent to remote"
@ -77,7 +77,7 @@ func TestIPResolution(t *testing.T) {
})
space.BindApp(dns.APP_ID, dnsServer)
freedom := NewFreedomConnection(
freedom := New(
&Config{DomainStrategy: Config_USE_IP},
space,
&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)))
assert.Destination(ipDest).IsTCP()