Skip to content

Commit

Permalink
exclude with host-based comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Nov 21, 2023
1 parent aef3e44 commit 439da26
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions pkg/core/inputs/hybrid/hmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,33 @@ func (i *Input) setItem(metaInput *contextargs.MetaInput) {

// setItem in the kv store
func (i *Input) delItem(metaInput *contextargs.MetaInput) {
key, err := metaInput.MarshalString()
targetUrl, err := urlutil.ParseURL(metaInput.Input, true)
if err != nil {
gologger.Warning().Msgf("%s\n", err)
return
}
if _, ok := i.hostMap.Get(key); !ok {
return
}

i.excludedCount++
_ = i.hostMap.Del(key)
i.hostMap.Scan(func(k, _ []byte) error {
var tmpMetaInput contextargs.MetaInput
if err := tmpMetaInput.Unmarshal(string(k)); err != nil {
return err
}
tmpKey, err := tmpMetaInput.MarshalString()
if err != nil {
return err
}
tmpUrl, err := urlutil.ParseURL(tmpMetaInput.Input, true)
if err != nil {
return err
}

if tmpUrl.Host == targetUrl.Host {
i.hostMap.Del(tmpKey)
i.excludedCount++
i.inputCount--
}
return nil
})
}

// setHostMapStream sets item in stream mode
Expand Down Expand Up @@ -481,27 +497,6 @@ func (i *Input) addTargets(targets []string) {
func (i *Input) removeTargets(targets []string) {
for _, target := range targets {
metaInput := &contextargs.MetaInput{Input: target}
key, err := metaInput.MarshalString()
if err != nil {
gologger.Warning().Msgf("%s\n", err)
return
}

i.hostMap.Scan(func(k, _ []byte) error {
var tmpMetaInput contextargs.MetaInput
if err := tmpMetaInput.Unmarshal(string(k)); err != nil {
return err
}
tmpKey, err := tmpMetaInput.MarshalString()
if err != nil {
return err
}
if tmpKey == key {
i.hostMap.Del(tmpKey)
i.excludedCount++
i.inputCount--
}
return nil
})
i.delItem(metaInput)
}
}

0 comments on commit 439da26

Please sign in to comment.