Merge pull request #554 from dpw/main-routerconfig

Pull forward the declaration of the RouterConfig in main()
This commit is contained in:
rade committed 2015-04-14 10:57:43 +01:00
commit 9b29d2ecc5
1 file changed
+16 -27
+16 -27
View File
@@ -35,32 +35,30 @@ func main() {
runtime.GOMAXPROCS(procs) runtime.GOMAXPROCS(procs)
var ( var (
config weave.RouterConfig
justVersion bool justVersion bool
port int
ifaceName string ifaceName string
routerName string routerName string
nickName string
password string password string
wait int wait int
debug bool debug bool
prof string prof string
peers []string peers []string
connLimit int bufSzMB int
bufSz int
httpAddr string httpAddr string
) )
flag.BoolVar(&justVersion, "version", false, "print version and exit") flag.BoolVar(&justVersion, "version", false, "print version and exit")
flag.IntVar(&port, "port", weave.Port, "router port") flag.IntVar(&config.Port, "port", weave.Port, "router port")
flag.StringVar(&ifaceName, "iface", "", "name of interface to capture/inject from (disabled if blank)") flag.StringVar(&ifaceName, "iface", "", "name of interface to capture/inject from (disabled if blank)")
flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC of interface)") flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC of interface)")
flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)") flag.StringVar(&config.NickName, "nickname", "", "nickname of peer (defaults to hostname)")
flag.StringVar(&password, "password", "", "network password") flag.StringVar(&password, "password", "", "network password")
flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up (0 = don't wait)") flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up (0 = don't wait)")
flag.BoolVar(&debug, "debug", false, "enable debug logging") flag.BoolVar(&debug, "debug", false, "enable debug logging")
flag.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path") flag.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path")
flag.IntVar(&connLimit, "connlimit", 30, "connection limit (0 for unlimited)") flag.IntVar(&config.ConnLimit, "connlimit", 30, "connection limit (0 for unlimited)")
flag.IntVar(&bufSz, "bufsz", 8, "capture buffer size in MB") flag.IntVar(&bufSzMB, "bufsz", 8, "capture buffer size in MB")
flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank, absolute path indicates unix domain socket)") flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank, absolute path indicates unix domain socket)")
flag.Parse() flag.Parse()
peers = flag.Args() peers = flag.Args()
@@ -75,29 +73,28 @@ func main() {
var err error var err error
var iface *net.Interface
if ifaceName != "" { if ifaceName != "" {
iface, err = weavenet.EnsureInterface(ifaceName, wait) config.Iface, err = weavenet.EnsureInterface(ifaceName, wait)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
if routerName == "" { if routerName == "" {
if iface == nil { if config.Iface == nil {
log.Fatal("Either an interface must be specified with -iface or a name with -name") log.Fatal("Either an interface must be specified with -iface or a name with -name")
} }
routerName = iface.HardwareAddr.String() routerName = config.Iface.HardwareAddr.String()
} }
if nickName == "" { if config.NickName == "" {
nickName, err = os.Hostname() config.NickName, err = os.Hostname()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
ourName, err := weave.PeerNameFromUserInput(routerName) config.Name, err = weave.PeerNameFromUserInput(routerName)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -106,11 +103,10 @@ func main() {
password = os.Getenv("WEAVE_PASSWORD") password = os.Getenv("WEAVE_PASSWORD")
} }
var pwSlice []byte
if password == "" { if password == "" {
log.Println("Communication between peers is unencrypted.") log.Println("Communication between peers is unencrypted.")
} else { } else {
pwSlice = []byte(password) config.Password = []byte(password)
log.Println("Communication between peers is encrypted.") log.Println("Communication between peers is encrypted.")
} }
@@ -120,17 +116,10 @@ func main() {
defer profile.Start(&p).Stop() defer profile.Start(&p).Stop()
} }
router := weave.NewRouter( config.BufSz = bufSzMB * 1024 * 1024
weave.RouterConfig{ config.LogFrame = logFrameFunc(debug)
Port: port,
Iface: iface,
Name: ourName,
NickName: nickName,
Password: pwSlice,
ConnLimit: connLimit,
BufSz: bufSz * 1024 * 1024,
LogFrame: logFrameFunc(debug)})
router := weave.NewRouter(config)
log.Println("Our name is", router.Ourself.FullName()) log.Println("Our name is", router.Ourself.FullName())
router.Start() router.Start()
initiateConnections(router, peers) initiateConnections(router, peers)