diff --git a/README.md b/README.md index 8431595b..d4be64ab 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Proxy2 = ss, server2, port, AEAD_CHACHA20_POLY1305, password [Proxy Group] # url-test select which proxy will be used by benchmarking speed to a URL. -# name = url-test, [proxys], url, interval(second) +# name = url-test, [proxies], url, interval(second) Proxy = url-test, Proxy1, Proxy2, http://www.google.com/generate_204, 300 [Rule] diff --git a/adapters/selector.go b/adapters/selector.go index 7305665a..42214e0e 100644 --- a/adapters/selector.go +++ b/adapters/selector.go @@ -9,7 +9,7 @@ import ( type Selector struct { name string selected C.Proxy - proxys map[string]C.Proxy + proxies map[string]C.Proxy } func (s *Selector) Name() string { @@ -30,14 +30,14 @@ func (s *Selector) Now() string { func (s *Selector) All() []string { var all []string - for k := range s.proxys { + for k := range s.proxies { all = append(all, k) } return all } func (s *Selector) Set(name string) error { - proxy, exist := s.proxys[name] + proxy, exist := s.proxies[name] if !exist { return errors.New("Proxy does not exist") } @@ -45,21 +45,21 @@ func (s *Selector) Set(name string) error { return nil } -func NewSelector(name string, proxys map[string]C.Proxy) (*Selector, error) { - if len(proxys) == 0 { +func NewSelector(name string, proxies map[string]C.Proxy) (*Selector, error) { + if len(proxies) == 0 { return nil, errors.New("Provide at least one proxy") } mapping := make(map[string]C.Proxy) var init string - for k, v := range proxys { + for k, v := range proxies { mapping[k] = v init = k } s := &Selector{ name: name, - proxys: mapping, - selected: proxys[init], + proxies: mapping, + selected: proxies[init], } return s, nil } diff --git a/adapters/urltest.go b/adapters/urltest.go index a68b2b90..00e87787 100644 --- a/adapters/urltest.go +++ b/adapters/urltest.go @@ -12,14 +12,14 @@ import ( ) type URLTest struct { - name string - proxys []C.Proxy - url *url.URL - rawURL string - addr *C.Addr - fast C.Proxy - delay time.Duration - done chan struct{} + name string + proxies []C.Proxy + url *url.URL + rawURL string + addr *C.Addr + fast C.Proxy + delay time.Duration + done chan struct{} } func (u *URLTest) Name() string { @@ -58,12 +58,12 @@ Loop: func (u *URLTest) speedTest() { wg := sync.WaitGroup{} - wg.Add(len(u.proxys)) + wg.Add(len(u.proxies)) c := make(chan interface{}) fast := selectFast(c) timer := time.NewTimer(u.delay) - for _, p := range u.proxys { + for _, p := range u.proxies { go func(p C.Proxy) { err := getUrl(p, u.addr, u.rawURL) if err == nil { @@ -129,7 +129,7 @@ func selectFast(in chan interface{}) chan interface{} { return out } -func NewURLTest(name string, proxys []C.Proxy, rawURL string, delay time.Duration) (*URLTest, error) { +func NewURLTest(name string, proxies []C.Proxy, rawURL string, delay time.Duration) (*URLTest, error) { u, err := url.Parse(rawURL) if err != nil { return nil, err @@ -154,14 +154,14 @@ func NewURLTest(name string, proxys []C.Proxy, rawURL string, delay time.Duratio } urlTest := &URLTest{ - name: name, - proxys: proxys[:], - rawURL: rawURL, - url: u, - addr: addr, - fast: proxys[0], - delay: delay, - done: make(chan struct{}), + name: name, + proxies: proxies[:], + rawURL: rawURL, + url: u, + addr: addr, + fast: proxies[0], + delay: delay, + done: make(chan struct{}), } go urlTest.loop() return urlTest, nil diff --git a/hub/proxys.go b/hub/proxies.go similarity index 80% rename from hub/proxys.go rename to hub/proxies.go index 52d62978..b8d90e2f 100644 --- a/hub/proxys.go +++ b/hub/proxies.go @@ -13,7 +13,7 @@ import ( func proxyRouter() http.Handler { r := chi.NewRouter() - r.Get("/", getProxys) + r.Get("/", getProxies) r.Get("/{name}", getProxy) r.Put("/{name}", updateProxy) return r @@ -56,23 +56,23 @@ func transformProxy(proxy C.Proxy) interface{} { } } -type GetProxysResponse struct { - Proxys map[string]interface{} `json:"proxys"` +type GetProxiesResponse struct { + Proxies map[string]interface{} `json:"proxies"` } -func getProxys(w http.ResponseWriter, r *http.Request) { - _, rawProxys := tunnel.Config() - proxys := make(map[string]interface{}) - for name, proxy := range rawProxys { - proxys[name] = transformProxy(proxy) +func getProxies(w http.ResponseWriter, r *http.Request) { + _, rawProxies := tunnel.Config() + proxies := make(map[string]interface{}) + for name, proxy := range rawProxies { + proxies[name] = transformProxy(proxy) } - render.JSON(w, r, GetProxysResponse{Proxys: proxys}) + render.JSON(w, r, GetProxiesResponse{Proxies: proxies}) } func getProxy(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") - _, proxys := tunnel.Config() - proxy, exist := proxys[name] + _, proxies := tunnel.Config() + proxy, exist := proxies[name] if !exist { w.WriteHeader(http.StatusNotFound) render.JSON(w, r, Error{ @@ -98,8 +98,8 @@ func updateProxy(w http.ResponseWriter, r *http.Request) { } name := chi.URLParam(r, "name") - _, proxys := tunnel.Config() - proxy, exist := proxys[name] + _, proxies := tunnel.Config() + proxy, exist := proxies[name] if !exist { w.WriteHeader(http.StatusNotFound) render.JSON(w, r, Error{ diff --git a/hub/server.go b/hub/server.go index 5efec54c..328e5108 100644 --- a/hub/server.go +++ b/hub/server.go @@ -23,7 +23,7 @@ func NewHub(addr string) { r.Get("/traffic", traffic) r.Get("/logs", getLogs) r.Mount("/configs", configRouter()) - r.Mount("/proxys", proxyRouter()) + r.Mount("/proxies", proxyRouter()) r.Mount("/rules", ruleRouter()) err := http.ListenAndServe(addr, r) diff --git a/proxy/listener.go b/proxy/listener.go index 3e03e36b..853508cf 100644 --- a/proxy/listener.go +++ b/proxy/listener.go @@ -26,7 +26,7 @@ type Listener struct { socksSignal *C.ProxySignal } -// Info returns the proxys's current configuration +// Info returns the proxies's current configuration func (l *Listener) Info() (info C.General) { return C.General{ Port: &l.httpPort, diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 805a7d67..16e43645 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -23,7 +23,7 @@ var ( type Tunnel struct { queue *channels.InfiniteChannel rules []C.Rule - proxys map[string]C.Proxy + proxies map[string]C.Proxy observable *observable.Observable logCh chan interface{} configLock *sync.RWMutex @@ -41,7 +41,7 @@ func (t *Tunnel) Traffic() *C.Traffic { } func (t *Tunnel) Config() ([]C.Rule, map[string]C.Proxy) { - return t.rules, t.proxys + return t.rules, t.proxies } func (t *Tunnel) Log() *observable.Observable { @@ -62,16 +62,16 @@ func (t *Tunnel) UpdateConfig() (err error) { return } - // empty proxys and rules - proxys := make(map[string]C.Proxy) + // empty proxies and rules + proxies := make(map[string]C.Proxy) rules := []C.Rule{} - proxysConfig := cfg.Section("Proxy") + proxiesConfig := cfg.Section("Proxy") rulesConfig := cfg.Section("Rule") groupsConfig := cfg.Section("Proxy Group") // parse proxy - for _, key := range proxysConfig.Keys() { + for _, key := range proxiesConfig.Keys() { proxy := key.Strings(",") if len(proxy) == 0 { continue @@ -87,7 +87,7 @@ func (t *Tunnel) UpdateConfig() (err error) { if err != nil { return err } - proxys[key.Name()] = ss + proxies[key.Name()] = ss } } @@ -126,7 +126,7 @@ func (t *Tunnel) UpdateConfig() (err error) { url := rule[len(rule)-2] var ps []C.Proxy for _, name := range proxyNames { - if p, ok := proxys[name]; ok { + if p, ok := proxies[name]; ok { ps = append(ps, p) } } @@ -135,7 +135,7 @@ func (t *Tunnel) UpdateConfig() (err error) { if err != nil { return fmt.Errorf("Config error: %s", err.Error()) } - proxys[key.Name()] = adapter + proxies[key.Name()] = adapter case "select": if len(rule) < 3 { return fmt.Errorf("Selector need more than 3 param") @@ -143,7 +143,7 @@ func (t *Tunnel) UpdateConfig() (err error) { proxyNames := rule[1:] selectProxy := make(map[string]C.Proxy) for _, name := range proxyNames { - proxy, exist := proxys[name] + proxy, exist := proxies[name] if !exist { return fmt.Errorf("Proxy %s not exist", name) } @@ -153,31 +153,31 @@ func (t *Tunnel) UpdateConfig() (err error) { if err != nil { return fmt.Errorf("Selector create error: %s", err.Error()) } - proxys[key.Name()] = selector + proxies[key.Name()] = selector } } // init proxy - proxys["DIRECT"] = adapters.NewDirect(t.traffic) - proxys["REJECT"] = adapters.NewReject() + proxies["DIRECT"] = adapters.NewDirect(t.traffic) + proxies["REJECT"] = adapters.NewReject() t.configLock.Lock() defer t.configLock.Unlock() // stop url-test - for _, elm := range t.proxys { + for _, elm := range t.proxies { urlTest, ok := elm.(*adapters.URLTest) if ok { urlTest.Close() } } - s, err := adapters.NewSelector("Proxy", proxys) + s, err := adapters.NewSelector("Proxy", proxies) if err != nil { return err } - t.proxys = proxys + t.proxies = proxies t.rules = rules t.selector = s @@ -200,7 +200,7 @@ func (t *Tunnel) handleConn(localConn C.ServerAdapter) { var proxy C.Proxy switch t.mode { case Direct: - proxy = t.proxys["DIRECT"] + proxy = t.proxies["DIRECT"] case Global: proxy = t.selector // Rule @@ -223,7 +223,7 @@ func (t *Tunnel) match(addr *C.Addr) C.Proxy { for _, rule := range t.rules { if rule.IsMatch(addr) { - a, ok := t.proxys[rule.Adapter()] + a, ok := t.proxies[rule.Adapter()] if !ok { continue } @@ -232,14 +232,14 @@ func (t *Tunnel) match(addr *C.Addr) C.Proxy { } } t.logCh <- newLog(INFO, "%v doesn't match any rule using DIRECT", addr.String()) - return t.proxys["DIRECT"] + return t.proxies["DIRECT"] } func newTunnel() *Tunnel { logCh := make(chan interface{}) tunnel := &Tunnel{ queue: channels.NewInfiniteChannel(), - proxys: make(map[string]C.Proxy), + proxies: make(map[string]C.Proxy), observable: observable.NewObservable(logCh), logCh: logCh, configLock: &sync.RWMutex{},