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

Add rate limit #2674

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TODO: add rate in policy level
  • Loading branch information
HikaruChang committed Aug 10, 2020
commit 1c64a0fdb6553f1a5535e56a61d99db29bf65a46
11 changes: 7 additions & 4 deletions app/policy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func defaultPolicy() *Policy {
Buffer: &Policy_Buffer{
Connection: p.Buffer.PerConnection,
},
Rate: &p.Rate,
Rate: p.Rate,
}
}

Expand All @@ -44,6 +44,9 @@ func (p *Policy_Timeout) overrideWith(another *Policy_Timeout) {
if another.DownlinkOnly != nil {
p.DownlinkOnly = &Second{Value: another.DownlinkOnly.Value}
}
if another.Rate != 0 {
p.Rate = another.Rate
}
}

func (p *Policy) overrideWith(another *Policy) {
Expand All @@ -59,7 +62,7 @@ func (p *Policy) overrideWith(another *Policy) {
Connection: another.Buffer.Connection,
}
}
if another.Rate != nil {
if another.Rate != 0 {
p.Rate = another.Rate
}
}
Expand All @@ -81,8 +84,8 @@ func (p *Policy) ToCorePolicy() policy.Session {
if p.Buffer != nil {
cp.Buffer.PerConnection = p.Buffer.Connection
}
if p.Rate != nil {
cp.Rate = *p.Rate
if p.Rate != 0 {
cp.Rate = p.Rate
}
return cp
}
Expand Down
13 changes: 11 additions & 2 deletions app/policy/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions features/policy/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func (DefaultManager) ForLevel(level uint32) Session {
if level == 1 {
p.Timeouts.ConnectionIdle = time.Second * 600
}
if level == 100 {
p.Rate = 100
}
return p
}

Expand Down
2 changes: 2 additions & 0 deletions features/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Stats struct {
UserUplink bool
// Whether or not to enable stat counter for user downlink traffic.
UserDownlink bool

Rate uint64
}

// Buffer contains settings for internal buffer.
Expand Down
2 changes: 1 addition & 1 deletion infra/conf/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (t *Policy) Build() (*policy.Policy, error) {
}

if t.Rate != nil {
config.Rate = t.Rate
p.Rate = *t.Rate
}

return p, nil
Expand Down
Binary file removed main/main-linux-amd64
Binary file not shown.