From ca50c622c99e43052d0c1f3360024b7e17cb427e Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 14 Dec 2019 12:09:42 -0800 Subject: [PATCH] Simplify -libp2pctl_port by removing offset logic Suggested-by: Edgar Aroutiounian --- cmd/harmony/main.go | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 73aa67eb0..08c06e136 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -567,7 +567,7 @@ func main() { } if *libp2pctlFlag { - port, err := getPort(*libp2pctlPortFlag) + port, err := net.LookupPort("tcp", *libp2pctlPortFlag) if err != nil { utils.FatalErrMsg(err, "cannot parse -libp2pctl_port %#v", *libp2pctlPortFlag) @@ -611,29 +611,3 @@ func main() { currentNode.StartServer() } - -func getPort(s string) (int, error) { - if s == "" { - return 0, errors.New("empty port") - } - if s[0] != '+' && s[0] != '-' { - return net.LookupPort("tcp", s) - } - n, err := strconv.ParseUint(s[1:], 0, 16) - if err != nil { - return 0, err - } - num, err := net.LookupPort("tcp", *port) - if err != nil { - return 0, errors.Wrapf(err, "cannot parse -port value %#v", *port) - } - if s[0] == '+' { - num += int(n) - } else { - num -= int(n) - } - if num < 1 || num > 65535 { - return 0, errors.Wrapf(err, "offset result %v out of range", num) - } - return num, nil -}