mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
p2p/protocols: addressed PR comments
This commit is contained in:
parent
3a35938a6c
commit
f2dee249c3
2 changed files with 22 additions and 18 deletions
|
|
@ -104,6 +104,9 @@ func NewAccounting(balance Balance, po Prices) *Accounting {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Implement Hook.Send
|
//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 {
|
func (ah *Accounting) Send(peer *Peer, size uint32, msg interface{}) error {
|
||||||
//get the price for a message (through the protocol spec)
|
//get the price for a message (through the protocol spec)
|
||||||
price := ah.Price(msg)
|
price := ah.Price(msg)
|
||||||
|
|
@ -121,6 +124,9 @@ func (ah *Accounting) Send(peer *Peer, size uint32, msg interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Implement Hook.Receive
|
//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 {
|
func (ah *Accounting) Receive(peer *Peer, size uint32, msg interface{}) error {
|
||||||
//get the price for a message (through the protocol spec)
|
//get the price for a message (through the protocol spec)
|
||||||
price := ah.Price(msg)
|
price := ah.Price(msg)
|
||||||
|
|
@ -139,21 +145,19 @@ func (ah *Accounting) Receive(peer *Peer, size uint32, msg interface{}) error {
|
||||||
|
|
||||||
//record some metrics
|
//record some metrics
|
||||||
func (ah *Accounting) doMetrics(price int64, size uint32, err error) {
|
func (ah *Accounting) doMetrics(price int64, size uint32, err error) {
|
||||||
/*
|
if price > 0 {
|
||||||
if price > 0 {
|
mBalanceCredit.Inc(price)
|
||||||
mBalanceCredit.Inc(int64(price))
|
mBytesCredit.Inc(int64(size))
|
||||||
mBytesCredit.Inc(int64(size))
|
mMsgCredit.Inc(1)
|
||||||
mMsgCredit.Inc(1)
|
if err != nil {
|
||||||
if err != nil {
|
mPeerDrops.Inc(1)
|
||||||
mPeerDrops.Inc(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mBalanceDebit.Inc(int64(price))
|
|
||||||
mBytesDebit.Inc(int64(size))
|
|
||||||
mMsgDebit.Inc(1)
|
|
||||||
if err != nil {
|
|
||||||
mSelfDrops.Inc(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
} else {
|
||||||
|
mBalanceDebit.Inc(price)
|
||||||
|
mBytesDebit.Inc(int64(size))
|
||||||
|
mMsgDebit.Inc(1)
|
||||||
|
if err != nil {
|
||||||
|
mSelfDrops.Inc(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ func TestProtocolHook(t *testing.T) {
|
||||||
if testHook.msg == nil || testHook.msg.(*dummyMsg).Content != "handshake" {
|
if testHook.msg == nil || testHook.msg.(*dummyMsg).Content != "handshake" {
|
||||||
t.Fatal("Expected msg to be set, but it is not")
|
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")
|
t.Fatal("Expected a send message, but it is not")
|
||||||
}
|
}
|
||||||
if testHook.peer == nil || testHook.peer.ID() != tester.Nodes[0].ID() {
|
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" {
|
if testHook.msg == nil || testHook.msg.(*dummyMsg).Content != "response" {
|
||||||
t.Fatal("Expected msg to be set, but it is not")
|
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")
|
t.Fatal("Expected a send message, but it is not")
|
||||||
}
|
}
|
||||||
if testHook.peer == nil || testHook.peer.ID() != tester.Nodes[1].ID() {
|
if testHook.peer == nil || testHook.peer.ID() != tester.Nodes[1].ID() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue