Skip to content
Snippets Groups Projects
Select Git revision
  • edf19ac33ff052a67a481bad10cab68286d5f5cb
  • 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

unsolidTxs.go

Blame
  • user avatar
    Wolfgang Welz authored and Luca Moser committed
    * fix solidifier
    
    Request branch and trunk if absent. Remove solidified transactions from unsolidTxs.
    
    * Recursively request not yet requesting transactions
    
    * remove existing transactions from request queue
    
    * :recycle: refactor solidifier
    8ae11a7e
    History
    unsolidTxs.go 894 B
    package tangle
    
    import (
    	"sync"
    	"time"
    )
    
    type UnsolidTxs struct {
    	internal map[string]Info
    	sync.RWMutex
    }
    
    type Info struct {
    	lastRequest time.Time
    	counter     int
    }
    
    func NewUnsolidTxs() *UnsolidTxs {
    	return &UnsolidTxs{
    		internal: make(map[string]Info),
    	}
    }
    
    func (u *UnsolidTxs) Add(hash string) bool {
    	u.Lock()
    	defer u.Unlock()
    	_, contains := u.internal[hash]
    	if contains {
    		return false
    	}
    	info := Info{
    		lastRequest: time.Now(),
    		counter:     1,
    	}
    	u.internal[hash] = info
    	return true
    }
    
    func (u *UnsolidTxs) Remove(hash string) {
    	u.Lock()
    	delete(u.internal, hash)
    	u.Unlock()
    }
    
    func (u *UnsolidTxs) Update(targetTime time.Time) (result []string) {
    	u.Lock()
    	for k, v := range u.internal {
    		if v.lastRequest.Before(targetTime) {
    			result = append(result, k)
    
    			v.lastRequest = time.Now()
    			v.counter++
    
    			u.internal[k] = v
    		}
    	}
    	u.Unlock()
    	return result
    }