Skip to content
Snippets Groups Projects
Select Git revision
  • 78d174c6e44d3fa808d9fb3be70f240841858b2b
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

events.go

Blame
  • network.go 2.00 KiB
    package metrics
    
    import (
    	"github.com/iotaledger/goshimmer/plugins/gossip"
    	"github.com/iotaledger/hive.go/identity"
    	"go.uber.org/atomic"
    )
    
    var (
    	_FPCInboundBytes  atomic.Uint64
    	_FPCOutboundBytes atomic.Uint64
    
    	previousNeighbors = make(map[identity.ID]gossipTrafficMetric)
    	gossipOldTx       uint32
    	gossipOldRx       uint32
    	gossipCurrentTx   atomic.Uint64
    	gossipCurrentRx   atomic.Uint64
    
    	analysisOutboundBytes atomic.Uint64
    )
    
    // FPCInboundBytes returns the total inbound FPC traffic.
    func FPCInboundBytes() uint64 {
    	return _FPCInboundBytes.Load()
    }
    
    // FPCOutboundBytes returns the total outbound FPC traffic.
    func FPCOutboundBytes() uint64 {
    	return _FPCOutboundBytes.Load()
    }
    
    // GossipInboundBytes returns the total inbound gossip traffic.
    func GossipInboundBytes() uint64 {
    	return gossipCurrentRx.Load()
    }
    
    // GossipOutboundBytes returns the total outbound gossip traffic.
    func GossipOutboundBytes() uint64 {
    	return gossipCurrentTx.Load()
    }
    
    // AnalysisOutboundBytes returns the total outbound analysis traffic.
    func AnalysisOutboundBytes() uint64 {
    	return analysisOutboundBytes.Load()
    }
    
    type gossipTrafficMetric struct {
    	BytesRead    uint32
    	BytesWritten uint32
    }
    
    func gossipCurrentTraffic() (g gossipTrafficMetric) {
    	neighbors := gossip.Manager().AllNeighbors()
    
    	currentNeighbors := make(map[identity.ID]bool)
    	for _, neighbor := range neighbors {
    		currentNeighbors[neighbor.ID()] = true
    
    		if _, ok := previousNeighbors[neighbor.ID()]; !ok {
    			previousNeighbors[neighbor.ID()] = gossipTrafficMetric{
    				BytesRead:    neighbor.BytesRead(),
    				BytesWritten: neighbor.BytesWritten(),
    			}
    		}
    
    		g.BytesRead += neighbor.BytesRead()
    		g.BytesWritten += neighbor.BytesWritten()
    	}
    
    	for prevNeighbor := range previousNeighbors {
    		if _, ok := currentNeighbors[prevNeighbor]; !ok {
    			gossipOldRx += previousNeighbors[prevNeighbor].BytesRead
    			gossipOldTx += previousNeighbors[prevNeighbor].BytesWritten
    			delete(currentNeighbors, prevNeighbor)
    		}
    	}
    
    	g.BytesRead += gossipOldRx
    	g.BytesWritten += gossipOldTx
    
    	return
    }