refactor: extract password determination

This commit is contained in:
Matthias Radestock committed 2016-01-13 16:23:00 +00:00
1 parent 6261ce0865
commit d50975a185
1 file changed
+13 -9
+13 -9
View File
@@ -141,15 +141,7 @@ func main() {
checkFatal(err)
}
if password == "" {
password = os.Getenv("WEAVE_PASSWORD")
}
if password == "" {
Log.Println("Communication between peers is unencrypted.")
} else {
config.Password = []byte(password)
Log.Println("Communication between peers via untrusted networks is encrypted.")
}
config.Password = determinePassword(password)
if prof != "" {
p := *profile.CPUProfile
@@ -371,6 +363,18 @@ func determineQuorum(initPeerCountFlag int, peers []string) uint {
return quorum
}
func determinePassword(password string) []byte {
if password == "" {
password = os.Getenv("WEAVE_PASSWORD")
}
if password == "" {
Log.Println("Communication between peers is unencrypted.")
return nil
}
Log.Println("Communication between peers via untrusted networks is encrypted.")
return []byte(password)
}
func peerName(routerName string, iface *net.Interface) mesh.PeerName {
if routerName == "" {
if iface == nil {