mirror of
				https://github.com/v2fly/v2ray-core.git
				synced 2025-10-31 01:39:16 +00:00 
			
		
		
		
	allow the loading of router strategy
This commit is contained in:
		
							parent
							
								
									459a914ab7
								
							
						
					
					
						commit
						017a11cfd5
					
				| @ -17,9 +17,16 @@ type RouterRulesConfig struct { | |||||||
| 	DomainStrategy string            `json:"domainStrategy"` | 	DomainStrategy string            `json:"domainStrategy"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // StrategyConfig represents a strategy config | ||||||
|  | type StrategyConfig struct { | ||||||
|  | 	Type     string           `json:"type"` | ||||||
|  | 	Settings *json.RawMessage `json:"settings"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
| type BalancingRule struct { | type BalancingRule struct { | ||||||
| 	Tag       string         `json:"tag"` | 	Tag       string         `json:"tag"` | ||||||
| 	Selectors StringList     `json:"selector"` | 	Selectors StringList     `json:"selector"` | ||||||
|  | 	Strategy  StrategyConfig `json:"strategy"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (r *BalancingRule) Build() (*router.BalancingRule, error) { | func (r *BalancingRule) Build() (*router.BalancingRule, error) { | ||||||
| @ -30,9 +37,20 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) { | |||||||
| 		return nil, newError("empty selector list") | 		return nil, newError("empty selector list") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	var strategy string | ||||||
|  | 	switch strings.ToLower(r.Strategy.Type) { | ||||||
|  | 	case strategyRandom, "": | ||||||
|  | 		strategy = strategyRandom | ||||||
|  | 	case strategyLeastPing: | ||||||
|  | 		strategy = "leastPing" | ||||||
|  | 	default: | ||||||
|  | 		return nil, newError("unknown balancing strategy: " + r.Strategy.Type) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return &router.BalancingRule{ | 	return &router.BalancingRule{ | ||||||
| 		Tag:              r.Tag, | 		Tag:              r.Tag, | ||||||
| 		OutboundSelector: []string(r.Selectors), | 		OutboundSelector: []string(r.Selectors), | ||||||
|  | 		Strategy:         strategy, | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								infra/conf/router_strategy.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								infra/conf/router_strategy.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | package conf | ||||||
|  | 
 | ||||||
|  | const ( | ||||||
|  | 	strategyRandom    string = "random" | ||||||
|  | 	strategyLeastPing string = "leastping" | ||||||
|  | ) | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Shelikhoo
						Shelikhoo