Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rate limiting to countries other than the target country #2

Merged
merged 7 commits into from
Dec 20, 2023

Conversation

pyama86
Copy link
Contributor

@pyama86 pyama86 commented Dec 19, 2023

指定した国以外にレートリミットを書けるケースを想定しています。サービスを提供する国以外からのアクセスに対して厳しいレートリミットをかけたいことがあります。

I am considering cases where rate limiting is applied to countries other than the specified one. Sometimes, we want to impose strict rate limits on access from countries where our service is not provided.

Copy link
Member

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Another way to implement this would be to provide an API similar to hosts.allow/hosts.deny or iptables.

It can be realized with two []strings and a wildcard (*).

Example

type CountryLimiter struct {
	db            *maxminddb.Reader
	countries     []string
	skipCountries []string
	BaseLimiter
}

Limit countries other than JP.

CountryLimiter{
  db: db,
  countries: ["*"],
  skipCountries: ["JP"],
}

Pros of this proposal is that the meaning of the fields does not change.

It is also easy to understand if we want to change the settings.

Cons are that skipCountries is redundant.
This is because skipCountries is usually used only when expressing "other than ~".

db *maxminddb.Reader
countries []string
db *maxminddb.Reader
limitRateForOtherCountries bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea, how about specifying the type?

Suggested change
limitRateForOtherCountries bool
CondType CondType
type CondType bool
var Target CondType = true
var Excect CondType = false

country_limiter.go Outdated Show resolved Hide resolved
country_limiter.go Outdated Show resolved Hide resolved
pyama86 and others added 3 commits December 20, 2023 11:01
Co-authored-by: Ken’ichiro Oyama <[email protected]>
Co-authored-by: Ken’ichiro Oyama <[email protected]>
Copy link
Member

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GREAT! LGTM!!

@pyama86 pyama86 merged commit 26df451 into main Dec 20, 2023
3 checks passed
@github-actions github-actions bot mentioned this pull request Dec 20, 2023
@pyama86 pyama86 deleted the exclude-contries branch December 20, 2023 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants