"sync/atomic"
"time"
+ log "github.com/sirupsen/logrus"
wire "github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
flow "github.com/tendermint/tmlibs/flowrate"
}
func (c *MConnection) flush() {
- c.Logger.Debug("Flush", "conn", c)
+ log.WithField("conn", c).Debug("Flush")
err := c.bufWriter.Flush()
if err != nil {
- c.Logger.Error("MConnection flush failed", "error", err)
+ log.WithField("error", err).Error("MConnection flush failed")
}
}
return false
}
- c.Logger.Debug("Send", "channel", chID, "conn", c, "msg", msg) //, "bytes", wire.BinaryBytes(msg))
+ log.WithFields(log.Fields{
+ "chID": chID,
+ "conn": c,
+ "msg": msg,
+ }).Debug("Send")
// Send message to channel.
channel, ok := c.channelsIdx[chID]
if !ok {
- c.Logger.Error(cmn.Fmt("Cannot send bytes, unknown channel %X", chID))
+ log.WithField("chID", chID).Error(cmn.Fmt("Cannot send bytes, unknown channel"))
return false
}
default:
}
} else {
- c.Logger.Error("Send failed", "channel", chID, "conn", c, "msg", msg)
+ log.WithFields(log.Fields{
+ "chID": chID,
+ "conn": c,
+ "msg": msg,
+ }).Error("Send failed")
}
return success
}
return false
}
- c.Logger.Debug("TrySend", "channel", chID, "conn", c, "msg", msg)
+ log.WithFields(log.Fields{
+ "chID": chID,
+ "conn": c,
+ "msg": msg,
+ }).Debug("TrySend")
// Send message to channel.
channel, ok := c.channelsIdx[chID]
if !ok {
- c.Logger.Error(cmn.Fmt("Cannot send bytes, unknown channel %X", chID))
+ log.WithField("chID", chID).Error(cmn.Fmt("cannot send bytes, unknown channel"))
return false
}
channel, ok := c.channelsIdx[chID]
if !ok {
- c.Logger.Error(cmn.Fmt("Unknown channel %X", chID))
+ log.WithField("chID", chID).Error(cmn.Fmt("Unknown channel"))
return false
}
return channel.canSend()
channel.updateStats()
}
case <-c.pingTimer.Ch:
- c.Logger.Debug("Send Ping")
+ log.Debug("Send Ping")
wire.WriteByte(packetTypePing, c.bufWriter, &n, &err)
c.sendMonitor.Update(int(n))
c.flush()
case <-c.pong:
- c.Logger.Debug("Send Pong")
+ log.Debug("Send Pong")
wire.WriteByte(packetTypePong, c.bufWriter, &n, &err)
c.sendMonitor.Update(int(n))
c.flush()
break FOR_LOOP
}
if err != nil {
- c.Logger.Error("Connection failed @ sendRoutine", "conn", c, "error", err)
+ log.WithFields(log.Fields{
+ "conn": c,
+ "error": err,
+ }).Error("Connection failed @ sendRoutine")
c.stopForError(err)
break FOR_LOOP
}
// Make & send a msgPacket from this channel
n, err := leastChannel.writeMsgPacketTo(c.bufWriter)
if err != nil {
- c.Logger.Error("Failed to write msgPacket", "error", err)
+ log.WithField("error", err).Error("Failed to write msgPacket")
c.stopForError(err)
return true
}
c.recvMonitor.Update(int(n))
if err != nil {
if c.IsRunning() {
- c.Logger.Error("Connection failed @ recvRoutine (reading byte)", "conn", c, "error", err)
+ log.WithFields(log.Fields{
+ "conn": c,
+ "error": err,
+ }).Error("Connection failed @ recvRoutine (reading byte)")
c.stopForError(err)
}
break FOR_LOOP
switch pktType {
case packetTypePing:
// TODO: prevent abuse, as they cause flush()'s.
- c.Logger.Debug("Receive Ping")
+ log.Debug("Receive Ping")
c.pong <- struct{}{}
case packetTypePong:
// do nothing
- c.Logger.Debug("Receive Pong")
+ log.Debug("Receive Pong")
case packetTypeMsg:
pkt, n, err := msgPacket{}, int(0), error(nil)
wire.ReadBinaryPtr(&pkt, c.bufReader, maxMsgPacketTotalSize, &n, &err)
c.recvMonitor.Update(int(n))
if err != nil {
if c.IsRunning() {
- c.Logger.Error("Connection failed @ recvRoutine", "conn", c, "error", err)
+ log.WithFields(log.Fields{
+ "conn": c,
+ "error": err,
+ }).Error("Connection failed @ recvRoutine")
c.stopForError(err)
}
break FOR_LOOP
msgBytes, err := channel.recvMsgPacket(pkt)
if err != nil {
if c.IsRunning() {
- c.Logger.Error("Connection failed @ recvRoutine", "conn", c, "error", err)
+ log.WithFields(log.Fields{
+ "conn": c,
+ "error": err,
+ }).Error("Connection failed @ recvRoutine")
c.stopForError(err)
}
break FOR_LOOP
}
if msgBytes != nil {
c.Logger.Debug("Received bytes", "chID", pkt.ChannelID, "msgBytes", msgBytes)
+ log.WithFields(log.Fields{
+ "channelID": pkt.ChannelID,
+ "msgBytes": msgBytes,
+ }).Debug("Received bytes")
c.onReceive(pkt.ChannelID, msgBytes)
}
default:
// Not goroutine-safe
func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int, err error) {
packet := ch.nextMsgPacket()
- // log.Debug("Write Msg Packet", "conn", ch.conn, "packet", packet)
wire.WriteByte(packetTypeMsg, w, &n, &err)
wire.WriteBinary(packet, w, &n, &err)
if err == nil {
// Handles incoming msgPackets. Returns a msg bytes if msg is complete.
// Not goroutine-safe
func (ch *Channel) recvMsgPacket(packet msgPacket) ([]byte, error) {
- // log.Debug("Read Msg Packet", "conn", ch.conn, "packet", packet)
if ch.desc.RecvMessageCapacity < len(ch.recving)+len(packet.Bytes) {
return nil, wire.ErrBinaryReadOverflow
}