include peer nickname in display output whenever possible

This commit is contained in:
Matthias Radestock committed 2015-03-27 05:25:28 +00:00
1 parent 1eca5e1097
commit 33520ea230
8 files changed
+29 -25

No files matched your search

+5 -5
View File
@@ -84,17 +84,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]:", conn.remote.Name)), args...)...)
log.Println(append(append([]interface{}{}, fmt.Sprintf("->[%s]:", conn.remote.FullName())), args...)...)
}
func (conn *RemoteConnection) String() string {
from := "<nil>"
if conn.local != nil {
from = conn.local.Name.String()
from = conn.local.FullName()
}
to := "<nil>"
if conn.remote != nil {
to = conn.remote.Name.String()
to = conn.remote.FullName()
}
return fmt.Sprint("Connection ", from, "->", to)
}
@@ -223,7 +223,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.Name, "moved from", old, "to", remoteUDPAddr)
log.Println("Peer", conn.remote.FullName(), "moved from", old, "to", remoteUDPAddr)
}
return nil
})
@@ -288,7 +288,7 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
log.Printf("->[%s] connection shutting down due to error during handshake: %v\n", conn.remoteTCPAddr, err)
return
}
log.Printf("->[%s] completed handshake with %s\n", conn.remoteTCPAddr, conn.remote.Name)
log.Printf("->[%s] completed handshake with %s\n", conn.remoteTCPAddr, conn.remote.FullName())
// We invoke AddConnection in the same goroutine that subsequently
// becomes the tcp receive loop, rather than outside, because a)
+2 -2
View File
@@ -38,7 +38,7 @@ func (peer *LocalPeer) Relay(srcPeer, dstPeer *Peer, df bool, frame []byte, dec
if !found {
// Not necessarily an error as there could be a race with the
// dst disappearing whilst the frame is in flight
log.Println("Received packet for unknown destination:", dstPeer.Name)
log.Println("Received packet for unknown destination:", dstPeer.FullName())
return nil
}
conn, found := peer.ConnectionTo(relayPeerName)
@@ -171,7 +171,7 @@ func (peer *LocalPeer) handleAddConnection(conn Connection) {
log.Fatal("Attempt made to add connection to peer with unknown remote peer")
}
toName := conn.Remote().Name
dupErr := fmt.Errorf("Multiple connections to %s added to %s", toName, peer.Name)
dupErr := fmt.Errorf("Multiple connections to %s added to %s", conn.Remote().FullName(), peer.FullName())
// deliberately non symmetrical
if dupConn, found := peer.connections[toName]; found {
if dupConn == conn {
+1 -1
View File
@@ -89,7 +89,7 @@ func (cache *MacCache) String() string {
cache.RLock()
defer cache.RUnlock()
for key, entry := range cache.table {
fmt.Fprintf(&buf, "%v -> %s (%v)\n", intmac(key), entry.peer.Name, entry.lastSeen)
fmt.Fprintf(&buf, "%v -> %s (%v)\n", intmac(key), entry.peer.FullName(), entry.lastSeen)
}
return buf.String()
}
+5 -1
View File
@@ -33,7 +33,11 @@ func NewPeer(name PeerName, nickName string, uid uint64, version uint64) *Peer {
func (peer *Peer) String() string {
peer.RLock()
defer peer.RUnlock()
return fmt.Sprint("Peer ", peer.Name, " (", peer.NickName, ") (v", peer.version, ") (UID ", peer.UID, ")")
return fmt.Sprint("Peer ", peer.FullName(), " (v", peer.version, ") (UID ", peer.UID, ")")
}
func (peer *Peer) FullName() string {
return fmt.Sprint(peer.Name, "(", peer.NickName, ")")
}
func (peer *Peer) Version() uint64 {
+1 -1
View File
@@ -136,7 +136,7 @@ func (peers *Peers) String() string {
if !conn.Established() {
established = " (unestablished)"
}
fmt.Fprintf(&buf, " -> %v (%v) [%v%s]\n", conn.Remote().Name, conn.Remote().NickName, conn.RemoteTCPAddr(), established)
fmt.Fprintf(&buf, " -> %s [%v%s]\n", conn.Remote().FullName(), conn.RemoteTCPAddr(), established)
}
})
return buf.String()
+4 -4
View File
@@ -55,11 +55,11 @@ func NewRouter(iface *net.Interface, name PeerName, nickName string, password []
BufSz: bufSz,
LogFrame: logFrame}
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
log.Println("Expired MAC", mac, "at", peer.Name)
log.Println("Expired MAC", mac, "at", peer.FullName())
}
onPeerGC := func(peer *Peer) {
router.Macs.Delete(peer)
log.Println("Removed unreachable", peer)
log.Println("Removed unreachable peer", peer.FullName())
}
router.Ourself = NewLocalPeer(name, nickName, router)
router.Macs = NewMacCache(macMaxAge, onMacExpiry)
@@ -92,7 +92,7 @@ func (router *Router) UsingPassword() bool {
func (router *Router) Status() string {
var buf bytes.Buffer
fmt.Fprintln(&buf, "Our name is", router.Ourself.Name, "("+router.Ourself.NickName+")")
fmt.Fprintln(&buf, "Our name is", router.Ourself.FullName())
fmt.Fprintln(&buf, "Sniffing traffic on", router.Iface)
fmt.Fprintf(&buf, "MACs:\n%s", router.Macs)
fmt.Fprintf(&buf, "Peers:\n%s", router.Peers)
@@ -322,7 +322,7 @@ func (router *Router) handleUDPPacketFunc(dec *EthernetDecoder, po PacketSink) F
dstMac := dec.eth.DstMAC
if router.Macs.Enter(srcMac, srcPeer) {
log.Println("Discovered remote MAC", srcMac, "at", srcPeer.Name)
log.Println("Discovered remote MAC", srcMac, "at", srcPeer.FullName())
}
router.LogFrame("Injecting", frame, &dec.eth)
checkWarn(po.WritePacket(frame))