mirror of https://github.com/0xERR0R/blocky.git
SourceLoadingConfig -> SourceLoading
This commit is contained in:
parent
253e1d4998
commit
3f210343c0
|
@ -13,7 +13,7 @@ type Blocking struct {
|
|||
ClientGroupsBlock map[string][]string `yaml:"clientGroupsBlock"`
|
||||
BlockType string `yaml:"blockType" default:"ZEROIP"`
|
||||
BlockTTL Duration `yaml:"blockTTL" default:"6h"`
|
||||
Loading SourceLoadingConfig `yaml:"loading"`
|
||||
Loading SourceLoading `yaml:"loading"`
|
||||
|
||||
// Deprecated options
|
||||
Deprecated struct {
|
||||
|
|
|
@ -319,7 +319,7 @@ func (c *Init) LogConfig(logger *logrus.Entry) {
|
|||
logger.Debugf("strategy = %s", c.Strategy)
|
||||
}
|
||||
|
||||
type SourceLoadingConfig struct {
|
||||
type SourceLoading struct {
|
||||
Init `yaml:",inline"`
|
||||
|
||||
Concurrency uint `yaml:"concurrency" default:"4"`
|
||||
|
@ -328,7 +328,7 @@ type SourceLoadingConfig struct {
|
|||
Downloads DownloaderConfig `yaml:"downloads"`
|
||||
}
|
||||
|
||||
func (c *SourceLoadingConfig) LogConfig(logger *logrus.Entry) {
|
||||
func (c *SourceLoading) LogConfig(logger *logrus.Entry) {
|
||||
c.Init.LogConfig(logger)
|
||||
logger.Infof("concurrency = %d", c.Concurrency)
|
||||
logger.Debugf("maxErrorsPerSource = %d", c.MaxErrorsPerSource)
|
||||
|
@ -343,7 +343,7 @@ func (c *SourceLoadingConfig) LogConfig(logger *logrus.Entry) {
|
|||
log.WithIndent(logger, " ", c.Downloads.LogConfig)
|
||||
}
|
||||
|
||||
func (c *SourceLoadingConfig) StartPeriodicRefresh(
|
||||
func (c *SourceLoading) StartPeriodicRefresh(
|
||||
ctx context.Context, refresh func(context.Context) error, logErr func(error),
|
||||
) error {
|
||||
err := c.Strategy.Do(ctx, refresh, logErr)
|
||||
|
@ -358,7 +358,7 @@ func (c *SourceLoadingConfig) StartPeriodicRefresh(
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *SourceLoadingConfig) periodically(
|
||||
func (c *SourceLoading) periodically(
|
||||
ctx context.Context, refresh func(context.Context) error, logErr func(error),
|
||||
) {
|
||||
refresh = recoverToError(refresh, func(panicVal any) error {
|
||||
|
|
|
@ -547,10 +547,10 @@ bootstrapDns:
|
|||
)
|
||||
|
||||
Describe("SourceLoadingConfig", func() {
|
||||
var cfg SourceLoadingConfig
|
||||
var cfg SourceLoading
|
||||
|
||||
BeforeEach(func() {
|
||||
cfg = SourceLoadingConfig{
|
||||
cfg = SourceLoading{
|
||||
Concurrency: 12,
|
||||
RefreshPeriod: Duration(time.Hour),
|
||||
}
|
||||
|
@ -777,7 +777,7 @@ bootstrapDns:
|
|||
DeferCleanup(cancelFn)
|
||||
})
|
||||
It("handles panics", func() {
|
||||
sut := SourceLoadingConfig{
|
||||
sut := SourceLoading{
|
||||
Init: Init{Strategy: InitStrategyFailOnError},
|
||||
}
|
||||
|
||||
|
@ -793,7 +793,7 @@ bootstrapDns:
|
|||
})
|
||||
|
||||
It("periodically calls refresh", func() {
|
||||
sut := SourceLoadingConfig{
|
||||
sut := SourceLoading{
|
||||
Init: Init{Strategy: InitStrategyFast},
|
||||
RefreshPeriod: Duration(5 * time.Millisecond),
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
)
|
||||
|
||||
type HostsFile struct {
|
||||
Sources []BytesSource `yaml:"sources"`
|
||||
HostsTTL Duration `yaml:"hostsTTL" default:"1h"`
|
||||
FilterLoopback bool `yaml:"filterLoopback"`
|
||||
Loading SourceLoadingConfig `yaml:"loading"`
|
||||
Sources []BytesSource `yaml:"sources"`
|
||||
HostsTTL Duration `yaml:"hostsTTL" default:"1h"`
|
||||
FilterLoopback bool `yaml:"filterLoopback"`
|
||||
Loading SourceLoading `yaml:"loading"`
|
||||
|
||||
// Deprecated options
|
||||
Deprecated struct {
|
||||
|
|
|
@ -20,7 +20,7 @@ var _ = Describe("HostsFileConfig", func() {
|
|||
TextBytesSource("127.0.0.1 localhost"),
|
||||
),
|
||||
HostsTTL: Duration(29 * time.Minute),
|
||||
Loading: SourceLoadingConfig{RefreshPeriod: Duration(30 * time.Minute)},
|
||||
Loading: SourceLoading{RefreshPeriod: Duration(30 * time.Minute)},
|
||||
FilterLoopback: true,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -40,7 +40,7 @@ type ListCache struct {
|
|||
groupedCache stringcache.GroupedStringCache
|
||||
regexCache stringcache.GroupedStringCache
|
||||
|
||||
cfg config.SourceLoadingConfig
|
||||
cfg config.SourceLoading
|
||||
listType ListCacheType
|
||||
groupSources map[string][]config.BytesSource
|
||||
downloader FileDownloader
|
||||
|
@ -70,7 +70,7 @@ func (b *ListCache) LogConfig(logger *logrus.Entry) {
|
|||
|
||||
// NewListCache creates new list instance
|
||||
func NewListCache(ctx context.Context,
|
||||
t ListCacheType, cfg config.SourceLoadingConfig,
|
||||
t ListCacheType, cfg config.SourceLoading,
|
||||
groupSources map[string][]config.BytesSource, downloader FileDownloader,
|
||||
) (*ListCache, error) {
|
||||
regexCache := stringcache.NewInMemoryGroupedRegexCache()
|
||||
|
|
|
@ -15,7 +15,7 @@ func BenchmarkRefresh(b *testing.B) {
|
|||
"gr1": config.NewBytesSources(file1, file2, file3),
|
||||
}
|
||||
|
||||
cfg := config.SourceLoadingConfig{
|
||||
cfg := config.SourceLoading{
|
||||
Concurrency: 5,
|
||||
RefreshPeriod: config.Duration(-1),
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ var _ = Describe("ListCache", func() {
|
|||
server1, server2, server3 *httptest.Server
|
||||
|
||||
sut *ListCache
|
||||
sutConfig config.SourceLoadingConfig
|
||||
sutConfig config.SourceLoading
|
||||
|
||||
listCacheType ListCacheType
|
||||
lists map[string][]config.BytesSource
|
||||
|
@ -48,7 +48,7 @@ var _ = Describe("ListCache", func() {
|
|||
|
||||
listCacheType = ListCacheTypeBlacklist
|
||||
|
||||
sutConfig, err = config.WithDefaults[config.SourceLoadingConfig]()
|
||||
sutConfig, err = config.WithDefaults[config.SourceLoading]()
|
||||
Expect(err).Should(Succeed())
|
||||
|
||||
sutConfig.RefreshPeriod = -1
|
||||
|
|
|
@ -170,7 +170,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
|
|||
ClientGroupsBlock: map[string][]string{
|
||||
"default": {"gr1"},
|
||||
},
|
||||
Loading: config.SourceLoadingConfig{
|
||||
Loading: config.SourceLoading{
|
||||
Init: config.Init{Strategy: config.InitStrategyFast},
|
||||
},
|
||||
}
|
||||
|
@ -1126,7 +1126,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
|
|||
_, err := NewBlockingResolver(ctx, config.Blocking{
|
||||
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources("wrongPath")},
|
||||
WhiteLists: map[string][]config.BytesSource{"whitelist": config.NewBytesSources("wrongPath")},
|
||||
Loading: config.SourceLoadingConfig{
|
||||
Loading: config.SourceLoading{
|
||||
Init: config.Init{Strategy: config.InitStrategyFailOnError},
|
||||
},
|
||||
BlockType: "zeroIp",
|
||||
|
|
|
@ -47,7 +47,7 @@ var _ = Describe("HostsFileResolver", func() {
|
|||
Sources: config.NewBytesSources(tmpFile.Path),
|
||||
HostsTTL: config.Duration(time.Duration(TTL) * time.Second),
|
||||
FilterLoopback: true,
|
||||
Loading: config.SourceLoadingConfig{
|
||||
Loading: config.SourceLoading{
|
||||
RefreshPeriod: -1,
|
||||
MaxErrorsPerSource: 5,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue