From 082179d91fdf6cd103422011c9bb448cd21af9f4 Mon Sep 17 00:00:00 2001 From: bigeagle Date: Mon, 16 Dec 2013 11:39:32 +0800 Subject: [PATCH] fix example config file bugs --- client.ini | 1 + hop/config.go | 196 -------------------------------------------------- main.go | 2 +- server.ini | 10 +-- 4 files changed, 8 insertions(+), 201 deletions(-) diff --git a/client.ini b/client.ini index f42e717..f0427be 100644 --- a/client.ini +++ b/client.ini @@ -8,6 +8,7 @@ server = example.com # port range for hopping hopstart = 4000 hopend = 5000 +mtu = 1400 key = ilovethebigbrother # method of traffic morphing: none or randsize morphmethod = none diff --git a/hop/config.go b/hop/config.go index 70248d6..fb31a05 100644 --- a/hop/config.go +++ b/hop/config.go @@ -1,205 +1,9 @@ package hop import ( - "encoding/json" - "os" "errors" - "io/ioutil" "code.google.com/p/gcfg" ) - - -type hopClientConfig struct { - servers []string - key string - addr string - // redirect gateway - regw bool - routes []*route -} - -// config for hopserver -type hopServerConfig struct { - ports []string - key string - addr string - // dev string -} - -func clientParseConfig(cfgFile string) (*hopClientConfig, error) { - file, err := os.Open(cfgFile) - if err != nil { - return nil, err - } - defer file.Close() - - jsonBuf, err := ioutil.ReadAll(file) - - // logger.Debug("%s", string(jsonBuf)) - - var icfg interface{} - err = json.Unmarshal(jsonBuf, &icfg) - - if err != nil { - return nil, err - } - - cltConfig := new(hopClientConfig) - - cfg, ok := icfg.(map[string]interface{}) - - if ok { - // logger.Debug("%v", cfg) - - if iservers, found := cfg["servers"]; found { - cltConfig.servers = make([]string, 0) - switch servers := iservers.(type) { - case string: - cltConfig.servers = append(cltConfig.servers, servers) - case []interface{}: - for _, v := range servers { - if server, ok := v.(string); ok { - cltConfig.servers = append(cltConfig.servers, server) - } else { - return nil, errors.New("Invalid server config") - } - } - default: - return nil, errors.New("Invalid server config") - } - } else { - return nil, errors.New("Servers not found") - } - - if ikey, found := cfg["key"]; found { - if key, ok := ikey.(string); ok { - cltConfig.key = key - } else { - return nil, errors.New("Invalid Key config") - } - } else { - return nil, errors.New("Key not found") - } - - if iaddr, found := cfg["addr"]; found { - if addr, ok := iaddr.(string); ok { - cltConfig.addr = addr - } else { - return nil, errors.New("Invalid Addr config") - } - } else { - return nil, errors.New("Addr config not found") - } - - if iregw, found := cfg["redirect_gateway"]; found { - if regw, ok := iregw.(bool); ok { - cltConfig.regw = regw - } else { - return nil, errors.New("Invalid Gateway Redirect Config") - } - } else { - cltConfig.regw = false - } - - net_gateway, net_nic, err = getNetGateway() - logger.Debug("Net Gateway: %s %s", net_gateway, net_nic) - if err != nil { - return nil, err - } - - if iroutes, found := cfg["net_gateway"]; found { - cltConfig.routes = make([]*route, 0) - if routes, ok := iroutes.([]interface{}); ok { - for _, v := range routes { - if destNet, ok := v.(string); ok { - r := &route{destNet, net_gateway, net_nic} - cltConfig.routes = append(cltConfig.routes, r) - } else { - return nil, errors.New("Invalid Route config") - } - } - - } - } - } - - return cltConfig, nil -} - - - -// read and parse config file -func serverParseConfig(cfgFile string) (*hopServerConfig, error) { - - file, err := os.Open(cfgFile) - if err != nil { - return nil, err - } - defer file.Close() - - jsonBuf, err := ioutil.ReadAll(file) - - // logger.Debug("%s", string(jsonBuf)) - - var icfg interface{} - err = json.Unmarshal(jsonBuf, &icfg) - - if err != nil { - return nil, err - } - - srvConfig := new(hopServerConfig) - - cfg, ok := icfg.(map[string]interface{}) - - if ok { - // logger.Debug("%v", cfg) - - if iports, found := cfg["ports"]; found { - srvConfig.ports = make([]string, 0) - switch ports := iports.(type) { - case string: - srvConfig.ports = append(srvConfig.ports, ports) - case []interface{}: - for _, v := range ports { - if port, ok := v.(string); ok { - srvConfig.ports = append(srvConfig.ports, port) - } else { - return nil, errors.New("Invalid port config") - } - } - default: - return nil, errors.New("Invalid port config") - } - } else { - return nil, errors.New("Port not found") - } - - if ikey, found := cfg["key"]; found { - if key, ok := ikey.(string); ok { - srvConfig.key = key - } else { - return nil, errors.New("Invalid Key config") - } - } else { - return nil, errors.New("Key not found") - } - - if iaddr, found := cfg["addr"]; found { - if addr, ok := iaddr.(string); ok { - srvConfig.addr = addr - } else { - return nil, errors.New("Invalid Addr config") - } - } else { - return nil, errors.New("Addr config not found") - } - - } - - return srvConfig, nil -} - // Server Config type HopServerConfig struct { HopStart int diff --git a/main.go b/main.go index 4577087..73b2137 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ import ( var srvMode, cltMode, debug, getVersion bool var cfgFile string -var VERSION = "0.3alpha2" +var VERSION = "0.3.1-dev" func main() { flag.BoolVar(&getVersion, "version", false, "Get Version info") diff --git a/server.ini b/server.ini index 6baddec..bf0cc3f 100644 --- a/server.ini +++ b/server.ini @@ -3,13 +3,15 @@ mode = server [server] -# port to listen -port = 1234 -# port range for iptables nat -hoprange = 4000:5000 +# port range to listen +hopstart = 40100 +hopend = 40200 # server addr addr = 10.1.1.1/24 # master key +mtu = 1400 key = ilovethebigbrother # method of traffic morphing: none or randsize morphmethod = none +# Fix MSS for tcp handshake +fixmss = true