mirror of
https://github.com/safing/portbase
synced 2025-04-19 17:09:09 +00:00
43 lines
704 B
Go
43 lines
704 B
Go
package rng
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
func getFullFeedDuration() time.Duration {
|
|
// full feed every 5x time of reseedAfterSeconds
|
|
secsUntilFullFeed := reseedAfterSeconds * 5
|
|
|
|
// full feed at most once every ten minutes
|
|
if secsUntilFullFeed < 600 {
|
|
secsUntilFullFeed = 600
|
|
}
|
|
|
|
return time.Duration(secsUntilFullFeed) * time.Second
|
|
}
|
|
|
|
func fullFeeder(ctx context.Context) error {
|
|
fullFeedDuration := getFullFeedDuration()
|
|
|
|
for {
|
|
select {
|
|
case <-time.After(fullFeedDuration):
|
|
|
|
rngLock.Lock()
|
|
feedAll:
|
|
for {
|
|
select {
|
|
case data := <-rngFeeder:
|
|
rng.Reseed(data)
|
|
default:
|
|
break feedAll
|
|
}
|
|
}
|
|
rngLock.Unlock()
|
|
|
|
case <-ctx.Done():
|
|
return nil
|
|
}
|
|
}
|
|
}
|