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) Shutdown(error) {}
func (conn *RemoteConnection) Log(args ...interface{}) { 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 { func (conn *RemoteConnection) String() string {
from := "<nil>" from := "<nil>"
if conn.local != nil { if conn.local != nil {
from = conn.local.Name.String() from = conn.local.FullName()
} }
to := "<nil>" to := "<nil>"
if conn.remote != nil { if conn.remote != nil {
to = conn.remote.Name.String() to = conn.remote.FullName()
} }
return fmt.Sprint("Connection ", from, "->", to) return fmt.Sprint("Connection ", from, "->", to)
} }
@@ -223,7 +223,7 @@ func (conn *LocalConnection) ReceivedHeartbeat(remoteUDPAddr *net.UDPAddr, connU
if oldRemoteUDPAddr == nil { if oldRemoteUDPAddr == nil {
return conn.sendFastHeartbeats() return conn.sendFastHeartbeats()
} else if oldRemoteUDPAddr.String() != remoteUDPAddr.String() { } 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 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) log.Printf("->[%s] connection shutting down due to error during handshake: %v\n", conn.remoteTCPAddr, err)
return 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 // We invoke AddConnection in the same goroutine that subsequently
// becomes the tcp receive loop, rather than outside, because a) // 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 { if !found {
// Not necessarily an error as there could be a race with the // Not necessarily an error as there could be a race with the
// dst disappearing whilst the frame is in flight // 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 return nil
} }
conn, found := peer.ConnectionTo(relayPeerName) 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") log.Fatal("Attempt made to add connection to peer with unknown remote peer")
} }
toName := conn.Remote().Name 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 // deliberately non symmetrical
if dupConn, found := peer.connections[toName]; found { if dupConn, found := peer.connections[toName]; found {
if dupConn == conn { if dupConn == conn {
+1 -1
View File
@@ -89,7 +89,7 @@ func (cache *MacCache) String() string {
cache.RLock() cache.RLock()
defer cache.RUnlock() defer cache.RUnlock()
for key, entry := range cache.table { 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() 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 { func (peer *Peer) String() string {
peer.RLock() peer.RLock()
defer peer.RUnlock() 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 { func (peer *Peer) Version() uint64 {
+1 -1
View File
@@ -136,7 +136,7 @@ func (peers *Peers) String() string {
if !conn.Established() { if !conn.Established() {
established = " (unestablished)" 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() return buf.String()
+4 -4
View File
@@ -55,11 +55,11 @@ func NewRouter(iface *net.Interface, name PeerName, nickName string, password []
BufSz: bufSz, BufSz: bufSz,
LogFrame: logFrame} LogFrame: logFrame}
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) { 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) { onPeerGC := func(peer *Peer) {
router.Macs.Delete(peer) router.Macs.Delete(peer)
log.Println("Removed unreachable", peer) log.Println("Removed unreachable peer", peer.FullName())
} }
router.Ourself = NewLocalPeer(name, nickName, router) router.Ourself = NewLocalPeer(name, nickName, router)
router.Macs = NewMacCache(macMaxAge, onMacExpiry) router.Macs = NewMacCache(macMaxAge, onMacExpiry)
@@ -92,7 +92,7 @@ func (router *Router) UsingPassword() bool {
func (router *Router) Status() string { func (router *Router) Status() string {
var buf bytes.Buffer 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.Fprintln(&buf, "Sniffing traffic on", router.Iface)
fmt.Fprintf(&buf, "MACs:\n%s", router.Macs) fmt.Fprintf(&buf, "MACs:\n%s", router.Macs)
fmt.Fprintf(&buf, "Peers:\n%s", router.Peers) 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 dstMac := dec.eth.DstMAC
if router.Macs.Enter(srcMac, srcPeer) { 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) router.LogFrame("Injecting", frame, &dec.eth)
checkWarn(po.WritePacket(frame)) checkWarn(po.WritePacket(frame))
+10 -10
View File
@@ -58,19 +58,19 @@ This produces output like:
```` ````
weave router 0.7.0 weave router 0.7.0
Encryption off Encryption off
Our name is 7a:f4:56:87:76:3b (weave01) Our name is 7a:f4:56:87:76:3b(weave01)
Sniffing traffic on &{39 65535 ethwe ae:e3:07:9c:8c:d4 up|broadcast|multicast} Sniffing traffic on &{39 65535 ethwe ae:e3:07:9c:8c:d4 up|broadcast|multicast}
MACs: MACs:
ba:8c:b9:dc:e1:c9 -> 7a:f4:56:87:76:3b (2014-10-23 16:39:19.482338935 +0000 UTC) ba:8c:b9:dc:e1:c9 -> 7a:f4:56:87:76:3b(weave01) (2014-10-23 16:39:19.482338935 +0000 UTC)
ce:15:34:a9:b5:6d -> 7a:f4:56:87:76:3b (2014-10-23 16:39:28.257103595 +0000 UTC) ce:15:34:a9:b5:6d -> 7a:f4:56:87:76:3b(weave01) (2014-10-23 16:39:28.257103595 +0000 UTC)
7a:61:a2:49:4b:91 -> 7a:f4:56:87:76:3b (2014-10-23 16:39:27.482970752 +0000 UTC) 7a:61:a2:49:4b:91 -> 7a:f4:56:87:76:3b(weave01) (2014-10-23 16:39:27.482970752 +0000 UTC)
9e:95:0c:54:8e:39 -> 7a:16:dd:5b:83:de (2014-10-23 16:39:28.795601325 +0000 UTC) 9e:95:0c:54:8e:39 -> 7a:16:dd:5b:83:de(weave02) (2014-10-23 16:39:28.795601325 +0000 UTC)
72:5f:a4:60:e5:ce -> 7a:16:dd:5b:83:de (2014-10-23 16:39:29.575995255 +0000 UTC) 72:5f:a4:60:e5:ce -> 7a:16:dd:5b:83:de(weave02) (2014-10-23 16:39:29.575995255 +0000 UTC)
Peers: Peers:
Peer 7a:16:dd:5b:83:de (weave02) (v31) (UID 13151318985609435078) Peer 7a:16:dd:5b:83:de(weave02) (v31) (UID 13151318985609435078)
-> 7a:f4:56:87:76:3b (weave01) [37.157.33.76:7195] -> 7a:f4:56:87:76:3b(weave01) [37.157.33.76:7195]
Peer 7a:f4:56:87:76:3b (weave01) (v1) (UID 6913268221365110570) Peer 7a:f4:56:87:76:3b(weave01) (v1) (UID 6913268221365110570)
-> 7a:16:dd:5b:83:de (weave02) [191.235.147.190:6783] -> 7a:16:dd:5b:83:de(weave02) [191.235.147.190:6783]
Routes: Routes:
unicast: unicast:
7a:f4:56:87:76:3b -> 00:00:00:00:00:00 7a:f4:56:87:76:3b -> 00:00:00:00:00:00
+1 -1
View File
@@ -121,7 +121,7 @@ func main() {
} }
router := weave.NewRouter(iface, ourName, nickName, pwSlice, connLimit, bufSz*1024*1024, logFrameFunc(debug)) router := weave.NewRouter(iface, ourName, nickName, pwSlice, connLimit, bufSz*1024*1024, logFrameFunc(debug))
log.Println("Our name is", router.Ourself.Name, "("+router.Ourself.NickName+")") log.Println("Our name is", router.Ourself.FullName())
router.Start() router.Start()
initiateConnections(router, peers) initiateConnections(router, peers)
go handleHTTP(router) go handleHTTP(router)