You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
933 B
38 lines
933 B
// package p2p
|
|
package p2p
|
|
|
|
import (
|
|
eth_metrics "github.com/ethereum/go-ethereum/metrics"
|
|
"github.com/libp2p/go-libp2p/core/metrics"
|
|
)
|
|
|
|
const (
|
|
// ingressMeterName is the prefix of the per-packet inbound metrics.
|
|
ingressMeterName = "p2p/ingress"
|
|
|
|
// egressMeterName is the prefix of the per-packet outbound metrics.
|
|
egressMeterName = "p2p/egress"
|
|
)
|
|
|
|
var (
|
|
ingressTrafficMeter = eth_metrics.NewRegisteredMeter(ingressMeterName, nil)
|
|
egressTrafficMeter = eth_metrics.NewRegisteredMeter(egressMeterName, nil)
|
|
)
|
|
|
|
// Counter is a wrapper around a metrics.BandwidthCounter that meters both the
|
|
// inbound and outbound network traffic.
|
|
type Counter struct {
|
|
*metrics.BandwidthCounter
|
|
}
|
|
|
|
func newCounter() *Counter {
|
|
return &Counter{metrics.NewBandwidthCounter()}
|
|
}
|
|
|
|
func (c *Counter) LogRecvMessage(size int64) {
|
|
ingressTrafficMeter.Mark(size)
|
|
}
|
|
|
|
func (c *Counter) LogSentMessage(size int64) {
|
|
egressTrafficMeter.Mark(size)
|
|
}
|
|
|