github.com/amazechain/amc@v0.1.3/internal/pubsub/pubsub_tracer.go (about)

     1  // Copyright 2022 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The AmazeChain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package pubsub
    18  
    19  import (
    20  	"github.com/libp2p/go-libp2p/core/peer"
    21  	"github.com/libp2p/go-libp2p/core/protocol"
    22  	pubsub "github.com/libp2p/go-libp2p-pubsub"
    23  	"github.com/rcrowley/go-metrics"
    24  )
    25  
    26  var (
    27  	egressPubsubTrafficMeter  = metrics.GetOrRegisterMeter("p2p/pubsub/egress", nil)
    28  	ingressPubsubTrafficMeter = metrics.GetOrRegisterMeter("p2p/pubsub/ingress", nil)
    29  )
    30  
    31  type rawTracer struct {
    32  }
    33  
    34  func newRawTracer() *rawTracer {
    35  	return &rawTracer{}
    36  }
    37  
    38  func (m rawTracer) AddPeer(p peer.ID, proto protocol.ID)             {}
    39  func (m rawTracer) RemovePeer(p peer.ID)                             {}
    40  func (m rawTracer) Join(topic string)                                {}
    41  func (m rawTracer) Leave(topic string)                               {}
    42  func (m rawTracer) Graft(p peer.ID, topic string)                    {}
    43  func (m rawTracer) Prune(p peer.ID, topic string)                    {}
    44  func (m rawTracer) ValidateMessage(msg *pubsub.Message)              {}
    45  func (m rawTracer) DeliverMessage(msg *pubsub.Message)               {}
    46  func (m rawTracer) RejectMessage(msg *pubsub.Message, reason string) {}
    47  func (m rawTracer) DuplicateMessage(msg *pubsub.Message)             {}
    48  func (m rawTracer) ThrottlePeer(p peer.ID)                           {}
    49  func (m rawTracer) UndeliverableMessage(msg *pubsub.Message)         {}
    50  func (m rawTracer) DropRPC(rpc *pubsub.RPC, p peer.ID)               {}
    51  
    52  func (m rawTracer) RecvRPC(rpc *pubsub.RPC) {
    53  	egressPubsubTrafficMeter.Mark(int64(rpc.Size()))
    54  }
    55  
    56  func (m rawTracer) SendRPC(rpc *pubsub.RPC, p peer.ID) {
    57  	ingressPubsubTrafficMeter.Mark(int64(rpc.Size()))
    58  }