diff --git a/p2p/protocols/accounting.go b/p2p/protocols/accounting.go index 95713ca6f6..f6b7c653c9 100644 --- a/p2p/protocols/accounting.go +++ b/p2p/protocols/accounting.go @@ -104,6 +104,9 @@ func NewAccounting(balance Balance, po Prices) *Accounting { } //Implement Hook.Send +// Send takes a peer, a size and a msg and +// - calculates the cost for the local node sending a msg of size to peer using the Prices interface +// - credits/debits local node using balance interface func (ah *Accounting) Send(peer *Peer, size uint32, msg interface{}) error { //get the price for a message (through the protocol spec) price := ah.Price(msg) @@ -121,6 +124,9 @@ func (ah *Accounting) Send(peer *Peer, size uint32, msg interface{}) error { } //Implement Hook.Receive +// Receive takes a peer, a size and a msg and +// - calculates the cost for the local node receiving a msg of size from peer using the Prices interface +// - credits/debits local node using balance interface func (ah *Accounting) Receive(peer *Peer, size uint32, msg interface{}) error { //get the price for a message (through the protocol spec) price := ah.Price(msg) @@ -139,21 +145,19 @@ func (ah *Accounting) Receive(peer *Peer, size uint32, msg interface{}) error { //record some metrics func (ah *Accounting) doMetrics(price int64, size uint32, err error) { - /* - if price > 0 { - mBalanceCredit.Inc(int64(price)) - mBytesCredit.Inc(int64(size)) - mMsgCredit.Inc(1) - if err != nil { - mPeerDrops.Inc(1) - } - } else { - mBalanceDebit.Inc(int64(price)) - mBytesDebit.Inc(int64(size)) - mMsgDebit.Inc(1) - if err != nil { - mSelfDrops.Inc(1) - } + if price > 0 { + mBalanceCredit.Inc(price) + mBytesCredit.Inc(int64(size)) + mMsgCredit.Inc(1) + if err != nil { + mPeerDrops.Inc(1) } - */ + } else { + mBalanceDebit.Inc(price) + mBytesDebit.Inc(int64(size)) + mMsgDebit.Inc(1) + if err != nil { + mSelfDrops.Inc(1) + } + } } diff --git a/p2p/protocols/protocol_test.go b/p2p/protocols/protocol_test.go index bbaed48d6d..be7c619923 100644 --- a/p2p/protocols/protocol_test.go +++ b/p2p/protocols/protocol_test.go @@ -262,7 +262,7 @@ func TestProtocolHook(t *testing.T) { if testHook.msg == nil || testHook.msg.(*dummyMsg).Content != "handshake" { t.Fatal("Expected msg to be set, but it is not") } - if testHook.send != true { + if !testHook.send { t.Fatal("Expected a send message, but it is not") } if testHook.peer == nil || testHook.peer.ID() != tester.Nodes[0].ID() { @@ -290,7 +290,7 @@ func TestProtocolHook(t *testing.T) { if testHook.msg == nil || testHook.msg.(*dummyMsg).Content != "response" { t.Fatal("Expected msg to be set, but it is not") } - if testHook.send != false { + if testHook.send { t.Fatal("Expected a send message, but it is not") } if testHook.peer == nil || testHook.peer.ID() != tester.Nodes[1].ID() {