Merge branch 'fix-dotted-imports-for-log' of https://github.com/dpw/weave into pr1254

This commit is contained in:
Michael Bridgen committed 2015-08-03 14:29:53 +01:00
commit 778038fdd3
9 files changed
+44 -54

No files matched your search

-7
View File
@@ -6,10 +6,3 @@ func Assert(test bool) {
panic("Assertion failure")
}
}
func OnOff(b bool) string {
if b {
return "on"
}
return "off"
}
+5 -7
View File
@@ -7,8 +7,6 @@ import (
"strconv"
"sync"
"time"
. "github.com/weaveworks/weave/common"
)
type Connection interface {
@@ -84,11 +82,11 @@ 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)), args...)...)
log.Println(append(append([]interface{}{}, fmt.Sprintf("->[%s|%s]:", conn.remoteTCPAddr, conn.remote)), args...)...)
}
func (conn *RemoteConnection) ErrorLog(args ...interface{}) {
Log.Errorln(append(append([]interface{}{}, fmt.Sprintf("->[%s|%s]:", conn.remoteTCPAddr, conn.remote)), args...)...)
log.Errorln(append(append([]interface{}{}, fmt.Sprintf("->[%s|%s]:", conn.remoteTCPAddr, conn.remote)), args...)...)
}
func (conn *RemoteConnection) String() string {
@@ -107,7 +105,7 @@ func (conn *RemoteConnection) String() string {
// end up in the local peer's connections map.
func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, udpAddr *net.UDPAddr, router *Router, acceptNewPeer bool) {
if connRemote.local != router.Ourself.Peer {
Log.Fatal("Attempt to create local connection from a peer which is not ourself")
log.Fatal("Attempt to create local connection from a peer which is not ourself")
}
// NB, we're taking a copy of connRemote here.
actionChan := make(chan ConnectionAction, ChannelSize)
@@ -233,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, "moved from", oldRemoteUDPAddr, "to", remoteUDPAddr)
log.Println("Peer", conn.remote, "moved from", oldRemoteUDPAddr, "to", remoteUDPAddr)
}
return nil
})
@@ -488,7 +486,7 @@ func (conn *LocalConnection) actorLoop(actionChan <-chan ConnectionAction) (err
func (conn *LocalConnection) shutdown(err error) {
if conn.remote == nil {
Log.Errorf("->[%s] connection shutting down due to error during handshake: %v", conn.remoteTCPAddr, err)
log.Errorf("->[%s] connection shutting down due to error during handshake: %v", conn.remoteTCPAddr, err)
} else {
conn.ErrorLog("connection shutting down due to error:", err)
}
+2 -4
View File
@@ -6,8 +6,6 @@ import (
"math/rand"
"net"
"time"
. "github.com/weaveworks/weave/common"
)
const (
@@ -299,9 +297,9 @@ func (cm *ConnectionMaker) connectToTargets(validTarget map[string]struct{}, dir
}
func (cm *ConnectionMaker) attemptConnection(address string, acceptNewPeer bool) {
Log.Printf("->[%s] attempting connection", address)
log.Printf("->[%s] attempting connection", address)
if err := cm.ourself.CreateConnection(address, acceptNewPeer); err != nil {
Log.Errorf("->[%s] error during connection attempt: %v", address, err)
log.Errorf("->[%s] error during connection attempt: %v", address, err)
cm.ConnectionTerminated(address, err)
}
}
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
. "github.com/weaveworks/weave/common"
)
type EthernetDecoder struct {
@@ -61,7 +60,7 @@ func (dec *EthernetDecoder) sendICMPFragNeeded(mtu int, sendFrame func([]byte) e
return err
}
Log.Printf("Sending ICMP 3,4 (%v -> %v): PMTU= %v", dec.IP.DstIP, dec.IP.SrcIP, mtu)
log.Printf("Sending ICMP 3,4 (%v -> %v): PMTU= %v", dec.IP.DstIP, dec.IP.SrcIP, mtu)
return sendFrame(buf.Bytes())
}
+1 -3
View File
@@ -5,8 +5,6 @@ import (
"encoding/gob"
"fmt"
"sync"
. "github.com/weaveworks/weave/common"
)
type GossipChannel struct {
@@ -226,5 +224,5 @@ func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) {
}
func (c *GossipChannel) log(args ...interface{}) {
Log.Println(append(append([]interface{}{}, "[gossip "+c.name+"]:"), args...)...)
log.Println(append(append([]interface{}{}, "[gossip "+c.name+"]:"), args...)...)
}
+9 -11
View File
@@ -5,8 +5,6 @@ import (
"net"
"sync"
"time"
. "github.com/weaveworks/weave/common"
)
type LocalPeer struct {
@@ -42,13 +40,13 @@ func (peer *LocalPeer) Relay(srcPeer, dstPeer *Peer, frame []byte, dec *Ethernet
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)
log.Println("Received packet for unknown destination:", dstPeer)
return nil
}
conn, found := peer.ConnectionTo(relayPeerName)
if !found {
// Again, could just be a race, not necessarily an error
Log.Println("Unable to find connection to relay peer", relayPeerName)
log.Println("Unable to find connection to relay peer", relayPeerName)
return nil
}
return conn.(*LocalConnection).Forward(&ForwardedFrame{
@@ -71,9 +69,9 @@ func (peer *LocalPeer) RelayBroadcast(srcPeer *Peer, frame []byte, dec *Ethernet
dec)
if err != nil {
if ftbe, ok := err.(FrameTooBigError); ok {
Log.Warningf("dropping too big DF broadcast frame (%v -> %v): PMTU= %v", dec.IP.DstIP, dec.IP.SrcIP, ftbe.EPMTU)
log.Warningf("dropping too big DF broadcast frame (%v -> %v): PMTU= %v", dec.IP.DstIP, dec.IP.SrcIP, ftbe.EPMTU)
} else {
Log.Errorln(err)
log.Errorln(err)
}
}
}
@@ -182,10 +180,10 @@ func (peer *LocalPeer) actorLoop(actionChan <-chan LocalPeerAction) {
func (peer *LocalPeer) handleAddConnection(conn Connection) error {
if peer.Peer != conn.Local() {
Log.Fatal("Attempt made to add connection to peer where peer is not the source of connection")
log.Fatal("Attempt made to add connection to peer where peer is not the source of connection")
}
if conn.Remote() == nil {
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
dupErr := fmt.Errorf("Multiple connections to %s added to %s", conn.Remote(), peer.String())
@@ -224,7 +222,7 @@ func (peer *LocalPeer) handleAddConnection(conn Connection) error {
func (peer *LocalPeer) handleConnectionEstablished(conn Connection) {
if peer.Peer != conn.Local() {
Log.Fatal("Peer informed of active connection where peer is not the source of connection")
log.Fatal("Peer informed of active connection where peer is not the source of connection")
}
if dupConn, found := peer.connections[conn.Remote().Name]; !found || conn != dupConn {
conn.Shutdown(fmt.Errorf("Cannot set unknown connection active"))
@@ -237,10 +235,10 @@ func (peer *LocalPeer) handleConnectionEstablished(conn Connection) {
func (peer *LocalPeer) handleDeleteConnection(conn Connection) {
if peer.Peer != conn.Local() {
Log.Fatal("Attempt made to delete connection from peer where peer is not the source of connection")
log.Fatal("Attempt made to delete connection from peer where peer is not the source of connection")
}
if conn.Remote() == nil {
Log.Fatal("Attempt made to delete connection to peer with unknown remote peer")
log.Fatal("Attempt made to delete connection to peer with unknown remote peer")
}
toName := conn.Remote().Name
if connFound, found := peer.connections[toName]; !found || connFound != conn {
+20 -15
View File
@@ -9,8 +9,6 @@ import (
"sync"
"syscall"
"time"
. "github.com/weaveworks/weave/common"
)
const (
@@ -69,11 +67,11 @@ type PacketSourceSink interface {
func NewRouter(config Config, name PeerName, nickName string) *Router {
router := &Router{Config: config, gossipChannels: make(GossipChannels)}
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
Log.Println("Expired MAC", mac, "at", peer)
log.Println("Expired MAC", mac, "at", peer)
}
onPeerGC := func(peer *Peer) {
router.Macs.Delete(peer)
Log.Println("Removed unreachable peer", peer)
log.Println("Removed unreachable peer", peer)
}
router.Ourself = NewLocalPeer(name, nickName, router)
router.Macs = NewMacCache(macMaxAge, onMacExpiry)
@@ -120,8 +118,8 @@ func (router *Router) UsingPassword() bool {
func (router *Router) Status() string {
var buf bytes.Buffer
fmt.Fprintln(&buf, "Our name is", router.Ourself)
fmt.Fprintln(&buf, "Encryption", OnOff(router.UsingPassword()))
fmt.Fprintln(&buf, "Peer discovery", OnOff(router.PeerDiscovery))
fmt.Fprintln(&buf, "Encryption", onOff(router.UsingPassword()))
fmt.Fprintln(&buf, "Peer discovery", onOff(router.PeerDiscovery))
fmt.Fprintln(&buf, "Sniffing traffic on", router.Iface)
fmt.Fprintf(&buf, "MACs:\n%s", router.Macs)
fmt.Fprintf(&buf, "Peers:\n%s", router.Peers)
@@ -130,13 +128,20 @@ func (router *Router) Status() string {
return buf.String()
}
func onOff(b bool) string {
if b {
return "on"
}
return "off"
}
func (router *Router) sniff(pio PacketSourceSink) {
Log.Println("Sniffing traffic on", router.Iface)
log.Println("Sniffing traffic on", router.Iface)
dec := NewEthernetDecoder()
mac := router.Iface.HardwareAddr
if router.Macs.Enter(mac, router.Ourself.Peer) {
Log.Println("Discovered our MAC", mac)
log.Println("Discovered our MAC", mac)
}
go func() {
for {
@@ -163,7 +168,7 @@ func (router *Router) handleCapturedPacket(frameData []byte, dec *EthernetDecode
return
}
if router.Macs.Enter(srcMac, router.Ourself.Peer) {
Log.Println("Discovered local MAC", srcMac)
log.Println("Discovered local MAC", srcMac)
}
if dec.DropFrame() {
return
@@ -206,7 +211,7 @@ func (router *Router) listenTCP(localPort int) {
for {
tcpConn, err := ln.AcceptTCP()
if err != nil {
Log.Errorln(err)
log.Errorln(err)
continue
}
router.acceptTCP(tcpConn)
@@ -220,7 +225,7 @@ func (router *Router) acceptTCP(tcpConn *net.TCPConn) {
// on router.Port and we wait for them to send us something on UDP to
// start.
remoteAddrStr := tcpConn.RemoteAddr().String()
Log.Printf("->[%s] connection accepted", remoteAddrStr)
log.Printf("->[%s] connection accepted", remoteAddrStr)
connRemote := NewRemoteConnection(router.Ourself.Peer, nil, remoteAddrStr, false, false)
StartLocalConnection(connRemote, tcpConn, nil, router, true)
}
@@ -250,10 +255,10 @@ func (router *Router) udpReader(conn *net.UDPConn, po PacketSink) {
if err == io.EOF {
return
} else if err != nil {
Log.Warnln("ignoring UDP read error", err)
log.Warnln("ignoring UDP read error", err)
continue
} else if n < NameSize {
Log.Warnln("ignoring too short UDP packet from", sender)
log.Warnln("ignoring too short UDP packet from", sender)
continue
}
name := PeerNameFromBin(buf[:NameSize])
@@ -330,7 +335,7 @@ func (router *Router) handleUDPPacketFunc(relayConn *LocalConnection, dec *Ether
dstMac := dec.Eth.DstMAC
if router.Macs.Enter(srcMac, srcPeer) {
Log.Println("Discovered remote MAC", srcMac, "at", srcPeer)
log.Println("Discovered remote MAC", srcMac, "at", srcPeer)
}
if po != nil {
router.LogFrame("Injecting", frame, dec)
@@ -416,7 +421,7 @@ func (router *Router) applyTopologyUpdate(update []byte) (PeerNameSet, PeerNameS
// itself included in the update, and we didn't know about
// already. We ignore this; eventually we should receive an
// update containing a complete topology.
Log.Println("Topology gossip:", err)
log.Println("Topology gossip:", err)
return nil, nil, nil
}
if err != nil {
+1 -2
View File
@@ -6,7 +6,6 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
. "github.com/weaveworks/weave/common"
)
type UDPSender interface {
@@ -87,7 +86,7 @@ func (sender *RawUDPSender) Send(msg []byte) error {
}
defer f.Close()
fd := int(f.Fd())
Log.Println("EMSGSIZE on send, expecting PMTU update (IP packet was",
log.Println("EMSGSIZE on send, expecting PMTU update (IP packet was",
len(packet), "bytes, payload was", len(msg), "bytes)")
pmtu, err := syscall.GetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_MTU)
if err != nil {
+5 -3
View File
@@ -7,20 +7,22 @@ import (
"fmt"
"net"
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common"
)
var log = common.Log
var void = struct{}{}
func checkFatal(e error) {
if e != nil {
Log.Fatal(e)
log.Fatal(e)
}
}
func checkWarn(e error) {
if e != nil {
Log.Warnln(e)
log.Warnln(e)
}
}