diff --git a/conf/gsnova.conf b/conf/gsnova.conf index b182eede..76bfe23c 100755 --- a/conf/gsnova.conf +++ b/conf/gsnova.conf @@ -19,7 +19,16 @@ Proxy=https://GoogleHttps [C4] Enable=0 Listen=localhost:48102 -WorkerNode[0]= + +#--- new style configuration syntax +WorkerNode=xxx.herokuapp.com +WorkerNode=xxx.cloudno.de +WorkerNode=xxx.rhcloud.com + +#--- old style configuration syntax +#--- any index from 0 to 9 will be readed, not necessary be successive starting from 0 +WorkerNode[8]= + ReadTimeout = 25 MaxConn = 3 WSConnKeepAlive = 1800 diff --git a/src/common/config.go b/src/common/config.go index c58c1fcc..7f80e9a6 100755 --- a/src/common/config.go +++ b/src/common/config.go @@ -27,9 +27,9 @@ func InitConfig() error { // if timeout, exist := Cfg.GetIntProperty("LocalServer", "KeepAliveTimeout"); exist { // KeepAliveTimeout = time.Duration(timeout) // } -// if addr, exist := Cfg.GetProperty("LocalProxy", "Proxy"); exist { -// LocalProxy, _ = url.Parse(addr) -// } + // if addr, exist := Cfg.GetProperty("LocalProxy", "Proxy"); exist { + // LocalProxy, _ = url.Parse(addr) + // } if enable, exist := Cfg.GetIntProperty("Misc", "DebugEnable"); exist { DebugEnable = (enable != 0) } diff --git a/src/main/launch.go b/src/main/launch.go index 0073ae48..a1c6b548 100644 --- a/src/main/launch.go +++ b/src/main/launch.go @@ -13,8 +13,6 @@ import ( "remote" "runtime" "sync/atomic" - "time" - "util" ) const ( @@ -120,12 +118,6 @@ func main() { if !exist { log.Fatalln("No config [LocalServer]->Listen found") } - if v, exist := common.Cfg.GetBoolProperty("Misc", "AutoOpenWebUI"); !exist || v { - go func() { - time.Sleep(1 * time.Second) - util.OpenBrowser("http://localhost:" + common.ProxyPort + "/") - }() - } testEntry() startLocalProxyServer(addr, proxy.GLOBAL_PROXY_SERVER) //launchSystemTray() diff --git a/src/proxy/c4.go b/src/proxy/c4.go index 1c9a2865..c82a0342 100755 --- a/src/proxy/c4.go +++ b/src/proxy/c4.go @@ -7,12 +7,13 @@ import ( "encoding/binary" "errors" "event" - //"fmt" + _ "fmt" "io" "log" "net" "net/http" "net/url" + _ "os" "regexp" "strconv" "strings" @@ -505,7 +506,7 @@ func (manager *C4) Init() error { } return url.Parse(c4_cfg.Proxy) }, - ResponseHeaderTimeout: time.Duration(c4_cfg.ReadTimeout + 1) * time.Second, + ResponseHeaderTimeout: time.Duration(c4_cfg.ReadTimeout+1) * time.Second, } c4HttpClient.Transport = tr @@ -514,11 +515,30 @@ func (manager *C4) Init() error { go writeCBLoop(i) } + workers := make([]string, 0) + // new style config syntax + wl, _ := common.Cfg.GetPropertyList("C4", "WorkerNode") + for _, worker := range wl { + workers = append(workers, worker) + } + + // old style config syntax index := 0 for { v, exist := common.Cfg.GetProperty("C4", "WorkerNode["+strconv.Itoa(index)+"]") if !exist || len(v) == 0 { - break + // don't exit if there's less than 10 index ... + if index > 9 { + break + } + } else { + workers = append(workers, v) + } + index = index + 1 + } + for _, v := range workers { + if len(v) == 0 { + continue } if !strings.Contains(v, "://") { v = "http://" + v @@ -527,13 +547,12 @@ func (manager *C4) Init() error { v = v + "/" } manager.servers.Add(v) - index = index + 1 if strings.HasPrefix(v, "ws://") { initC4WebsocketChannel(v) } manager.loginC4(v) } - if index == 0 { + if len(workers) == 0 { C4Enable = false return errors.New("No configed C4 server.") } diff --git a/src/proxy/local_hosts.go b/src/proxy/local_hosts.go index fc009f36..5bd1d27c 100644 --- a/src/proxy/local_hosts.go +++ b/src/proxy/local_hosts.go @@ -28,9 +28,10 @@ func loadLocalHostMapping(file string) error { } props, exist := ini.GetTagProperties("") if exist { - for k, v := range props { + for k, _ := range props { selector := &util.ListSelector{} - hs := strings.Split(v, "|") + vs, _ := ini.GetProperty("", k) + hs := strings.Split(vs, "|") for _, h := range hs { selector.Add(h) } diff --git a/src/util/ini.go b/src/util/ini.go index 9df4812c..ffa50080 100755 --- a/src/util/ini.go +++ b/src/util/ini.go @@ -3,19 +3,21 @@ package util import ( "bufio" "bytes" + _ "fmt" "io" "os" "strconv" "strings" ) +type Stringlist []string type Ini struct { - props map[string]map[string]string + props map[string]map[string]Stringlist } func NewIni() *Ini { ini := new(Ini) - ini.props = make(map[string]map[string]string) + ini.props = make(map[string]map[string]Stringlist) return ini } @@ -51,12 +53,12 @@ func (ini *Ini) Load(is io.Reader) (err error) { value := strings.TrimSpace(line[idx+1:]) ini.SetProperty(currenttag, key, value) } -// splits := strings.Split(line, "=") -// if len(splits) >= 2 { -// key := strings.TrimSpace(splits[0]) -// value := strings.TrimSpace(splits[1]) -// ini.SetProperty(currenttag, key, value) -// } + // splits := strings.Split(line, "=") + // if len(splits) >= 2 { + // key := strings.TrimSpace(splits[0]) + // value := strings.TrimSpace(splits[1]) + // ini.SetProperty(currenttag, key, value) + // } } } } @@ -66,8 +68,10 @@ func (ini *Ini) Load(is io.Reader) (err error) { func (ini *Ini) Save(os io.Writer) { if _, ok := ini.props[""]; ok { for k1, v1 := range ini.props[""] { - line := k1 + " = " + v1 + "\r\n" - os.Write([]byte(line)) + for _, v := range v1 { + line := k1 + " = " + v + "\r\n" + os.Write([]byte(line)) + } } os.Write([]byte("\r\n")) } @@ -76,8 +80,10 @@ func (ini *Ini) Save(os io.Writer) { k = "[" + k + "]\r\n" os.Write([]byte(k)) for k1, v1 := range xm { - line := k1 + " = " + v1 + "\r\n" - os.Write([]byte(line)) + for _, v := range v1 { + line := k1 + " = " + v + "\r\n" + os.Write([]byte(line)) + } } os.Write([]byte("\r\n")) } @@ -86,12 +92,12 @@ func (ini *Ini) Save(os io.Writer) { func (ini *Ini) SetProperty(tag, key, value string) { if nil == ini.props[tag] { - ini.props[tag] = make(map[string]string) + ini.props[tag] = make(map[string]Stringlist) } - ini.props[tag][key] = value + ini.props[tag][key] = append(ini.props[tag][key], value) } -func (ini *Ini) GetProperty(tag, key string) (value string, exist bool) { +func (ini *Ini) GetPropertyList(tag, key string) (value Stringlist, exist bool) { if m, ok := ini.props[tag]; !ok { exist = false return @@ -101,6 +107,17 @@ func (ini *Ini) GetProperty(tag, key string) (value string, exist bool) { return } +func (ini *Ini) GetProperty(tag, key string) (value string, exist bool) { + var vl Stringlist + vl, exist = ini.GetPropertyList(tag, key) + if len(vl) > 0 { + value = vl[0] + } else { + return "", false + } + return +} + func (ini *Ini) GetIntProperty(tag, key string) (value int64, exist bool) { var str string if str, exist = ini.GetProperty(tag, key); exist { @@ -125,7 +142,7 @@ func (ini *Ini) GetBoolProperty(tag, key string) (value bool, exist bool) { return } -func (ini *Ini) GetTagProperties(tag string) (map[string]string, bool) { +func (ini *Ini) GetTagProperties(tag string) (map[string]Stringlist, bool) { v, exist := ini.props[tag] return v, exist }