Compare commits

...

4 Commits

Author SHA1 Message Date
zu1k
1fee5e87ff rename func 2020-08-18 19:07:52 +08:00
zu1k
2ba481e388 clean for all 2020-08-18 19:06:47 +08:00
zu1k
daea47552d opti 2020-08-18 18:37:38 +08:00
zu1k
59ea871190 fix proxy list clone 2020-08-18 18:31:45 +08:00
8 changed files with 34 additions and 10 deletions

4
app/cache/cache.go vendored
View File

@@ -13,10 +13,10 @@ var c = cache.New(cache.NoExpiration, 10*time.Minute)
func GetProxies(key string) proxy.ProxyList {
result, found := c.Get(key)
if found {
log.Println(len(result.(proxy.ProxyList)))
log.Println("found cache for:", key, "length:", len(result.(proxy.ProxyList)))
return result.(proxy.ProxyList)
}
log.Println("Cache not found")
log.Println("cache not found:", key)
return nil
}

View File

@@ -39,17 +39,13 @@ func CrawlGo() {
// 节点去重
proxies = proxies.Deduplication()
log.Println("CrawlGo node count:", len(proxies))
proxies = provider.Clash{Proxies: proxies}.CleanProxies()
proxies.NameAddCounrty().Sort().NameAddIndex()
cache.SetProxies("allproxies", proxies)
// 可用性检测
proxiesUseful := proxy.CleanProxies(provider.Clash{Proxies: proxies}.CleanProxies())
proxies = make(proxy.ProxyList, len(proxiesUseful))
copy(proxies, proxiesUseful)
proxies = proxy.CleanBadProxies(proxies)
log.Println("CrawlGo clash useable node count:", len(proxies))
// 排序和重命名
proxies.NameAddCounrty().Sort().NameAddIndex()
cache.SetProxies("proxies", proxies)

View File

@@ -23,6 +23,11 @@ func (b *Base) BaseInfo() *Base {
return b
}
func (b *Base) Clone() Base {
c := *b
return c
}
type Proxy interface {
String() string
ToClash() string
@@ -31,4 +36,5 @@ type Proxy interface {
SetName(name string)
TypeName() string
BaseInfo() *Base
Clone() Proxy
}

View File

@@ -35,7 +35,7 @@ func testDelay(p Proxy) (delay uint16, err error) {
return delay, err
}
func CleanProxies(proxies []Proxy) (cproxies []Proxy) {
func CleanBadProxies(proxies []Proxy) (cproxies []Proxy) {
c := make(chan checkResult, 40)
defer close(c)
for _, p := range proxies {
@@ -52,7 +52,7 @@ func CleanProxies(proxies []Proxy) (cproxies []Proxy) {
cproxies = make([]Proxy, 0)
for _, p := range proxies {
if _, ok := okMap[p.Identifier()]; ok {
cproxies = append(cproxies, p)
cproxies = append(cproxies, p.Clone())
}
}
return

View File

@@ -71,3 +71,13 @@ func Deduplication(src ProxyList) ProxyList {
}
return result
}
func (ps ProxyList) Clone() ProxyList {
result := make(ProxyList, 0, len(ps))
for _, pp := range ps {
if pp != nil {
result = append(result, pp.Clone())
}
}
return result
}

View File

@@ -61,6 +61,10 @@ func (ss Shadowsocks) ToSurge() string {
}
}
func (ss Shadowsocks) Clone() Proxy {
return &ss
}
func ParseSSLink(link string) (*Shadowsocks, error) {
if !strings.HasPrefix(link, "ss://") {
return nil, ErrorNotSSRLink

View File

@@ -57,6 +57,10 @@ func (ssr ShadowsocksR) ToSurge() string {
return ""
}
func (ssr ShadowsocksR) Clone() Proxy {
return &ssr
}
func ParseSSRLink(link string) (*ShadowsocksR, error) {
if !strings.HasPrefix(link, "ssr") {
return nil, ErrorNotSSRLink

View File

@@ -82,6 +82,10 @@ func (v Vmess) ToSurge() string {
}
}
func (v Vmess) Clone() Proxy {
return &v
}
type vmessLinkJson struct {
Add string `json:"add"`
V string `json:"v"`