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) checkFatal(err)
} }
if password == "" { config.Password = determinePassword(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.")
}
if prof != "" { if prof != "" {
p := *profile.CPUProfile p := *profile.CPUProfile
@@ -371,6 +363,18 @@ func determineQuorum(initPeerCountFlag int, peers []string) uint {
return quorum 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 { func peerName(routerName string, iface *net.Interface) mesh.PeerName {
if routerName == "" { if routerName == "" {
if iface == nil { if iface == nil {