mirror of https://github.com/dnomd343/XProxy.git
Dnomd343
1 year ago
4 changed files with 89 additions and 40 deletions
@ -1,29 +1,75 @@ |
|||||
package assets |
package assets |
||||
|
|
||||
|
import ( |
||||
|
"XProxy/next/logger" |
||||
|
urlpkg "net/url" |
||||
|
"strings" |
||||
|
"sync" |
||||
|
) |
||||
|
|
||||
var buildinAssets = map[string]string{ |
var buildinAssets = map[string]string{ |
||||
"geoip.dat": "geoip.dat.xz", |
"geoip.dat": "/geoip.dat.xz", |
||||
"geosite.dat": "geosite.dat.xz", |
"geosite.dat": "/geosite.dat.xz", |
||||
|
} |
||||
|
|
||||
|
type UpdateSettings struct { |
||||
|
cron string |
||||
|
mutex sync.Mutex |
||||
|
proxy *urlpkg.URL |
||||
|
assets map[string]string |
||||
} |
} |
||||
|
|
||||
func Demo() { |
var update UpdateSettings |
||||
|
|
||||
remoteAssets := map[string]string{ |
func assetsClone(raw map[string]string) map[string]string { |
||||
"geoip.dat": "https://cdn.dnomd343.top/v2ray-rules-dat/geoip.dat.xz", |
assets := make(map[string]string, len(raw)) |
||||
"geosite.dat": "https://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", |
for file, url := range raw { |
||||
|
assets[file] = strings.Clone(url) |
||||
} |
} |
||||
|
return assets |
||||
|
} |
||||
|
|
||||
|
func SetCron(cron string) error { |
||||
|
// TODO: setting up crond service
|
||||
|
return nil |
||||
|
} |
||||
|
|
||||
//updateLocalAssets(buildinAssets, true)
|
func GetProxy() string { |
||||
//updateLocalAssets(buildinAssets, false)
|
update.mutex.Lock() |
||||
|
proxy := update.proxy.String() |
||||
|
update.mutex.Unlock() |
||||
|
return proxy |
||||
|
} |
||||
|
|
||||
updateRemoteAssets(remoteAssets, "", true) |
func SetProxy(proxy string) error { |
||||
//updateRemoteAssets(remoteAssets, "", false)
|
var proxyUrl *urlpkg.URL // clear proxy by empty string
|
||||
//updateRemoteAssets(remoteAssets, "socks5://192.168.2.2:1084", true)
|
if proxy != "" { |
||||
//updateRemoteAssets(remoteAssets, "socks5://192.168.2.2:1084", false)
|
url, err := urlpkg.Parse(proxy) |
||||
|
if err != nil { |
||||
|
logger.Errorf("Invalid proxy url `%s` -> %v", proxy, err) |
||||
|
return err |
||||
|
} |
||||
|
proxyUrl = url |
||||
|
} |
||||
|
update.mutex.Lock() |
||||
|
update.proxy = proxyUrl |
||||
|
update.mutex.Unlock() |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
//time.Sleep(10 * time.Second)
|
func SetAssets(assets map[string]string) { |
||||
|
update.mutex.Lock() |
||||
|
update.assets = assetsClone(assets) |
||||
|
update.mutex.Unlock() |
||||
|
} |
||||
|
|
||||
//updateRemoteAsset("geosite.dat", "http://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", "")
|
func GetAssets() map[string]string { |
||||
//updateRemoteAsset("geosite.dat", "http://cdn.dnomd343.top/v2ray-rules-dat/geosite.dat.xz", "socks5://192.168.2.2:1084")
|
update.mutex.Lock() |
||||
//updateLocalAsset("geosite.dat", "geosite.dat.xz")
|
assets := assetsClone(update.assets) |
||||
|
update.mutex.Unlock() |
||||
|
return assets |
||||
|
} |
||||
|
|
||||
|
func LoadBuildin() { |
||||
|
updateLocalAssets(buildinAssets, true) |
||||
} |
} |
||||
|
Loading…
Reference in new issue