From 1b3122b37b9171504d8495a0a6b2150850f6ce6f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 10 Sep 2014 17:02:16 +0100 Subject: [PATCH] refactor: eliminate some helper functions --- connection_maker.go | 5 +++-- utils.go | 23 ----------------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/connection_maker.go b/connection_maker.go index 0776e4f3..89522357 100644 --- a/connection_maker.go +++ b/connection_maker.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "math/rand" + "net" "time" ) @@ -115,9 +116,9 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) { return } address := conn.RemoteTCPAddr() - // try both portnumber of connection and standart port + // try both portnumber of connection and standard port validTarget[address] = true - if host, _, err := ExtractHostPort(address); err == nil { + if host, _, err := net.SplitHostPort(address); err == nil { validTarget[NormalisePeerAddr(host)] = true } }) diff --git a/utils.go b/utils.go index 74dce894..da57cf2a 100644 --- a/utils.go +++ b/utils.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "net" - "strconv" ) func checkFatal(e error) { @@ -99,28 +98,6 @@ func (lop ListOfPeers) Less(i, j int) bool { return lop[i].Name < lop[i].Name } -func StripPortFromAddr(address string) string { - // If we've been given a port number, take it off - if addrHost, _, err := net.SplitHostPort(address); err == nil { - return addrHost - } - return address -} - -// given an address like '1.2.3.4:567', return the host and port number, -// given an address like '1.2.3.4', return the host and weave's standard port number -func ExtractHostPort(address string) (host string, port int, err error) { - if host, port, err := net.SplitHostPort(address); err == nil { - if portnum, err := strconv.Atoi(port); err == nil { - return host, portnum, nil - } else { - return host, 0, err - } - } else { - return host, Port, nil - } -} - // given an address like '1.2.3.4:567', return the address if it has a port, // otherwise return the address with weave's standard port number func NormalisePeerAddr(peerAddr string) string {