refactor: eliminate some helper functions

This commit is contained in:
Matthias Radestock committed 2014-09-10 17:02:16 +01:00
1 parent 20bfdc2e73
commit 1b3122b37b
2 files changed
+3 -25

No files matched your search

+3 -2
View File
@@ -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
}
})
-23
View File
@@ -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 {