| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | // +build json | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package freedom | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2016-05-24 22:41:51 +02:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	"github.com/v2ray/v2ray-core/proxy/internal" | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | func (this *Config) UnmarshalJSON(data []byte) error { | 
					
						
							|  |  |  | 	type JsonConfig struct { | 
					
						
							|  |  |  | 		DomainStrategy string `json:"domainStrategy"` | 
					
						
							| 
									
										
										
										
											2016-06-02 23:18:44 +02:00
										 |  |  | 		Timeout        uint32 `json:"timeout"` | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	jsonConfig := new(JsonConfig) | 
					
						
							|  |  |  | 	if err := json.Unmarshal(data, jsonConfig); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this.DomainStrategy = DomainStrategyAsIs | 
					
						
							| 
									
										
										
										
											2016-05-24 22:41:51 +02:00
										 |  |  | 	domainStrategy := strings.ToLower(jsonConfig.DomainStrategy) | 
					
						
							|  |  |  | 	if domainStrategy == "useip" { | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 		this.DomainStrategy = DomainStrategyUseIP | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-02 23:18:44 +02:00
										 |  |  | 	this.Timeout = jsonConfig.Timeout | 
					
						
							| 
									
										
										
										
											2016-05-22 22:30:21 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | func init() { | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	internal.RegisterOutboundConfig("freedom", func() interface{} { return new(Config) }) | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | } |