crowdsec/pkg/leakybucket/buckets.go
registergoofy 5b7ac4a473
[Rebased] fix races (#633)
* get rid of dead code
* have LeakRoutined started in a tomb
* fix race and multiple small issues in the way we handle tombs
* yet another race fix
* another race
* get rid of leaky.KillSwitch for proper tomb use
* fix deadlock
* empty overflow before exiting
* fix an obvious typo
* proper use of waitgroup
* have a smart signalisation for allowing LeakRoutine being killed
* ugly workaround
* fix lint error
* fix compilation
* fix panic
* shorten lock
* up lock both copy
* wait for crowdsec to die
* fix coding style and lint issue
* go mod tidy

Co-authored-by: bui <thibault@crowdsec.net>
2021-02-25 11:26:46 +01:00

29 lines
633 B
Go

package leakybucket
import (
"crypto/sha1"
"fmt"
"sync"
)
// Buckets is the struct used to hold buckets in the context of
// main.go the idea is to have one struct to rule them all
type Buckets struct {
wgDumpState *sync.WaitGroup
wgPour *sync.WaitGroup
Bucket_map *sync.Map
}
// NewBuckets create the Buckets struct
func NewBuckets() *Buckets {
return &Buckets{
wgDumpState: &sync.WaitGroup{},
wgPour: &sync.WaitGroup{},
Bucket_map: &sync.Map{},
}
}
func GetKey(bucketCfg BucketFactory, stackkey string) string {
return fmt.Sprintf("%x", sha1.Sum([]byte(bucketCfg.Filter+stackkey+bucketCfg.Name)))
}