Skip to content

Commit

Permalink
fix example config file bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bigeagle committed Dec 16, 2013
1 parent 12610e9 commit 082179d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 201 deletions.
1 change: 1 addition & 0 deletions client.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
196 changes: 0 additions & 196 deletions hop/config.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 6 additions & 4 deletions server.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 082179d

Please sign in to comment.