Skip to content

Commit

Permalink
fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Dec 22, 2016
1 parent 4cbcd2f commit a24b11a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions proxy/blackhole/blackhole.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package blackhole is an outbound handler that blocks all connections.
package blackhole

import (
Expand Down
5 changes: 5 additions & 0 deletions proxy/blackhole/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions proxy/dokodemo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions proxy/dokodemo/dokodemo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
20 changes: 10 additions & 10 deletions proxy/freedom/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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()
Expand Down Expand Up @@ -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))
}
8 changes: 4 additions & 4 deletions proxy/freedom/freedom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestSinglePacket(t *testing.T) {
assert.Error(err).IsNil()

space := app.NewSpace()
freedom := NewFreedomConnection(
freedom := New(
&Config{},
space,
&proxy.OutboundHandlerMeta{
Expand All @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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()
Expand Down

0 comments on commit a24b11a

Please sign in to comment.