mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
Fixed: the configuration can now be updated correctly
This commit is contained in:
parent
330a3391e3
commit
c2c8f82f96
|
@ -19,6 +19,7 @@ type URLTest struct {
|
|||
addr *C.Addr
|
||||
fast C.Proxy
|
||||
delay time.Duration
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (u *URLTest) Name() string {
|
||||
|
@ -29,11 +30,21 @@ func (u *URLTest) Generator(addr *C.Addr) (adapter C.ProxyAdapter, err error) {
|
|||
return u.fast.Generator(addr)
|
||||
}
|
||||
|
||||
func (u *URLTest) Close() {
|
||||
u.done <- struct{}{}
|
||||
}
|
||||
|
||||
func (u *URLTest) loop() {
|
||||
tick := time.Tick(u.delay)
|
||||
tick := time.NewTicker(u.delay)
|
||||
go u.speedTest()
|
||||
for range tick {
|
||||
go u.speedTest()
|
||||
Loop:
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
go u.speedTest()
|
||||
case <-u.done:
|
||||
break Loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,6 +153,7 @@ func NewURLTest(name string, proxys []C.Proxy, rawURL string, delay time.Duratio
|
|||
addr: addr,
|
||||
fast: proxys[0],
|
||||
delay: delay,
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
go urlTest.loop()
|
||||
return urlTest, nil
|
||||
|
|
|
@ -48,7 +48,7 @@ func (t *Tunnel) UpdateConfig() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// clear proxys and rules
|
||||
// empty proxys and rules
|
||||
proxys := make(map[string]C.Proxy)
|
||||
rules := []C.Rule{}
|
||||
|
||||
|
@ -78,10 +78,6 @@ func (t *Tunnel) UpdateConfig() (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// init proxy
|
||||
proxys["DIRECT"] = adapters.NewDirect(t.traffic)
|
||||
proxys["REJECT"] = adapters.NewReject()
|
||||
|
||||
// parse rules
|
||||
for _, key := range rulesConfig.Keys() {
|
||||
rule := strings.Split(key.Name(), ",")
|
||||
|
@ -130,9 +126,21 @@ func (t *Tunnel) UpdateConfig() (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// init proxy
|
||||
proxys["DIRECT"] = adapters.NewDirect(t.traffic)
|
||||
proxys["REJECT"] = adapters.NewReject()
|
||||
|
||||
t.configLock.Lock()
|
||||
defer t.configLock.Unlock()
|
||||
|
||||
// stop url-test
|
||||
for _, elm := range t.proxys {
|
||||
urlTest, ok := elm.(*adapters.URLTest)
|
||||
if ok {
|
||||
urlTest.Close()
|
||||
}
|
||||
}
|
||||
|
||||
t.proxys = proxys
|
||||
t.rules = rules
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user