Ver código fonte

fix lint warnings

Darien Raymond 8 anos atrás
pai
commit
a24b11af27

+ 1 - 1
app/proxy/proxy_test.go

@@ -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,

+ 1 - 0
proxy/blackhole/blackhole.go

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

+ 5 - 0
proxy/blackhole/config.go

@@ -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

+ 1 - 0
proxy/dokodemo/config.go

@@ -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 {

+ 2 - 2
proxy/dokodemo/dokodemo_test.go

@@ -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{

+ 10 - 10
proxy/freedom/freedom.go

@@ -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))
 }

+ 4 - 4
proxy/freedom/freedom_test.go

@@ -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()