Skip to content
Snippets Groups Projects
Select Git revision
  • 8c6701ff5429d60a09e1df01dbdedcd723f318a5
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

polltracker.go

Blame
  • polltracker.go 1.15 KiB
    package network
    
    import (
    	"fmt"
    	"gitlab.com/xx_network/primitives/id"
    	"gitlab.com/xx_network/primitives/id/ephemeral"
    )
    
    type pollTracker map[id.ID]map[int64]uint
    
    func newPollTracker() *pollTracker {
    	pt := make(pollTracker)
    	return &pt
    }
    
    // Track tracks a single poll
    func (pt *pollTracker) Track(ephID ephemeral.Id, source *id.ID) {
    	if _, exists := (*pt)[*source]; !exists {
    		(*pt)[*source] = make(map[int64]uint)
    		(*pt)[*source][ephID.Int64()] = 1
    	} else if _, exists := (*pt)[*source][ephID.Int64()]; !exists {
    		(*pt)[*source][ephID.Int64()] = 1
    	} else {
    		(*pt)[*source][ephID.Int64()] = (*pt)[*source][ephID.Int64()] + 1
    	}
    }
    
    // Report reports all recent polls
    func (pt *pollTracker) Report() string {
    	report := ""
    	numReports := uint(0)
    
    	for source := range *pt {
    		numSubReports := uint(0)
    		subReport := ""
    		for ephID, reports := range (*pt)[source] {
    			numSubReports += reports
    			subReport += fmt.Sprintf("\n\t\tEphID %d polled %d times", ephID, reports)
    		}
    		subReport = fmt.Sprintf("\n\tID %s polled %d times", &source, numSubReports)
    		numReports += numSubReports
    	}
    
    	return fmt.Sprintf("\nPolled the network %d times", numReports) + report
    }