Fix: should keep the original order of proxy groups (#284)

This commit is contained in:
gVisor bot 2019-08-28 23:44:32 +08:00
parent db11be9306
commit 7afb0cc5d9
2 changed files with 16 additions and 9 deletions

View file

@ -292,15 +292,26 @@ func parseProxies(cfg *rawConfig) (map[string]C.Proxy, error) {
proxyList = append(proxyList, proxy.Name()) proxyList = append(proxyList, proxy.Name())
} }
// parse proxy group // keep the origional order of ProxyGroups in config file
for idx, mapping := range groupsConfig {
groupName, existName := mapping["name"].(string)
if !existName {
return nil, fmt.Errorf("ProxyGroup %d: missing name", idx)
}
proxyList = append(proxyList, groupName)
}
// check if any loop exists and sort the ProxyGroups
if err := proxyGroupsDagSort(groupsConfig); err != nil { if err := proxyGroupsDagSort(groupsConfig); err != nil {
return nil, err return nil, err
} }
for idx, mapping := range groupsConfig {
// parse proxy group
for _, mapping := range groupsConfig {
groupType, existType := mapping["type"].(string) groupType, existType := mapping["type"].(string)
groupName, existName := mapping["name"].(string) groupName, _ := mapping["name"].(string)
if !(existType && existName) { if !existType {
return nil, fmt.Errorf("ProxyGroup %d: missing type or name", idx) return nil, fmt.Errorf("ProxyGroup %s: missing type", groupName)
} }
if _, exist := proxies[groupName]; exist { if _, exist := proxies[groupName]; exist {
@ -364,7 +375,6 @@ func parseProxies(cfg *rawConfig) (map[string]C.Proxy, error) {
return nil, fmt.Errorf("Proxy %s: %s", groupName, err.Error()) return nil, fmt.Errorf("Proxy %s: %s", groupName, err.Error())
} }
proxies[groupName] = adapters.NewProxy(group) proxies[groupName] = adapters.NewProxy(group)
proxyList = append(proxyList, groupName)
} }
ps := []C.Proxy{} ps := []C.Proxy{}

View file

@ -55,9 +55,6 @@ func proxyGroupsDagSort(groupsConfig []map[string]interface{}) error {
// Step 1.1 build dependency graph // Step 1.1 build dependency graph
for idx, mapping := range groupsConfig { for idx, mapping := range groupsConfig {
// record original order in config file.
// this field can be used determinate the display order in FrontEnd.
mapping["configIdx"] = idx
groupName, existName := mapping["name"].(string) groupName, existName := mapping["name"].(string)
if !existName { if !existName {
return fmt.Errorf("ProxyGroup %d: missing name", idx) return fmt.Errorf("ProxyGroup %d: missing name", idx)