This commit is contained in:
Dmitry Shulyak 2018-02-23 04:22:33 +00:00 committed by GitHub
commit 47d7f8da97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -0,0 +1,26 @@
// Copyright 2018 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package whisperv6
import "github.com/ethereum/go-ethereum/metrics"
var (
newEnvelopes = metrics.NewMeter("whisper/NewEnvelopes")
totalEnvelopes = metrics.NewMeter("whisper/TotalEnvelopes")
envelopesSize = metrics.NewMeter("whisper/EnvelopesSize")
metricsPeers = metrics.NewCounter("whisper/Peers")
)

View file

@ -624,15 +624,15 @@ func (whisper *Whisper) Stop() error {
func (whisper *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error { func (whisper *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
// Create the new peer and start tracking it // Create the new peer and start tracking it
whisperPeer := newPeer(whisper, peer, rw) whisperPeer := newPeer(whisper, peer, rw)
whisper.peerMu.Lock() whisper.peerMu.Lock()
whisper.peers[whisperPeer] = struct{}{} whisper.peers[whisperPeer] = struct{}{}
whisper.peerMu.Unlock() whisper.peerMu.Unlock()
metricsPeers.Inc(1)
defer func() { defer func() {
whisper.peerMu.Lock() whisper.peerMu.Lock()
delete(whisper.peers, whisperPeer) delete(whisper.peers, whisperPeer)
whisper.peerMu.Unlock() whisper.peerMu.Unlock()
metricsPeers.Dec(1)
}() }()
// Run the peer handshake and state updates // Run the peer handshake and state updates
@ -747,6 +747,9 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
// whisper network. It also inserts the envelope into the expiration pool at the // whisper network. It also inserts the envelope into the expiration pool at the
// appropriate time-stamp. In case of error, connection should be dropped. // appropriate time-stamp. In case of error, connection should be dropped.
func (whisper *Whisper) add(envelope *Envelope) (bool, error) { func (whisper *Whisper) add(envelope *Envelope) (bool, error) {
totalEnvelopes.Mark(1)
envelopesSize.Mark(int64(envelope.size()))
now := uint32(time.Now().Unix()) now := uint32(time.Now().Unix())
sent := envelope.Expiry - envelope.TTL sent := envelope.Expiry - envelope.TTL
@ -794,6 +797,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) {
whisper.poolMu.Lock() whisper.poolMu.Lock()
_, alreadyCached := whisper.envelopes[hash] _, alreadyCached := whisper.envelopes[hash]
if !alreadyCached { if !alreadyCached {
newEnvelopes.Mark(1)
whisper.envelopes[hash] = envelope whisper.envelopes[hash] = envelope
if whisper.expirations[envelope.Expiry] == nil { if whisper.expirations[envelope.Expiry] == nil {
whisper.expirations[envelope.Expiry] = set.NewNonTS() whisper.expirations[envelope.Expiry] = set.NewNonTS()