1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

fix lint warnings

This commit is contained in:
Darien Raymond 2017-11-15 18:28:39 +01:00
parent 23f209075f
commit f3ba1dbb8c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -20,6 +20,7 @@ import (
"v2ray.com/core/transport/ray" "v2ray.com/core/transport/ray"
) )
// Handler handles Freedom connections.
type Handler struct { type Handler struct {
domainStrategy Config_DomainStrategy domainStrategy Config_DomainStrategy
timeout uint32 timeout uint32
@ -27,6 +28,7 @@ type Handler struct {
destOverride *DestinationOverride destOverride *DestinationOverride
} }
// New creates a new Freedom handler.
func New(ctx context.Context, config *Config) (*Handler, error) { func New(ctx context.Context, config *Config) (*Handler, error) {
space := app.SpaceFromContext(ctx) space := app.SpaceFromContext(ctx)
if space == nil { if space == nil {
@ -49,7 +51,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
return f, nil return f, nil
} }
func (v *Handler) ResolveIP(ctx context.Context, domain string) net.Address { func (h *Handler) resolveIP(ctx context.Context, domain string) net.Address {
if resolver, ok := proxy.ResolvedIPsFromContext(ctx); ok { if resolver, ok := proxy.ResolvedIPsFromContext(ctx); ok {
ips := resolver.Resolve() ips := resolver.Resolve()
if len(ips) == 0 { if len(ips) == 0 {
@ -58,17 +60,18 @@ func (v *Handler) ResolveIP(ctx context.Context, domain string) net.Address {
return ips[dice.Roll(len(ips))] return ips[dice.Roll(len(ips))]
} }
ips := v.dns.Get(domain) ips := h.dns.Get(domain)
if len(ips) == 0 { if len(ips) == 0 {
return nil return nil
} }
return net.IPAddress(ips[dice.Roll(len(ips))]) return net.IPAddress(ips[dice.Roll(len(ips))])
} }
func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error { // Process implements proxy.Outbound.
func (h *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dialer proxy.Dialer) error {
destination, _ := proxy.TargetFromContext(ctx) destination, _ := proxy.TargetFromContext(ctx)
if v.destOverride != nil { if h.destOverride != nil {
server := v.destOverride.Server server := h.destOverride.Server
destination = net.Destination{ destination = net.Destination{
Network: destination.Network, Network: destination.Network,
Address: server.Address.AsAddress(), Address: server.Address.AsAddress(),
@ -80,9 +83,8 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
input := outboundRay.OutboundInput() input := outboundRay.OutboundInput()
output := outboundRay.OutboundOutput() output := outboundRay.OutboundOutput()
var conn internet.Connection if h.domainStrategy == Config_USE_IP && destination.Address.Family().IsDomain() {
if v.domainStrategy == Config_USE_IP && destination.Address.Family().IsDomain() { ip := h.resolveIP(ctx, destination.Address.Domain())
ip := v.ResolveIP(ctx, destination.Address.Domain())
if ip != nil { if ip != nil {
destination = net.Destination{ destination = net.Destination{
Network: destination.Network, Network: destination.Network,
@ -93,6 +95,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
} }
} }
var conn internet.Connection
err := retry.ExponentialBackoff(5, 100).On(func() error { err := retry.ExponentialBackoff(5, 100).On(func() error {
rawConn, err := dialer.Dial(ctx, destination) rawConn, err := dialer.Dial(ctx, destination)
if err != nil { if err != nil {
@ -106,7 +109,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
} }
defer conn.Close() defer conn.Close()
timeout := time.Second * time.Duration(v.timeout) timeout := time.Second * time.Duration(h.timeout)
if timeout == 0 { if timeout == 0 {
timeout = time.Minute * 5 timeout = time.Minute * 5
} }