mirror of https://github.com/Dreamacro/clash.git
Style: rename `Generator` with `Dial`
This commit is contained in:
parent
23bb01a4df
commit
7683271fe6
|
@ -10,7 +10,7 @@ type Direct struct {
|
||||||
*Base
|
*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)
|
address := net.JoinHostPort(metadata.Host, metadata.Port)
|
||||||
if metadata.IP != nil {
|
if metadata.IP != nil {
|
||||||
address = net.JoinHostPort(metadata.IP.String(), metadata.Port)
|
address = net.JoinHostPort(metadata.IP.String(), metadata.Port)
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (f *Fallback) Now() string {
|
||||||
return f.proxies[0].RawProxy.Name()
|
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
|
idx := 0
|
||||||
var proxy *proxy
|
var proxy *proxy
|
||||||
for {
|
for {
|
||||||
|
@ -46,7 +46,7 @@ func (f *Fallback) Generator(metadata *C.Metadata) (net.Conn, error) {
|
||||||
if proxy == nil {
|
if proxy == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
adapter, err := proxy.RawProxy.Generator(metadata)
|
adapter, err := proxy.RawProxy.Dial(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
proxy.Valid = false
|
proxy.Valid = false
|
||||||
idx++
|
idx++
|
||||||
|
@ -54,7 +54,7 @@ func (f *Fallback) Generator(metadata *C.Metadata) (net.Conn, error) {
|
||||||
}
|
}
|
||||||
return adapter, err
|
return adapter, err
|
||||||
}
|
}
|
||||||
return f.proxies[0].RawProxy.Generator(metadata)
|
return f.proxies[0].RawProxy.Dial(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fallback) MarshalJSON() ([]byte, error) {
|
func (f *Fallback) MarshalJSON() ([]byte, error) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ type HttpOption struct {
|
||||||
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
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)
|
c, err := net.DialTimeout("tcp", h.addr, tcpTimeout)
|
||||||
if err == nil && h.tls {
|
if err == nil && h.tls {
|
||||||
cc := tls.Client(c, h.tlsConfig)
|
cc := tls.Client(c, h.tlsConfig)
|
||||||
|
|
|
@ -48,18 +48,18 @@ func jumpHash(key uint64, buckets int32) int32 {
|
||||||
return int32(b)
|
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))))
|
key := uint64(murmur3.Sum32([]byte(getKey(metadata))))
|
||||||
buckets := int32(len(lb.proxies))
|
buckets := int32(len(lb.proxies))
|
||||||
for i := 0; i < lb.maxRetry; i++ {
|
for i := 0; i < lb.maxRetry; i++ {
|
||||||
idx := jumpHash(key, buckets)
|
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
|
return proxy, nil
|
||||||
}
|
}
|
||||||
key++
|
key++
|
||||||
}
|
}
|
||||||
|
|
||||||
return lb.proxies[0].Generator(metadata)
|
return lb.proxies[0].Dial(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lb *LoadBalance) MarshalJSON() ([]byte, error) {
|
func (lb *LoadBalance) MarshalJSON() ([]byte, error) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ type Reject struct {
|
||||||
*Base
|
*Base
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reject) Generator(metadata *C.Metadata) (net.Conn, error) {
|
func (r *Reject) Dial(metadata *C.Metadata) (net.Conn, error) {
|
||||||
return &NopConn{}, nil
|
return &NopConn{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ type SelectorOption struct {
|
||||||
Proxies []string `proxy:"proxies"`
|
Proxies []string `proxy:"proxies"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) Generator(metadata *C.Metadata) (net.Conn, error) {
|
func (s *Selector) Dial(metadata *C.Metadata) (net.Conn, error) {
|
||||||
return s.selected.Generator(metadata)
|
return s.selected.Dial(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) MarshalJSON() ([]byte, error) {
|
func (s *Selector) MarshalJSON() ([]byte, error) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ type v2rayObfsOption struct {
|
||||||
SkipCertVerify bool `obfs:"skip-cert-verify,omitempty"`
|
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)
|
c, err := net.DialTimeout("tcp", ss.server, tcpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
|
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
|
||||||
|
|
|
@ -34,7 +34,7 @@ type Socks5Option struct {
|
||||||
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
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)
|
c, err := net.DialTimeout("tcp", ss.addr, tcpTimeout)
|
||||||
|
|
||||||
if err == nil && ss.tls {
|
if err == nil && ss.tls {
|
||||||
|
|
|
@ -33,8 +33,8 @@ func (u *URLTest) Now() string {
|
||||||
return u.fast.Name()
|
return u.fast.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *URLTest) Generator(metadata *C.Metadata) (net.Conn, error) {
|
func (u *URLTest) Dial(metadata *C.Metadata) (net.Conn, error) {
|
||||||
a, err := u.fast.Generator(metadata)
|
a, err := u.fast.Dial(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
go u.speedTest()
|
go u.speedTest()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func DelayTest(proxy C.Proxy, url string) (t int16, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
instance, err := proxy.Generator(&addr)
|
instance, err := proxy.Dial(&addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ type VmessOption struct {
|
||||||
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
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)
|
c, err := net.DialTimeout("tcp", v.server, tcpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error", v.server)
|
return nil, fmt.Errorf("%s connect error", v.server)
|
||||||
|
|
|
@ -26,7 +26,7 @@ type ServerAdapter interface {
|
||||||
type Proxy interface {
|
type Proxy interface {
|
||||||
Name() string
|
Name() string
|
||||||
Type() AdapterType
|
Type() AdapterType
|
||||||
Generator(metadata *Metadata) (net.Conn, error)
|
Dial(metadata *Metadata) (net.Conn, error)
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ func (t *Tunnel) handleConn(localConn C.ServerAdapter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remoConn, err := proxy.Generator(metadata)
|
remoConn, err := proxy.Dial(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("Proxy[%s] connect [%s --> %s] error: %s", proxy.Name(), metadata.SourceIP.String(), metadata.String(), err.Error())
|
log.Warnln("Proxy[%s] connect [%s --> %s] error: %s", proxy.Name(), metadata.SourceIP.String(), metadata.String(), err.Error())
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue