make Peer.String() return the common case

When we want a string representation of a Peer, we nearly always just
want the full name. So make String() return that and introduce Info()
to return expanded info.
This commit is contained in:
Matthias Radestock committed 2015-05-10 23:58:23 +01:00
1 parent db198652a5
commit 0cbbe9bac3
8 files changed
+20 -20

No files matched your search

+4 -4
View File
@@ -82,17 +82,17 @@ func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak { return T
func (conn *RemoteConnection) Shutdown(error) {}
func (conn *RemoteConnection) Log(args ...interface{}) {
log.Println(append(append([]interface{}{}, fmt.Sprintf("->[%s|%s]:", conn.remoteTCPAddr, conn.remote.FullName())), args...)...)
log.Println(append(append([]interface{}{}, fmt.Sprintf("->[%s|%s]:", conn.remoteTCPAddr, conn.remote)), args...)...)
}
func (conn *RemoteConnection) String() string {
from := "<nil>"
if conn.local != nil {
from = conn.local.FullName()
from = conn.local.String()
}
to := "<nil>"
if conn.remote != nil {
to = conn.remote.FullName()
to = conn.remote.String()
}
return fmt.Sprint("Connection ", from, "->", to)
}
@@ -231,7 +231,7 @@ func (conn *LocalConnection) ReceivedHeartbeat(remoteUDPAddr *net.UDPAddr, connU
if oldRemoteUDPAddr == nil {
return conn.sendFastHeartbeats()
} else if oldRemoteUDPAddr.String() != remoteUDPAddr.String() {
log.Println("Peer", conn.remote.FullName(), "moved from", old, "to", remoteUDPAddr)
log.Println("Peer", conn.remote, "moved from", old, "to", remoteUDPAddr)
}
return nil
})