Skip to content

Commit

Permalink
Merge ae00582 into c2972b7
Browse files Browse the repository at this point in the history
  • Loading branch information
dpw committed Apr 13, 2015
2 parents c2972b7 + ae00582 commit 1860845
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,30 @@ func main() {
runtime.GOMAXPROCS(procs)

var (
config weave.RouterConfig
justVersion bool
port int
ifaceName string
routerName string
nickName string
password string
wait int
debug bool
prof string
peers []string
connLimit int
bufSz int
bufSzMB int
httpAddr string
)

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(&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.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.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path")
flag.IntVar(&connLimit, "connlimit", 30, "connection limit (0 for unlimited)")
flag.IntVar(&bufSz, "bufsz", 8, "capture buffer size in MB")
flag.IntVar(&config.ConnLimit, "connlimit", 30, "connection limit (0 for unlimited)")
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.Parse()
peers = flag.Args()
Expand All @@ -75,29 +73,28 @@ func main() {

var err error

var iface *net.Interface
if ifaceName != "" {
iface, err = weavenet.EnsureInterface(ifaceName, wait)
config.Iface, err = weavenet.EnsureInterface(ifaceName, wait)
if err != nil {
log.Fatal(err)
}
}

if routerName == "" {
if iface == nil {
if config.Iface == nil {
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 == "" {
nickName, err = os.Hostname()
if config.NickName == "" {
config.NickName, err = os.Hostname()
if err != nil {
log.Fatal(err)
}
}

ourName, err := weave.PeerNameFromUserInput(routerName)
config.Name, err = weave.PeerNameFromUserInput(routerName)
if err != nil {
log.Fatal(err)
}
Expand All @@ -106,11 +103,10 @@ func main() {
password = os.Getenv("WEAVE_PASSWORD")
}

var pwSlice []byte
if password == "" {
log.Println("Communication between peers is unencrypted.")
} else {
pwSlice = []byte(password)
config.Password = []byte(password)
log.Println("Communication between peers is encrypted.")
}

Expand All @@ -120,17 +116,10 @@ func main() {
defer profile.Start(&p).Stop()
}

router := weave.NewRouter(
weave.RouterConfig{
Port: port,
Iface: iface,
Name: ourName,
NickName: nickName,
Password: pwSlice,
ConnLimit: connLimit,
BufSz: bufSz * 1024 * 1024,
LogFrame: logFrameFunc(debug)})
config.BufSz = bufSzMB * 1024 * 1024
config.LogFrame = logFrameFunc(debug)

router := weave.NewRouter(config)
log.Println("Our name is", router.Ourself.FullName())
router.Start()
initiateConnections(router, peers)
Expand Down

0 comments on commit 1860845

Please sign in to comment.