Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
HAOYUatHZ committed Oct 30, 2018
1 parent 903a43c commit 443f2e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
51 changes: 26 additions & 25 deletions netsync/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"net"
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/tendermint/tmlibs/flowrate"
Expand Down Expand Up @@ -39,17 +40,17 @@ type BasePeerSet interface {

// PeerInfo indicate peer status snap
type PeerInfo struct {
ID string `json:"peer_id"`
RemoteAddr string `json:"remote_addr"`
Height uint64 `json:"height"`
Ping string `json:"ping"`
Duration string `json:"duration"`
TotalSent int64 `json:"total_sent"`
TotalReceive int64 `json:"total_receive"`
AverageSentRate int64 `json:"average_sent_rate"`
AverageReceiveRate int64 `json:"average_receive_rate"`
CurrentSentRate int64 `json:"current_sent_rate"`
CurrentReceiveRate int64 `json:"current_receive_rate"`
ID string `json:"peer_id"`
RemoteAddr string `json:"remote_addr"`
Height uint64 `json:"height"`
Ping time.Duration `json:"ping"`
Duration time.Duration `json:"duration"`
TotalSent int64 `json:"total_sent"`
TotalReceived int64 `json:"total_received"`
AverageSentRate int64 `json:"average_sent_rate"`
AverageReceivedRate int64 `json:"average_received_rate"`
CurrentSentRate int64 `json:"current_sent_rate"`
CurrentReceivedRate int64 `json:"current_received_rate"`
}

type peer struct {
Expand Down Expand Up @@ -149,24 +150,24 @@ func (p *peer) getPeerInfo() *PeerInfo {
p.mtx.RLock()
defer p.mtx.RUnlock()

sentStatus, receiveStatus := p.TrafficStatus()
ping := sentStatus.Idle - receiveStatus.Idle
if receiveStatus.Idle > sentStatus.Idle {
sentStatus, receivedStatus := p.TrafficStatus()
ping := sentStatus.Idle - receivedStatus.Idle
if receivedStatus.Idle > sentStatus.Idle {
ping = -ping
}

return &PeerInfo{
ID: p.ID(),
RemoteAddr: p.Addr().String(),
Height: p.height,
Ping: ping.String(),
Duration: sentStatus.Duration.String(),
TotalSent: sentStatus.Bytes,
TotalReceive: receiveStatus.Bytes,
AverageSentRate: sentStatus.AvgRate,
AverageReceiveRate: receiveStatus.AvgRate,
CurrentSentRate: sentStatus.CurRate,
CurrentReceiveRate: receiveStatus.CurRate,
ID: p.ID(),
RemoteAddr: p.Addr().String(),
Height: p.height,
Ping: ping,
Duration: sentStatus.Duration,
TotalSent: sentStatus.Bytes,
TotalReceived: receivedStatus.Bytes,
AverageSentRate: sentStatus.AvgRate,
AverageReceivedRate: receivedStatus.AvgRate,
CurrentSentRate: sentStatus.CurRate,
CurrentReceivedRate: receivedStatus.CurRate,
}
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func (c *MConnection) Send(chID byte, msg interface{}) bool {
// TrafficStatus return the in and out traffic status
func (c *MConnection) TrafficStatus() (*flowrate.Status, *flowrate.Status) {
sentStatus := c.sendMonitor.Status()
receiveStatus := c.recvMonitor.Status()
return &sentStatus, &receiveStatus
receivedStatus := c.recvMonitor.Status()
return &sentStatus, &receivedStatus
}

// TrySend queues a message to be sent to channel(Nonblocking).
Expand Down
16 changes: 8 additions & 8 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ func (sw *Switch) stopAndRemovePeer(peer *Peer, reason interface{}) {
}
peer.Stop()

sentStatus, receiveStatus := peer.TrafficStatus()
sentStatus, receivedStatus := peer.TrafficStatus()
log.WithFields(log.Fields{
"address": peer.Addr().String(),
"reason": reason,
"duration": sentStatus.Duration.String(),
"total_sent": sentStatus.Bytes,
"total_receive": receiveStatus.Bytes,
"average_sent_rate": sentStatus.AvgRate,
"average_receive_rate": receiveStatus.AvgRate,
"address": peer.Addr().String(),
"reason": reason,
"duration": sentStatus.Duration.String(),
"total_sent": sentStatus.Bytes,
"total_received": receivedStatus.Bytes,
"average_sent_rate": sentStatus.AvgRate,
"average_received_rate": receivedStatus.AvgRate,
}).Info("disconnect with peer")
}

0 comments on commit 443f2e5

Please sign in to comment.