From d50975a185a97c3e6b3736d698ed446edc4e64a0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 13 Jan 2016 15:59:21 +0000 Subject: [PATCH] refactor: extract password determination --- prog/weaver/main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index c80c6469..577ab630 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -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 {