Style: rename Generator with Dial

This commit is contained in:
gVisor bot 2019-03-03 11:59:07 +08:00
parent 41531ddec9
commit e3614e0605
13 changed files with 19 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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