From e3614e060515457eaaa1ef18765d1e7db4697e67 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 3 Mar 2019 11:59:07 +0800 Subject: [PATCH] Style: rename `Generator` with `Dial` --- adapters/outbound/direct.go | 2 +- adapters/outbound/fallback.go | 6 +++--- adapters/outbound/http.go | 2 +- adapters/outbound/loadbalance.go | 6 +++--- adapters/outbound/reject.go | 2 +- adapters/outbound/selector.go | 4 ++-- adapters/outbound/shadowsocks.go | 2 +- adapters/outbound/socks5.go | 2 +- adapters/outbound/urltest.go | 4 ++-- adapters/outbound/util.go | 2 +- adapters/outbound/vmess.go | 2 +- constant/adapters.go | 2 +- tunnel/tunnel.go | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/adapters/outbound/direct.go b/adapters/outbound/direct.go index b46bf500..245c28b3 100644 --- a/adapters/outbound/direct.go +++ b/adapters/outbound/direct.go @@ -10,7 +10,7 @@ type Direct struct { *Base } -func (d *Direct) Generator(metadata *C.Metadata) (net.Conn, error) { +func (d *Direct) Dial(metadata *C.Metadata) (net.Conn, error) { address := net.JoinHostPort(metadata.Host, metadata.Port) if metadata.IP != nil { address = net.JoinHostPort(metadata.IP.String(), metadata.Port) diff --git a/adapters/outbound/fallback.go b/adapters/outbound/fallback.go index ea456fd3..00073010 100644 --- a/adapters/outbound/fallback.go +++ b/adapters/outbound/fallback.go @@ -38,7 +38,7 @@ func (f *Fallback) Now() string { return f.proxies[0].RawProxy.Name() } -func (f *Fallback) Generator(metadata *C.Metadata) (net.Conn, error) { +func (f *Fallback) Dial(metadata *C.Metadata) (net.Conn, error) { idx := 0 var proxy *proxy for { @@ -46,7 +46,7 @@ func (f *Fallback) Generator(metadata *C.Metadata) (net.Conn, error) { if proxy == nil { break } - adapter, err := proxy.RawProxy.Generator(metadata) + adapter, err := proxy.RawProxy.Dial(metadata) if err != nil { proxy.Valid = false idx++ @@ -54,7 +54,7 @@ func (f *Fallback) Generator(metadata *C.Metadata) (net.Conn, error) { } return adapter, err } - return f.proxies[0].RawProxy.Generator(metadata) + return f.proxies[0].RawProxy.Dial(metadata) } func (f *Fallback) MarshalJSON() ([]byte, error) { diff --git a/adapters/outbound/http.go b/adapters/outbound/http.go index cf1fb748..79d8b31e 100644 --- a/adapters/outbound/http.go +++ b/adapters/outbound/http.go @@ -35,7 +35,7 @@ type HttpOption struct { SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` } -func (h *Http) Generator(metadata *C.Metadata) (net.Conn, error) { +func (h *Http) Dial(metadata *C.Metadata) (net.Conn, error) { c, err := net.DialTimeout("tcp", h.addr, tcpTimeout) if err == nil && h.tls { cc := tls.Client(c, h.tlsConfig) diff --git a/adapters/outbound/loadbalance.go b/adapters/outbound/loadbalance.go index 3edeae5d..0ba08731 100644 --- a/adapters/outbound/loadbalance.go +++ b/adapters/outbound/loadbalance.go @@ -48,18 +48,18 @@ func jumpHash(key uint64, buckets int32) int32 { return int32(b) } -func (lb *LoadBalance) Generator(metadata *C.Metadata) (net.Conn, error) { +func (lb *LoadBalance) Dial(metadata *C.Metadata) (net.Conn, error) { key := uint64(murmur3.Sum32([]byte(getKey(metadata)))) buckets := int32(len(lb.proxies)) for i := 0; i < lb.maxRetry; i++ { idx := jumpHash(key, buckets) - if proxy, err := lb.proxies[idx].Generator(metadata); err == nil { + if proxy, err := lb.proxies[idx].Dial(metadata); err == nil { return proxy, nil } key++ } - return lb.proxies[0].Generator(metadata) + return lb.proxies[0].Dial(metadata) } func (lb *LoadBalance) MarshalJSON() ([]byte, error) { diff --git a/adapters/outbound/reject.go b/adapters/outbound/reject.go index 9f49ae85..f78d4f45 100644 --- a/adapters/outbound/reject.go +++ b/adapters/outbound/reject.go @@ -12,7 +12,7 @@ type Reject struct { *Base } -func (r *Reject) Generator(metadata *C.Metadata) (net.Conn, error) { +func (r *Reject) Dial(metadata *C.Metadata) (net.Conn, error) { return &NopConn{}, nil } diff --git a/adapters/outbound/selector.go b/adapters/outbound/selector.go index 28f39c40..a0a126a5 100644 --- a/adapters/outbound/selector.go +++ b/adapters/outbound/selector.go @@ -20,8 +20,8 @@ type SelectorOption struct { Proxies []string `proxy:"proxies"` } -func (s *Selector) Generator(metadata *C.Metadata) (net.Conn, error) { - return s.selected.Generator(metadata) +func (s *Selector) Dial(metadata *C.Metadata) (net.Conn, error) { + return s.selected.Dial(metadata) } func (s *Selector) MarshalJSON() ([]byte, error) { diff --git a/adapters/outbound/shadowsocks.go b/adapters/outbound/shadowsocks.go index abddbb37..b4d57c0c 100644 --- a/adapters/outbound/shadowsocks.go +++ b/adapters/outbound/shadowsocks.go @@ -55,7 +55,7 @@ type v2rayObfsOption struct { SkipCertVerify bool `obfs:"skip-cert-verify,omitempty"` } -func (ss *ShadowSocks) Generator(metadata *C.Metadata) (net.Conn, error) { +func (ss *ShadowSocks) Dial(metadata *C.Metadata) (net.Conn, error) { c, err := net.DialTimeout("tcp", ss.server, tcpTimeout) if err != nil { return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error()) diff --git a/adapters/outbound/socks5.go b/adapters/outbound/socks5.go index 97e883e4..2adb999a 100644 --- a/adapters/outbound/socks5.go +++ b/adapters/outbound/socks5.go @@ -34,7 +34,7 @@ type Socks5Option struct { SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` } -func (ss *Socks5) Generator(metadata *C.Metadata) (net.Conn, error) { +func (ss *Socks5) Dial(metadata *C.Metadata) (net.Conn, error) { c, err := net.DialTimeout("tcp", ss.addr, tcpTimeout) if err == nil && ss.tls { diff --git a/adapters/outbound/urltest.go b/adapters/outbound/urltest.go index b8b144aa..5f5cfb4e 100644 --- a/adapters/outbound/urltest.go +++ b/adapters/outbound/urltest.go @@ -33,8 +33,8 @@ func (u *URLTest) Now() string { return u.fast.Name() } -func (u *URLTest) Generator(metadata *C.Metadata) (net.Conn, error) { - a, err := u.fast.Generator(metadata) +func (u *URLTest) Dial(metadata *C.Metadata) (net.Conn, error) { + a, err := u.fast.Dial(metadata) if err != nil { go u.speedTest() } diff --git a/adapters/outbound/util.go b/adapters/outbound/util.go index 6dedc9b7..5c07e955 100644 --- a/adapters/outbound/util.go +++ b/adapters/outbound/util.go @@ -29,7 +29,7 @@ func DelayTest(proxy C.Proxy, url string) (t int16, err error) { } start := time.Now() - instance, err := proxy.Generator(&addr) + instance, err := proxy.Dial(&addr) if err != nil { return } diff --git a/adapters/outbound/vmess.go b/adapters/outbound/vmess.go index 67820acc..6c137432 100644 --- a/adapters/outbound/vmess.go +++ b/adapters/outbound/vmess.go @@ -30,7 +30,7 @@ type VmessOption struct { SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` } -func (v *Vmess) Generator(metadata *C.Metadata) (net.Conn, error) { +func (v *Vmess) Dial(metadata *C.Metadata) (net.Conn, error) { c, err := net.DialTimeout("tcp", v.server, tcpTimeout) if err != nil { return nil, fmt.Errorf("%s connect error", v.server) diff --git a/constant/adapters.go b/constant/adapters.go index 082743cf..e3ce76e4 100644 --- a/constant/adapters.go +++ b/constant/adapters.go @@ -26,7 +26,7 @@ type ServerAdapter interface { type Proxy interface { Name() string Type() AdapterType - Generator(metadata *Metadata) (net.Conn, error) + Dial(metadata *Metadata) (net.Conn, error) MarshalJSON() ([]byte, error) } diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index d98ec40a..6fec24eb 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -143,7 +143,7 @@ func (t *Tunnel) handleConn(localConn C.ServerAdapter) { } } - remoConn, err := proxy.Generator(metadata) + remoConn, err := proxy.Dial(metadata) if err != nil { log.Warnln("Proxy[%s] connect [%s --> %s] error: %s", proxy.Name(), metadata.SourceIP.String(), metadata.String(), err.Error()) return